fix (embed): Filestash embedding issue

whenever embedding something with a locale setup, it would crash while
trying to download the translation. This was due to some
missunderstanding of how fetch work while in an iframe and all the
reports would get miss because of that same issue as it was sent not to
the origin server but the website embedding the frame
This commit is contained in:
MickaelK
2025-04-30 17:23:18 +10:00
parent 7f6a514b6e
commit 7858b29cf5
4 changed files with 8 additions and 7 deletions

View File

@ -1,4 +1,5 @@
import { toHref } from "../lib/skeleton/router.js";
import ajax from "../lib/ajax.js";
export function report(msg, err, link, lineNo, columnNo) {
if (window.navigator.onLine === false) return Promise.resolve();
@ -10,5 +11,5 @@ export function report(msg, err, link, lineNo, columnNo) {
url += "from.columnNo=" + columnNo;
if (err instanceof Error) url += "error=" + encodeURIComponent(err.message) + "&";
return fetch(url, { method: "post" }).catch(() => {});
return ajax({ url, method: "post" }).toPromise().catch(() => {});
}

View File

@ -1,4 +1,5 @@
import rxjs, { ajax } from "../lib/rx.js";
import rxjs from "../lib/rx.js";
import ajax from "../lib/ajax.js";
let LNG = {};
@ -42,11 +43,10 @@ export async function init() {
}
return ajax({
url: "assets/locales/" + selectedLanguage + ".json",
responseType: "json",
}).pipe(rxjs.tap(({ responseHeaders, response }) => {
const contentType = responseHeaders["content-type"].trim();
if (contentType === "application/json") {
LNG = response;
LNG = JSON.parse(response);
return;
}
throw new Error(`wrong content type '${contentType}'`);

View File

@ -19,7 +19,7 @@ class ITable {
getBody() { throw new Error("NOT_IMPLEMENTED"); }
}
export default async function(render, { mime, getDownloadUrl = nop, getFilename = nop, hasMenubar = true, acl$ }) {
export default async function(render, { mime, getDownloadUrl = nop, getFilename = nop, hasMenubar = true, acl$ = rxjs.EMPTY }) {
const $page = createElement(`
<div class="component_tableviewer">
<component-menubar filename="${getFilename()}" class="${!hasMenubar && "hidden"}"></component-menubar>

View File

@ -103,8 +103,8 @@ func Build(r *mux.Router, a App) {
}
// Other endpoints
middlewares = []Middleware{ApiHeaders, PluginInjector}
r.HandleFunc(WithBase("/report"), NewMiddlewareChain(ReportHandler, middlewares, a)).Methods("POST")
middlewares = []Middleware{ApiHeaders, PluginInjector, PublicCORS}
r.HandleFunc(WithBase("/report"), NewMiddlewareChain(ReportHandler, middlewares, a)).Methods("POST", "OPTIONS")
middlewares = []Middleware{IndexHeaders, SecureHeaders, PluginInjector}
r.HandleFunc(WithBase("/about"), NewMiddlewareChain(AboutHandler, middlewares, a)).Methods("GET")
r.HandleFunc(WithBase("/robots.txt"), NewMiddlewareChain(RobotsHandler, []Middleware{}, a))