fix (cache): cache invalidation problem

This commit is contained in:
MickaelK 2025-09-03 01:59:09 +10:00
parent 13f926fc3b
commit 9e41d0c97f
4 changed files with 24 additions and 11 deletions

View file

@ -21,9 +21,12 @@ export function createSession(authenticationRequest) {
url: withShare("api/session"), url: withShare("api/session"),
body: authenticationRequest, body: authenticationRequest,
responseType: "json", responseType: "json",
}).pipe(rxjs.tap(({ responseHeaders }) => { }).pipe(
rxjs.tap(({ responseHeaders }) => {
if (responseHeaders.bearer) window.BEARER_TOKEN = responseHeaders.bearer; // see ctrl_boot_frontoffice.js -> setup_iframe if (responseHeaders.bearer) window.BEARER_TOKEN = responseHeaders.bearer; // see ctrl_boot_frontoffice.js -> setup_iframe
})); }),
rxjs.map(({ responseJSON }) => responseJSON.result),
);
} }
export function deleteSession() { export function deleteSession() {

View file

@ -18,6 +18,7 @@ import ctrlError from "../ctrl_error.js";
import config$ from "./model_config.js"; import config$ from "./model_config.js";
import backend$ from "./model_backend.js"; import backend$ from "./model_backend.js";
import { setCurrentBackend, getCurrentBackend, getURLParams } from "./ctrl_form_state.js"; import { setCurrentBackend, getCurrentBackend, getURLParams } from "./ctrl_form_state.js";
import { updateBackend } from "../filespage/cache.js";
const connections$ = config$.pipe( const connections$ = config$.pipe(
rxjs.map(({ connections, auth }) => (connections || []).map((conn) => { rxjs.map(({ connections, auth }) => (connections || []).map((conn) => {
@ -200,11 +201,12 @@ export default async function(render) {
return rxjs.of(null).pipe( return rxjs.of(null).pipe(
rxjs.tap(() => toggleLoader(true)), rxjs.tap(() => toggleLoader(true)),
rxjs.mergeMap(() => createSession(formData)), rxjs.mergeMap(() => createSession(formData)),
rxjs.tap(({ responseJSON }) => { rxjs.tap(({ home, backendID }) => {
updateBackend(backendID);
let redirectURL = toHref("/files/"); let redirectURL = toHref("/files/");
const GET = getURLParams(); const GET = getURLParams();
if (GET["next"]) redirectURL = GET["next"]; if (GET["next"]) redirectURL = GET["next"];
else if (responseJSON.result) redirectURL = toHref("/files" + responseJSON.result); else if (home) redirectURL = toHref("/files" + home);
if (redirectURL.startsWith("/api/")) return location.replace(redirectURL); if (redirectURL.startsWith("/api/")) return location.replace(redirectURL);
navigate(forwardURLParams(redirectURL, ["nav"])); navigate(forwardURLParams(redirectURL, ["nav"]));

View file

@ -255,6 +255,9 @@ let backendID = "";
export function currentBackend() { export function currentBackend() {
return backendID; return backendID;
} }
export function updateBackend(id) {
backendID = id;
}
export function currentShare() { export function currentShare() {
return new window.URL(location.href).searchParams.get("share") || ""; return new window.URL(location.href).searchParams.get("share") || "";

View file

@ -44,7 +44,7 @@ func SessionGet(ctx *App, res http.ResponseWriter, req *http.Request) {
} }
r.IsAuth = true r.IsAuth = true
r.Home = NewString(home) r.Home = NewString(home)
r.Backend = Hash(GenerateID(ctx.Session)+ctx.Session["path"], 20) r.Backend = backendID(ctx.Session)
if ctx.Share.Id == "" && Config.Get("features.protection.enable_chromecast").Bool() { if ctx.Share.Id == "" && Config.Get("features.protection.enable_chromecast").Bool() {
r.Authorization = ctx.Authorization r.Authorization = ctx.Authorization
} }
@ -126,11 +126,12 @@ func SessionAuthenticate(ctx *App, res http.ResponseWriter, req *http.Request) {
if Config.Get("features.protection.iframe").String() != "" { if Config.Get("features.protection.iframe").String() != "" {
res.Header().Set("bearer", obfuscate) res.Header().Set("bearer", obfuscate)
} }
if home != "" { SendSuccessResult(res, Session{
SendSuccessResult(res, home) IsAuth: true,
return Home: NewString(home),
} Backend: backendID(session),
SendSuccessResult(res, nil) Authorization: obfuscate,
})
} }
func SessionLogout(ctx *App, res http.ResponseWriter, req *http.Request) { func SessionLogout(ctx *App, res http.ResponseWriter, req *http.Request) {
@ -504,3 +505,7 @@ func applyCookieSameSiteRule(cookie *http.Cookie, sameSiteValue http.SameSite) *
cookie.SameSite = sameSiteValue cookie.SameSite = sameSiteValue
return cookie return cookie
} }
func backendID(session map[string]string) string {
return Hash(GenerateID(session)+session["path"], 20)
}