Add dynamic, finishing basic proxy functionality

This commit is contained in:
rift 2023-12-21 13:04:59 -06:00
parent 6d99559768
commit db2b7a6c2f
13 changed files with 203 additions and 12 deletions

View file

@ -8,12 +8,16 @@
<title>Nebula</title> <title>Nebula</title>
<script src="/uv/uv.bundle.js"></script> <script src="/uv/uv.bundle.js"></script>
<script src="/uv/uv.config.js"></script> <script src="/uv/uv.config.js"></script>
<script src="/dynamic/dynamic.config.js"></script>
<script> <script>
if ("serviceWorker" in navigator) { if ("serviceWorker" in navigator) {
window.addEventListener("load", () => { window.addEventListener("load", () => {
navigator.serviceWorker.register("/sw.js", { navigator.serviceWorker.register("/uvsw.js", {
scope: __uv$config.prefix scope: __uv$config.prefix
}); });
navigator.serviceWorker.register("/dysw.js", {
scope: __dynamic$config.prefix
});
}); });
} }
</script> </script>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,30 @@
// See documentation for more information
self.__dynamic$config = {
prefix: '/~/dynamic/',
encoding: 'plain',
mode: 'production',
logLevel: 0,
bare: {
version: 2,
path: '/bare/',
},
tab: {
title: 'Service',
icon: null,
ua: null,
},
assets: {
prefix: '/dynamic/',
files: {
handler: 'dynamic.handler.js',
client: 'dynamic.client.js',
worker: 'dynamic.worker.js',
config: 'dynamic.config.js',
inject: null,
}
},
block: [
]
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

21
public/dysw.js Normal file
View file

@ -0,0 +1,21 @@
importScripts("/dynamic/dynamic.config.js");
importScripts("/dynamic/dynamic.worker.js");
const dynamic = new Dynamic();
self.dynamic = dynamic;
self.addEventListener("fetch", (event) => {
if (
event.request.url.startsWith(location.origin + self.__dynamic$config.prefix)
)
event.respondWith(
(async function () {
if (await dynamic.route(event)) {
return await dynamic.fetch(event);
}
return await fetch(event.request);
})()
);
});

View file

@ -1,7 +0,0 @@
importScripts("/uv/uv.bundle.js");
importScripts("/uv/uv.config.js");
importScripts(__uv$config.sw || "/uv/uv.sw.js");
const sw = new UVServiceWorker();
self.addEventListener("fetch", (event) => event.respondWith(sw.fetch(event)));

10
public/uvsw.js Normal file
View file

@ -0,0 +1,10 @@
importScripts("/uv/uv.bundle.js");
importScripts("/uv/uv.config.js");
importScripts(__uv$config.sw || "/uv/uv.sw.js");
const sw = new UVServiceWorker();
self.addEventListener("fetch", (event) => {
if (event.request.url.startsWith(location.origin + __uv$config.prefix))
return event.respondWith(sw.fetch(event));
});

View file

@ -4,6 +4,7 @@ import { useEffect, useState } from "preact/hooks";
declare global { declare global {
interface Window { interface Window {
__uv$config: any; __uv$config: any;
__dynamic$config: any;
} }
} }
@ -31,6 +32,13 @@ export function ProxyFrame(props: { url: string }) {
} else if (localProxy === "ultraviolet") { } else if (localProxy === "ultraviolet") {
window.location.href = window.location.href =
window.__uv$config.prefix + window.__uv$config.encodeUrl(decodedUrl); window.__uv$config.prefix + window.__uv$config.encodeUrl(decodedUrl);
} else if (localProxy === "dynamic") {
window.location.href =
window.__dynamic$config.prefix + encodeURIComponent(decodedUrl);
} else {
// use UV for automatic
window.location.href =
window.__uv$config.prefix + window.__uv$config.encodeUrl(decodedUrl);
} }
}, [localProxy]); }, [localProxy]);

View file

@ -28,7 +28,8 @@
"proxy": { "proxy": {
"title": "Proxy", "title": "Proxy",
"subtitle": "Choose the proxy that fits your needs", "subtitle": "Choose the proxy that fits your needs",
"automatic": "Automatic" "automatic": "Automatic",
"buggyWarning": "(BUGGY)"
}, },
"languages": { "languages": {
"title": "Language", "title": "Language",

View file

@ -6,7 +6,7 @@
"discord": "もっとリンクが欲しいですか?" "discord": "もっとリンクが欲しいですか?"
}, },
"404": { "404": {
"text": "このネビュラサービスは無効になっています", "text": "このネラサービスは無効になっています",
"return": "帰宅" "return": "帰宅"
}, },
"home": { "home": {
@ -28,7 +28,8 @@
"proxy": { "proxy": {
"title": "プロキシ", "title": "プロキシ",
"subtitle": "ニーズに合ったプロキシを選んでください", "subtitle": "ニーズに合ったプロキシを選んでください",
"automatic": "自動" "automatic": "自動",
"buggyWarning": "(バグ)"
}, },
"languages": { "languages": {
"title": "言語", "title": "言語",

View file

@ -9,7 +9,7 @@ const Proxy = ({ id, active }) => {
{ id: "automatic", label: t("settings.proxy.automatic") }, { id: "automatic", label: t("settings.proxy.automatic") },
{ id: "ultraviolet", label: "Ultraviolet" }, { id: "ultraviolet", label: "Ultraviolet" },
{ id: "rammerhead", label: "Rammerhead" }, { id: "rammerhead", label: "Rammerhead" },
{ id: "dynamic", label: "Dynamic" } { id: "dynamic", label: "Dynamic " + t("settings.proxy.buggyWarning") }
]; ];
return ( return (