Add dynamic, finishing basic proxy functionality
This commit is contained in:
parent
6d99559768
commit
db2b7a6c2f
13 changed files with 203 additions and 12 deletions
|
|
@ -8,12 +8,16 @@
|
|||
<title>Nebula</title>
|
||||
<script src="/uv/uv.bundle.js"></script>
|
||||
<script src="/uv/uv.config.js"></script>
|
||||
<script src="/dynamic/dynamic.config.js"></script>
|
||||
<script>
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker.register("/sw.js", {
|
||||
navigator.serviceWorker.register("/uvsw.js", {
|
||||
scope: __uv$config.prefix
|
||||
});
|
||||
navigator.serviceWorker.register("/dysw.js", {
|
||||
scope: __dynamic$config.prefix
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
38
public/dynamic/dynamic.client.js
Normal file
38
public/dynamic/dynamic.client.js
Normal file
File diff suppressed because one or more lines are too long
30
public/dynamic/dynamic.config.js
Normal file
30
public/dynamic/dynamic.config.js
Normal 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: [
|
||||
|
||||
]
|
||||
};
|
||||
38
public/dynamic/dynamic.handler.js
Normal file
38
public/dynamic/dynamic.handler.js
Normal file
File diff suppressed because one or more lines are too long
9
public/dynamic/dynamic.html.js
Normal file
9
public/dynamic/dynamic.html.js
Normal file
File diff suppressed because one or more lines are too long
38
public/dynamic/dynamic.worker.js
Normal file
38
public/dynamic/dynamic.worker.js
Normal file
File diff suppressed because one or more lines are too long
21
public/dysw.js
Normal file
21
public/dysw.js
Normal 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);
|
||||
})()
|
||||
);
|
||||
});
|
||||
|
|
@ -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
10
public/uvsw.js
Normal 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));
|
||||
});
|
||||
|
|
@ -4,6 +4,7 @@ import { useEffect, useState } from "preact/hooks";
|
|||
declare global {
|
||||
interface Window {
|
||||
__uv$config: any;
|
||||
__dynamic$config: any;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +32,13 @@ export function ProxyFrame(props: { url: string }) {
|
|||
} else if (localProxy === "ultraviolet") {
|
||||
window.location.href =
|
||||
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]);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@
|
|||
"proxy": {
|
||||
"title": "Proxy",
|
||||
"subtitle": "Choose the proxy that fits your needs",
|
||||
"automatic": "Automatic"
|
||||
"automatic": "Automatic",
|
||||
"buggyWarning": "(BUGGY)"
|
||||
},
|
||||
"languages": {
|
||||
"title": "Language",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
"discord": "もっとリンクが欲しいですか?"
|
||||
},
|
||||
"404": {
|
||||
"text": "このネビュラサービスは無効になっています",
|
||||
"text": "このネブラサービスは無効になっています",
|
||||
"return": "帰宅"
|
||||
},
|
||||
"home": {
|
||||
|
|
@ -28,7 +28,8 @@
|
|||
"proxy": {
|
||||
"title": "プロキシ",
|
||||
"subtitle": "ニーズに合ったプロキシを選んでください",
|
||||
"automatic": "自動"
|
||||
"automatic": "自動",
|
||||
"buggyWarning": "(バグ)"
|
||||
},
|
||||
"languages": {
|
||||
"title": "言語",
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const Proxy = ({ id, active }) => {
|
|||
{ id: "automatic", label: t("settings.proxy.automatic") },
|
||||
{ id: "ultraviolet", label: "Ultraviolet" },
|
||||
{ id: "rammerhead", label: "Rammerhead" },
|
||||
{ id: "dynamic", label: "Dynamic" }
|
||||
{ id: "dynamic", label: "Dynamic " + t("settings.proxy.buggyWarning") }
|
||||
];
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue