mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-28 19:22:31 +01:00
feature (url): support for .url files
This commit is contained in:
parent
ded8ef28cc
commit
25404e8d13
4 changed files with 36 additions and 0 deletions
|
|
@ -160,6 +160,7 @@
|
|||
"tk": "application/x-tcl",
|
||||
"ts": "text/plain",
|
||||
"txt": "text/plain",
|
||||
"url": "application/x-url",
|
||||
"vcf": "text/vcard",
|
||||
"vrml": "application/x-vrml",
|
||||
"war": "application/java-archive",
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ function loadModule(appName) {
|
|||
return import("./viewerpage/application_iframe.js");
|
||||
case "map":
|
||||
return import("./viewerpage/application_map.js");
|
||||
case "url":
|
||||
return import("./viewerpage/application_url.js");
|
||||
default:
|
||||
throw new ApplicationError("Internal Error", `Unknown opener app "${appName}" at "${getCurrentPath()}"`);
|
||||
}
|
||||
|
|
|
|||
31
public/assets/pages/viewerpage/application_url.js
Normal file
31
public/assets/pages/viewerpage/application_url.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { createElement, navigate } from "../../lib/skeleton/index.js";
|
||||
import rxjs, { effect } from "../../lib/rx.js";
|
||||
import { ApplicationError } from "../../lib/error.js";
|
||||
import { createLoader } from "../../components/loader.js";
|
||||
import ctrlError from "../ctrl_error.js";
|
||||
import { cat } from "./model_files.js";
|
||||
|
||||
export default function(render) {
|
||||
const $page = createElement(`
|
||||
<div class="component_urlopener" style="background: #52565911;"></div>
|
||||
`);
|
||||
render($page);
|
||||
createLoader($page);
|
||||
|
||||
effect(cat().pipe(
|
||||
rxjs.tap((content) => {
|
||||
const url = content.replace(/[\s\S]*(https?:\/\/\S+)[\s\S]*/, "$1");
|
||||
try {
|
||||
const u = new URL(url);
|
||||
if (u.host === location.host) {
|
||||
navigate(u.href.replace(u.origin, ""));
|
||||
return;
|
||||
}
|
||||
location.href = url;
|
||||
} catch(err) {
|
||||
throw new ApplicationError("Not Valid", err);
|
||||
}
|
||||
}),
|
||||
rxjs.catchError(ctrlError()),
|
||||
));
|
||||
}
|
||||
|
|
@ -32,6 +32,8 @@ export function opener(file = "", mimes) {
|
|||
return ["ebook", { mime }];
|
||||
} else if (type === "model" || ["application/object", "application/fbx"].indexOf(mime) !== -1) {
|
||||
return ["3d", { mime }];
|
||||
} else if (mime === "application/x-url") {
|
||||
return ["url", { mime }];
|
||||
} else if (type === "application") {
|
||||
return ["download", { mime }];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue