feature (url): support for .url files

This commit is contained in:
MickaelK 2024-11-07 13:02:52 +11:00
parent ded8ef28cc
commit 25404e8d13
4 changed files with 36 additions and 0 deletions

View file

@ -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",

View file

@ -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()}"`);
}

View 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()),
));
}

View file

@ -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 }];
}