mirror of
https://github.com/Forceu/Gokapi.git
synced 2025-12-30 13:29:34 -06:00
Add nginx header for SSE, update nginx documentation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user