fix (public): login redirection

This commit is contained in:
MickaelK 2024-12-04 17:08:51 +11:00
parent 97a82423a4
commit c7dcf29f11
2 changed files with 15 additions and 3 deletions

View file

@ -9,7 +9,7 @@ import { transition, getFilename, getDownloadUrl } from "./common.js";
import "../../components/icon.js";
import "./component_menubar.js";
export default async function(render) {
export default async function(render, { acl$ }) {
const $page = createElement(`
<div class="component_filedownloader">
<component-menubar></component-menubar>
@ -41,6 +41,7 @@ export default async function(render) {
})),
rxjs.tap(() => setLoading(false)),
));
effect(acl$);
}
export function init() {

View file

@ -1,12 +1,23 @@
import { toHref, navigate } from "../../lib/skeleton/router.js";
import rxjs from "../../lib/rx.js";
import ajax from "../../lib/ajax.js";
import { getCurrentPath } from "./common.js";
import { AjaxError } from "../../lib/error.js";
import { forwardURLParams } from "../../lib/path.js";
import { getCurrentPath } from "./common.js";
export const options = () => ajax({
url: forwardURLParams(`api/files/cat?path=${encodeURIComponent(getCurrentPath())}`, ["share"]),
method: "OPTIONS",
}).pipe(rxjs.map((res) => res.responseHeaders.allow.replace(/\r/, "").split(", ")));
}).pipe(
rxjs.catchError((err) => {
if (err instanceof AjaxError && err.err().status === 401) {
navigate(toHref("/login?next=" + location.pathname + location.hash + location.search));
return rxjs.EMPTY;
}
throw err;
}),
rxjs.map((res) => res.responseHeaders.allow.replace(/\r/, "").split(", ")),
);
export const cat = () => ajax({
url: forwardURLParams("api/files/cat?path=" + encodeURIComponent(getCurrentPath()), ["share"]),