diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..993fee2 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,8 @@ +# Build artifacts +dist/ + +# Other things that don't need to be reformatted +public/uv/ +public/dynamic/ +pnpm-lock.yaml +package-lock.json diff --git a/.prettierrc b/.prettierrc index e902508..9a846d7 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,8 +1,8 @@ -{ - "singleQuote": false, - "endOfLine": "crlf", - "tabWidth": 2, - "useTabs": false, - "trailingComma": "none", - "plugins": ["prettier-plugin-tailwindcss"] -} +{ + "singleQuote": false, + "endOfLine": "crlf", + "tabWidth": 2, + "useTabs": false, + "trailingComma": "none", + "plugins": ["prettier-plugin-tailwindcss"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index ed78fd2..44a46f4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,12 +1,12 @@ -{ - "editor.tabSize": 2, - "editor.insertSpaces": true, - "editor.formatOnSave": true, - "editor.formatOnPaste": true, - "editor.defaultFormatter": "esbenp.prettier-vscode", - "files.autoSave": "afterDelay", - "files.autoSaveDelay": 0, - "css.lint.unknownAtRules": "ignore", - "editor.linkedEditing": true, - "css.lint.unknownProperties": "ignore" -} +{ + "editor.tabSize": 2, + "editor.insertSpaces": true, + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "files.autoSave": "afterDelay", + "files.autoSaveDelay": 0, + "css.lint.unknownAtRules": "ignore", + "editor.linkedEditing": true, + "css.lint.unknownProperties": "ignore" +} diff --git a/README.md b/README.md index 452a49d..4886cec 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -# Nebula rewrite -`npm i -g pnpm tsx` -`git clone https://github.com/NebulaServices/Nebula.git` -`git switch rewrite` -`pnpm i` - -readme meant for devs, will be changed before being merged into main +# Nebula rewrite + +`npm i -g pnpm tsx` +`git clone https://github.com/NebulaServices/Nebula.git` +`git switch rewrite` +`pnpm i` + +readme meant for devs, will be changed before being merged into main diff --git a/framer-motion.d.ts b/framer-motion.d.ts index b62fed5..44a8d8e 100644 --- a/framer-motion.d.ts +++ b/framer-motion.d.ts @@ -1,7 +1,7 @@ -import * as React from "preact/compat"; - -declare module "framer-motion" { - export interface AnimatePresenceProps { - children?: React.ReactNode; - } -} +import * as React from "preact/compat"; + +declare module "framer-motion" { + export interface AnimatePresenceProps { + children?: React.ReactNode; + } +} diff --git a/index.html b/index.html index 6603005..4a34c83 100644 --- a/index.html +++ b/index.html @@ -1,29 +1,29 @@ - - - - - - - - Nebula - - - - - - -
- - - + + + + + + + + Nebula + + + + + + +
+ + + diff --git a/package.json b/package.json index 90f2215..840af3e 100644 --- a/package.json +++ b/package.json @@ -1,46 +1,46 @@ -{ - "private": true, - "type": "module", - "scripts": { - "dev": "concurrently \"vite\" \"bare-server-node --port 8080\"", - "build": "vite build", - "bstart": "npm run build && tsx server.ts", - "preview": "vite preview", - "format": "prettier --write ." - }, - "dependencies": { - "@fastify/compress": "^6.5.0", - "@fastify/static": "^6.12.0", - "@titaniumnetwork-dev/ultraviolet": "^2.0.0", - "@tomphttp/bare-server-node": "^2.0.1", - "classnames": "^2.3.2", - "fastify": "^4.25.1", - "framer-motion": "^10.16.16", - "i18next": "^23.7.9", - "i18next-browser-languagedetector": "^7.2.0", - "million": "^2.6.4", - "preact": "^10.13.1", - "preact-iso": "^2.3.2", - "preact-render-to-string": "^6.3.1", - "preact-router": "^4.1.2", - "rammerhead": "https://github.com/holy-unblocker/rammerhead/releases/download/v1.2.41-holy.5/rammerhead-1.2.41-holy.5.tgz", - "react-helmet": "^6.1.0", - "react-i18next": "^13.5.0", - "react-icons": "^4.12.0", - "tsx": "^4.7.0" - }, - "devDependencies": { - "@preact/preset-vite": "^2.5.0", - "autoprefixer": "^10.4.16", - "concurrently": "^8.2.2", - "eslint": "^8.55.0", - "eslint-config-preact": "^1.3.0", - "postcss": "^8.4.32", - "prettier": "^3.1.1", - "prettier-plugin-tailwindcss": "^0.5.9", - "tailwindcss": "^3.3.6", - "typescript": "^5.3.3", - "vite": "^5.0.9", - "vite-plugin-static-copy": "^1.0.0" - } -} +{ + "private": true, + "type": "module", + "scripts": { + "dev": "concurrently \"vite\" \"bare-server-node --port 8080\"", + "build": "vite build", + "bstart": "npm run build && tsx server.ts", + "preview": "vite preview", + "format": "prettier --write ." + }, + "dependencies": { + "@fastify/compress": "^6.5.0", + "@fastify/static": "^6.12.0", + "@titaniumnetwork-dev/ultraviolet": "^2.0.0", + "@tomphttp/bare-server-node": "^2.0.1", + "classnames": "^2.3.2", + "fastify": "^4.25.1", + "framer-motion": "^10.16.16", + "i18next": "^23.7.9", + "i18next-browser-languagedetector": "^7.2.0", + "million": "^2.6.4", + "preact": "^10.13.1", + "preact-iso": "^2.3.2", + "preact-render-to-string": "^6.3.1", + "preact-router": "^4.1.2", + "rammerhead": "https://github.com/holy-unblocker/rammerhead/releases/download/v1.2.41-holy.5/rammerhead-1.2.41-holy.5.tgz", + "react-helmet": "^6.1.0", + "react-i18next": "^13.5.0", + "react-icons": "^4.12.0", + "tsx": "^4.7.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.5.0", + "autoprefixer": "^10.4.16", + "concurrently": "^8.2.2", + "eslint": "^8.55.0", + "eslint-config-preact": "^1.3.0", + "postcss": "^8.4.32", + "prettier": "^3.1.1", + "prettier-plugin-tailwindcss": "^0.5.9", + "tailwindcss": "^3.3.6", + "typescript": "^5.3.3", + "vite": "^5.0.9", + "vite-plugin-static-copy": "^1.0.0" + } +} diff --git a/postcss.config.js b/postcss.config.js index ba80730..82fbe55 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,6 +1,6 @@ -export default { - plugins: { - tailwindcss: {}, - autoprefixer: {} - } -}; +export default { + plugins: { + tailwindcss: {}, + autoprefixer: {} + } +}; diff --git a/public/dysw.js b/public/dysw.js index ca32265..1159615 100644 --- a/public/dysw.js +++ b/public/dysw.js @@ -1,21 +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); - })() - ); -}); +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); + })() + ); +}); diff --git a/public/uvsw.js b/public/uvsw.js index d64cacc..ae7354b 100644 --- a/public/uvsw.js +++ b/public/uvsw.js @@ -1,10 +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)); -}); +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)); +}); diff --git a/server.ts b/server.ts index b9fa1a9..a2c413e 100644 --- a/server.ts +++ b/server.ts @@ -1,86 +1,86 @@ -import fastify from 'fastify'; -import fastifyStatic from '@fastify/static'; -import { fileURLToPath } from 'url'; -import path from 'path'; -import createRammerhead from "rammerhead/src/server/index.js"; -import { createBareServer } from "@tomphttp/bare-server-node"; -import { createServer } from "http"; - -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); - -const bare = createBareServer("/bare/"); -const rh = createRammerhead(); - -const rammerheadScopes = [ - "/rammerhead.js", - "/hammerhead.js", - "/transport-worker.js", - "/task.js", - "/iframe-task.js", - "/worker-hammerhead.js", - "/messaging", - "/sessionexists", - "/deletesession", - "/newsession", - "/editsession", - "/needpassword", - "/syncLocalStorage", - "/api/shuffleDict", - "/mainport" -]; - -const rammerheadSession = /^\/[a-z0-9]{32}/; - -function shouldRouteRh(req) { - const url = new URL(req.url, "http://0.0.0.0"); - return ( - rammerheadScopes.includes(url.pathname) || - rammerheadSession.test(url.pathname) - ); -} - -function routeRhRequest(req, res) { - rh.emit("request", req, res); -} - -function routeRhUpgrade(req, socket, head) { - rh.emit("upgrade", req, socket, head); -} - -const serverFactory = (handler, opts) => { - return createServer() - .on("request", (req, res) => { - if (bare.shouldRoute(req)) { - bare.routeRequest(req, res); - } else if (shouldRouteRh(req)) { - routeRhRequest(req, res); - } else { - handler(req, res); - } - }) - .on("upgrade", (req, socket, head) => { - if (bare.shouldRoute(req)) { - bare.routeUpgrade(req, socket, head); - } else if (shouldRouteRh(req)) { - routeRhUpgrade(req, socket, head); - } - }); -}; - -const app = fastify({ logger: true, serverFactory }); - -app.register(fastifyStatic, { - root: path.join(__dirname, 'dist'), - prefix: '/', - serve: true, - wildcard: false, -}); - -app.setNotFoundHandler((req, res) => { - res.sendFile('index.html') // SPA catch-all -}) - -app.listen({ - port: 8080 -}); \ No newline at end of file +import fastify from "fastify"; +import fastifyStatic from "@fastify/static"; +import { fileURLToPath } from "url"; +import path from "path"; +import createRammerhead from "rammerhead/src/server/index.js"; +import { createBareServer } from "@tomphttp/bare-server-node"; +import { createServer } from "http"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const bare = createBareServer("/bare/"); +const rh = createRammerhead(); + +const rammerheadScopes = [ + "/rammerhead.js", + "/hammerhead.js", + "/transport-worker.js", + "/task.js", + "/iframe-task.js", + "/worker-hammerhead.js", + "/messaging", + "/sessionexists", + "/deletesession", + "/newsession", + "/editsession", + "/needpassword", + "/syncLocalStorage", + "/api/shuffleDict", + "/mainport" +]; + +const rammerheadSession = /^\/[a-z0-9]{32}/; + +function shouldRouteRh(req) { + const url = new URL(req.url, "http://0.0.0.0"); + return ( + rammerheadScopes.includes(url.pathname) || + rammerheadSession.test(url.pathname) + ); +} + +function routeRhRequest(req, res) { + rh.emit("request", req, res); +} + +function routeRhUpgrade(req, socket, head) { + rh.emit("upgrade", req, socket, head); +} + +const serverFactory = (handler, opts) => { + return createServer() + .on("request", (req, res) => { + if (bare.shouldRoute(req)) { + bare.routeRequest(req, res); + } else if (shouldRouteRh(req)) { + routeRhRequest(req, res); + } else { + handler(req, res); + } + }) + .on("upgrade", (req, socket, head) => { + if (bare.shouldRoute(req)) { + bare.routeUpgrade(req, socket, head); + } else if (shouldRouteRh(req)) { + routeRhUpgrade(req, socket, head); + } + }); +}; + +const app = fastify({ logger: true, serverFactory }); + +app.register(fastifyStatic, { + root: path.join(__dirname, "dist"), + prefix: "/", + serve: true, + wildcard: false +}); + +app.setNotFoundHandler((req, res) => { + res.sendFile("index.html"); // SPA catch-all +}); + +app.listen({ + port: 8080 +}); diff --git a/src/components/HeaderRoute.tsx b/src/components/HeaderRoute.tsx index 43fedec..989c129 100644 --- a/src/components/HeaderRoute.tsx +++ b/src/components/HeaderRoute.tsx @@ -1,12 +1,12 @@ -import { Header } from "./Header"; - -export function HeaderRoute(props: { children: any }) { - return ( -
-
-
-
{props.children}
-
-
- ); -} +import { Header } from "./Header"; + +export function HeaderRoute(props: { children: any }) { + return ( +
+
+
+
{props.children}
+
+
+ ); +} diff --git a/src/components/iframe/Iframe.tsx b/src/components/iframe/Iframe.tsx index 4670203..735f828 100644 --- a/src/components/iframe/Iframe.tsx +++ b/src/components/iframe/Iframe.tsx @@ -1,13 +1,23 @@ -import { motion } from "framer-motion" -import { IframeHeader } from "./IframeHeader" - -export function Iframe(props: { url: string }) { - return ( - <> - - - - - - `); - newDocument.close() - window.location.replace("/"); - } - - return ( -
- {proxyMode === "direct" &&

Loading {localProxy}...

} - {proxyMode === "aboutblank" &&

Loading {localProxy}...

} - {proxyMode === "embed" && + + + `); + newDocument.close(); + window.location.replace("/"); + } + + return ( +
+ {proxyMode === "direct" &&

Loading {localProxy}...

} + {proxyMode === "aboutblank" &&

Loading {localProxy}...

} + {proxyMode === "embed" && ( +