Add nginx header for SSE, update nginx documentation

This commit is contained in:
Marc Ole Bulling
2024-05-24 11:01:56 +02:00
parent 1729200ee4
commit ac12cca1bf
5 changed files with 49 additions and 24 deletions

View File

@@ -26,6 +26,11 @@ Nginx Configuration
client_body_buffer_size 128k;
server_name your.server.url;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
location / {
# If using Cloudflare

View File

@@ -14,10 +14,13 @@ type UploadStatus struct {
CurrentStatus int `json:"currentstatus"`
// LastUpdate indicates the last status change
LastUpdate int64 `json:"lastupdate"`
// Type is the type of the message and is always "uploadstatus"
Type string `json:"type"`
}
// ToJson returns the struct as a Json byte array
func (u *UploadStatus) ToJson() ([]byte, error) {
u.Type = "uploadstatus"
return json.Marshal(u)
}

View File

@@ -84,6 +84,7 @@ func Start() {
mux := http.NewServeMux()
sseServer = sse.New()
sseServer.Headers["X-Accel-Buffering"] = "no"
sseServer.CreateStream("changes")
processingstatus.Init(sseServer)
@@ -145,13 +146,13 @@ func Start() {
ssl.GenerateIfInvalidCert(configuration.Get().ServerUrl, false)
fmt.Println(infoMessage)
err = srv.ListenAndServeTLS(ssl.GetCertificateLocations())
if err != nil && err != http.ErrServerClosed {
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
} else {
fmt.Println(infoMessage)
err = srv.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}

View File

@@ -226,22 +226,22 @@ function editFile() {
button.disabled = true;
let apiUrl = './api/files/modify';
let allowedDownloads = document.getElementById('mi_edit_down').value;
let expiryTimestamp = document.getElementById('mi_edit_expiry').value;
let password = document.getElementById('mi_edit_pw').value;
let originalPassword = (password === '(unchanged)');
let allowedDownloads = document.getElementById('mi_edit_down').value;
let expiryTimestamp = document.getElementById('mi_edit_expiry').value;
let password = document.getElementById('mi_edit_pw').value;
let originalPassword = (password === '(unchanged)');
if (!document.getElementById('mc_download').checked) {
allowedDownloads = 0;
allowedDownloads = 0;
}
if (!document.getElementById('mc_expiry').checked) {
expiryTimestamp = 0;
expiryTimestamp = 0;
}
if (!document.getElementById('mc_password').checked) {
originalPassword = false;
password = "";
}
originalPassword = false;
password = "";
}
const requestOptions = {
method: 'PUT',
headers: {
@@ -360,14 +360,14 @@ function selectTextForPw(input) {
}
function add14DaysIfBeforeCurrentTime(unixTimestamp) {
let currentTime = Date.now();
let timestampInMilliseconds = unixTimestamp * 1000;
if (timestampInMilliseconds < currentTime) {
let newTimestamp = currentTime + (14 * 24 * 60 * 60 * 1000);
return Math.floor(newTimestamp / 1000);
} else {
return unixTimestamp;
}
let currentTime = Date.now();
let timestampInMilliseconds = unixTimestamp * 1000;
if (timestampInMilliseconds < currentTime) {
let newTimestamp = currentTime + (14 * 24 * 60 * 60 * 1000);
return Math.floor(newTimestamp / 1000);
} else {
return unixTimestamp;
}
}
function changeApiPermission(apiKey, permission, buttonId) {
@@ -454,9 +454,25 @@ function parseData(data) {
function registerChangeHandler() {
const source = new EventSource("./uploadStatus?stream=changes")
source.onmessage = (event) => {
let eventData = JSON.parse(event.data);
setProgressStatus(eventData.chunkid, eventData.currentstatus);
try {
let eventData = JSON.parse(event.data);
setProgressStatus(eventData.chunkid, eventData.currentstatus);
} catch (e) {
console.error("Failed to parse event data:", e);
}
}
source.onerror = (error) => {
// Check for net::ERR_HTTP2_PROTOCOL_ERROR 200 (OK) and ignore it
if (error.target.readyState !== EventSource.CLOSED) {
source.close();
}
console.log("Reconnecting to SSE...");
// Attempt to reconnect after a delay
setTimeout(registerChangeHandler, 1000);
};
}
var statusItemCount = 0;

File diff suppressed because one or more lines are too long