Skip to content

Commit 68a99a4

Browse files
committed
Update until v2.44.1
1 parent 113a1f0 commit 68a99a4

5 files changed

Lines changed: 40 additions & 19 deletions

File tree

auth/hook.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"os/exec"
11+
"slices"
1112
"strings"
1213

1314
fbErrors "github.com/thevickypedia/filebrowser/v2/errors"
@@ -266,13 +267,7 @@ var validHookFields = []string{
266267

267268
// IsValid checks if the provided field is on the valid fields list
268269
func (hf *hookFields) IsValid(field string) bool {
269-
for _, val := range validHookFields {
270-
if field == val {
271-
return true
272-
}
273-
}
274-
275-
return false
270+
return slices.Contains(validHookFields, field)
276271
}
277272

278273
// GetString returns the string value or provided default

frontend/src/api/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,21 @@ export function createURL(endpoint: string, searchParams = {}): string {
9191

9292
return url.toString();
9393
}
94+
95+
export function setSafeTimeout(callback: () => void, delay: number): number {
96+
const MAX_DELAY = 86_400_000;
97+
let remaining = delay;
98+
99+
function scheduleNext(): number {
100+
if (remaining <= MAX_DELAY) {
101+
return window.setTimeout(callback, remaining);
102+
} else {
103+
return window.setTimeout(() => {
104+
remaining -= MAX_DELAY;
105+
scheduleNext();
106+
}, MAX_DELAY);
107+
}
108+
}
109+
110+
return scheduleNext();
111+
}

frontend/src/components/prompts/DiscardEditorChanges.vue

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</button>
1818
<button
1919
class="button button--flat button--blue"
20-
@click="saveAndClose"
20+
@click="currentPrompt.saveAction"
2121
:aria-label="$t('buttons.saveChanges')"
2222
:title="$t('buttons.saveChanges')"
2323
tabindex="1"
@@ -39,8 +39,8 @@
3939
</template>
4040

4141
<script>
42-
import { mapState, mapActions } from "pinia";
4342
import { useLayoutStore } from "@/stores/layout";
43+
import { mapActions, mapState } from "pinia";
4444
4545
export default {
4646
name: "discardEditorChanges",
@@ -49,12 +49,6 @@ export default {
4949
},
5050
methods: {
5151
...mapActions(useLayoutStore, ["closeHovers"]),
52-
saveAndClose() {
53-
if (this.currentPrompt?.saveAction) {
54-
this.currentPrompt.saveAction();
55-
}
56-
this.closeHovers();
57-
},
5852
},
5953
};
6054
</script>

frontend/src/utils/auth.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { JwtPayload } from "jwt-decode";
44
import { jwtDecode } from "jwt-decode";
55
import { baseURL, noAuth } from "./constants";
66
import { StatusError } from "@/api/utils";
7+
import { setSafeTimeout } from "@/api/utils";
78

89
export function parseToken(token: string) {
910
// falsy or malformed jwt will throw InvalidTokenError
@@ -22,10 +23,11 @@ export function parseToken(token: string) {
2223
}
2324

2425
const expiresAt = new Date(data.exp! * 1000);
26+
const timeout = expiresAt.getTime() - Date.now();
2527
authStore.setLogoutTimer(
26-
window.setTimeout(() => {
28+
setSafeTimeout(() => {
2729
logout("inactivity");
28-
}, expiresAt.getTime() - Date.now())
30+
}, timeout)
2931
);
3032
}
3133

frontend/src/views/files/Editor.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,24 @@ const decreaseFontSize = () => {
216216
217217
const close = () => {
218218
if (!editor.value?.session.getUndoManager().isClean()) {
219-
layoutStore.showHover("discardEditorChanges");
219+
layoutStore.showHover({
220+
prompt: "discardEditorChanges",
221+
confirm: (event: Event) => {
222+
event.preventDefault();
223+
finishClose();
224+
},
225+
saveAction: async () => {
226+
await save();
227+
finishClose();
228+
},
229+
});
220230
return;
221231
}
232+
finishClose();
233+
};
222234
235+
const finishClose = () => {
223236
fileStore.updateRequest(null);
224-
225237
const uri = url.removeLastDir(route.path) + "/";
226238
router.push({ path: uri });
227239
};

0 commit comments

Comments
 (0)