mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-29 17:18:43 +08:00
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:
@ -1,4 +1,5 @@
|
|||||||
import { toHref } from "../lib/skeleton/router.js";
|
import { toHref } from "../lib/skeleton/router.js";
|
||||||
|
import ajax from "../lib/ajax.js";
|
||||||
|
|
||||||
export function report(msg, err, link, lineNo, columnNo) {
|
export function report(msg, err, link, lineNo, columnNo) {
|
||||||
if (window.navigator.onLine === false) return Promise.resolve();
|
if (window.navigator.onLine === false) return Promise.resolve();
|
||||||
@ -10,5 +11,5 @@ export function report(msg, err, link, lineNo, columnNo) {
|
|||||||
url += "from.columnNo=" + columnNo;
|
url += "from.columnNo=" + columnNo;
|
||||||
if (err instanceof Error) url += "error=" + encodeURIComponent(err.message) + "&";
|
if (err instanceof Error) url += "error=" + encodeURIComponent(err.message) + "&";
|
||||||
|
|
||||||
return fetch(url, { method: "post" }).catch(() => {});
|
return ajax({ url, method: "post" }).toPromise().catch(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 = {};
|
let LNG = {};
|
||||||
|
|
||||||
@ -42,11 +43,10 @@ export async function init() {
|
|||||||
}
|
}
|
||||||
return ajax({
|
return ajax({
|
||||||
url: "assets/locales/" + selectedLanguage + ".json",
|
url: "assets/locales/" + selectedLanguage + ".json",
|
||||||
responseType: "json",
|
|
||||||
}).pipe(rxjs.tap(({ responseHeaders, response }) => {
|
}).pipe(rxjs.tap(({ responseHeaders, response }) => {
|
||||||
const contentType = responseHeaders["content-type"].trim();
|
const contentType = responseHeaders["content-type"].trim();
|
||||||
if (contentType === "application/json") {
|
if (contentType === "application/json") {
|
||||||
LNG = response;
|
LNG = JSON.parse(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error(`wrong content type '${contentType}'`);
|
throw new Error(`wrong content type '${contentType}'`);
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class ITable {
|
|||||||
getBody() { throw new Error("NOT_IMPLEMENTED"); }
|
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(`
|
const $page = createElement(`
|
||||||
<div class="component_tableviewer">
|
<div class="component_tableviewer">
|
||||||
<component-menubar filename="${getFilename()}" class="${!hasMenubar && "hidden"}"></component-menubar>
|
<component-menubar filename="${getFilename()}" class="${!hasMenubar && "hidden"}"></component-menubar>
|
||||||
|
|||||||
@ -103,8 +103,8 @@ func Build(r *mux.Router, a App) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Other endpoints
|
// Other endpoints
|
||||||
middlewares = []Middleware{ApiHeaders, PluginInjector}
|
middlewares = []Middleware{ApiHeaders, PluginInjector, PublicCORS}
|
||||||
r.HandleFunc(WithBase("/report"), NewMiddlewareChain(ReportHandler, middlewares, a)).Methods("POST")
|
r.HandleFunc(WithBase("/report"), NewMiddlewareChain(ReportHandler, middlewares, a)).Methods("POST", "OPTIONS")
|
||||||
middlewares = []Middleware{IndexHeaders, SecureHeaders, PluginInjector}
|
middlewares = []Middleware{IndexHeaders, SecureHeaders, PluginInjector}
|
||||||
r.HandleFunc(WithBase("/about"), NewMiddlewareChain(AboutHandler, middlewares, a)).Methods("GET")
|
r.HandleFunc(WithBase("/about"), NewMiddlewareChain(AboutHandler, middlewares, a)).Methods("GET")
|
||||||
r.HandleFunc(WithBase("/robots.txt"), NewMiddlewareChain(RobotsHandler, []Middleware{}, a))
|
r.HandleFunc(WithBase("/robots.txt"), NewMiddlewareChain(RobotsHandler, []Middleware{}, a))
|
||||||
|
|||||||
Reference in New Issue
Block a user