diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 22a1505..2592970 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,4 +1,4 @@ { - "recommendations": ["astro-build.astro-vscode"], - "unwantedRecommendations": [] + "recommendations": ["astro-build.astro-vscode"], + "unwantedRecommendations": [] } diff --git a/.vscode/launch.json b/.vscode/launch.json index d642209..e368c54 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,11 +1,11 @@ { - "version": "0.2.0", - "configurations": [ - { - "command": "./node_modules/.bin/astro dev", - "name": "Development server", - "request": "launch", - "type": "node-terminal" - } - ] + "version": "0.2.0", + "configurations": [ + { + "command": "./node_modules/.bin/astro dev", + "name": "Development server", + "request": "launch", + "type": "node-terminal" + } + ] } diff --git a/astro.config.mjs b/astro.config.mjs index 30cf99e..2753c9f 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -9,72 +9,72 @@ import icon from "astro-icon"; import { defineConfig } from "astro/config"; import { viteStaticCopy } from "vite-plugin-static-copy"; export default defineConfig({ - integrations: [tailwind(), icon(), svelte()], - vite: { - plugins: [ - viteStaticCopy({ - targets: [ - { - src: `${uvPath}/**/*`.replace(/\\/g, "/"), - dest: "uv", - overwrite: false - }, - { - src: `${epoxyPath}/**/*`.replace(/\\/g, "/"), - dest: "epoxy", - overwrite: false - }, - { - src: `${libcurlPath}/**/*`.replace(/\\/g, "/"), - dest: "libcurl", - overwrite: false - }, - { - src: `${baremuxPath}/**/*`.replace(/\\/g, "/"), - dest: "baremux", - overwrite: false - } - ] - }) - ], - server: { - proxy: { - "/api/catalog-assets": { - target: "http://localhost:8080/api/catalog-assets", - changeOrigin: true, - rewrite: (path) => path.replace(/^\/api\/catalog-assets/, "") - }, - "/images": { - target: "http://localhost:8080", - changeOrigin: true - }, - "/videos": { - target: "http://localhost:8080", - changeOrigin: true - }, - "/wisp/": { - target: "ws://localhost:8080/wisp/", - changeOrigin: true, - ws: true, - rewrite: (path) => path.replace(/^\/wisp\//, "") - }, - "/styles": { - target: "http://localhost:8080", - changeOrigin: true - }, - "/api/packages": { - target: "http://localhost:8080", - changeOrigin: true - }, - "/api/catalog-pages": { - target: "http://localhost:8080", - changeOrigin: true + integrations: [tailwind(), icon(), svelte()], + vite: { + plugins: [ + viteStaticCopy({ + targets: [ + { + src: `${uvPath}/**/*`.replace(/\\/g, "/"), + dest: "uv", + overwrite: false + }, + { + src: `${epoxyPath}/**/*`.replace(/\\/g, "/"), + dest: "epoxy", + overwrite: false + }, + { + src: `${libcurlPath}/**/*`.replace(/\\/g, "/"), + dest: "libcurl", + overwrite: false + }, + { + src: `${baremuxPath}/**/*`.replace(/\\/g, "/"), + dest: "baremux", + overwrite: false + } + ] + }) + ], + server: { + proxy: { + "/api/catalog-assets": { + target: "http://localhost:8080/api/catalog-assets", + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api\/catalog-assets/, "") + }, + "/images": { + target: "http://localhost:8080", + changeOrigin: true + }, + "/videos": { + target: "http://localhost:8080", + changeOrigin: true + }, + "/wisp/": { + target: "ws://localhost:8080/wisp/", + changeOrigin: true, + ws: true, + rewrite: (path) => path.replace(/^\/wisp\//, "") + }, + "/styles": { + target: "http://localhost:8080", + changeOrigin: true + }, + "/api/packages": { + target: "http://localhost:8080", + changeOrigin: true + }, + "/api/catalog-pages": { + target: "http://localhost:8080", + changeOrigin: true + } + } } - } - } - }, - output: "server", - adapter: node({ - mode: "hybrid" - }) + }, + output: "server", + adapter: node({ + mode: "hybrid" + }) }); diff --git a/biome.json b/biome.json index 0750cf9..53feb84 100644 --- a/biome.json +++ b/biome.json @@ -1,32 +1,32 @@ { - "$schema": "https://biomejs.dev/schemas/1.9.3/schema.json", - "files": { - "ignore": ["~/", "**/dist/**", ".github/**"], - "include": ["**/**", "server/**"] - }, - "formatter": { - "indentStyle": "space", - "indentWidth": 2, - "lineWidth": 100, - "ignore": ["pnpm-lock.yaml", "package.json"] - }, - "organizeImports": { "enabled": true }, - "linter": { "enabled": false }, - "javascript": { - "formatter": { - "trailingCommas": "none", - "quoteStyle": "double", - "semicolons": "always" - } - }, - "json": { - "parser": { - "allowComments": true, - "allowTrailingCommas": true + "$schema": "https://biomejs.dev/schemas/1.9.3/schema.json", + "files": { + "ignore": ["~/", "**/dist/**", ".github/**"], + "include": ["**/**", "server/**"] }, "formatter": { - "indentStyle": "space", - "trailingCommas": "none" + "indentStyle": "space", + "indentWidth": 4, + "lineWidth": 100, + "ignore": ["pnpm-lock.yaml", "package.json"] + }, + "organizeImports": { "enabled": true }, + "linter": { "enabled": false }, + "javascript": { + "formatter": { + "trailingCommas": "none", + "quoteStyle": "double", + "semicolons": "always" + } + }, + "json": { + "parser": { + "allowComments": true, + "allowTrailingCommas": true + }, + "formatter": { + "indentStyle": "space", + "trailingCommas": "none" + } } - } } diff --git a/config.json b/config.json index 51f5da4..b2ca0e4 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "marketplace_enabled": true, - "marketplace_psk": "CHANGE_THIS_THIS_IS_INSECURE", - "marketplace_level": "1" + "marketplace_enabled": true, + "marketplace_psk": "CHANGE_THIS_THIS_IS_INSECURE", + "marketplace_level": "1" } diff --git a/database_assets/styles/com.nebula.cybermonay.css b/database_assets/styles/com.nebula.cybermonay.css index 8cb9857..8cf33f6 100644 --- a/database_assets/styles/com.nebula.cybermonay.css +++ b/database_assets/styles/com.nebula.cybermonay.css @@ -1,19 +1,19 @@ :root { - --background-primary: rgba(0, 0, 0, 0); - --background-lighter: #000; - --navbar-color: #000; - --navbar-height: 60px; - --navbar-text-color: greenyellow; - --navbar-link-color: greenyellow; - --navbar-link-hover-color: green; - --navbar-font: "Roboto"; - --input-text-color: greenyellow; - --input-placeholder-color: white; - --input-background-color: #000; - --input-border-color: greenyellow; - --input-border-size: 1.3px; - --navbar-logo-filter: none; - --dropdown-option-hover-color: #312a49; - --tab-color: var(--black); - --border-color: greenyellow; + --background-primary: rgba(0, 0, 0, 0); + --background-lighter: #000; + --navbar-color: #000; + --navbar-height: 60px; + --navbar-text-color: greenyellow; + --navbar-link-color: greenyellow; + --navbar-link-hover-color: green; + --navbar-font: "Roboto"; + --input-text-color: greenyellow; + --input-placeholder-color: white; + --input-background-color: #000; + --input-border-color: greenyellow; + --input-border-size: 1.3px; + --navbar-logo-filter: none; + --dropdown-option-hover-color: #312a49; + --tab-color: var(--black); + --border-color: greenyellow; } diff --git a/public/nebula.css b/public/nebula.css index 954e7c1..128833b 100644 --- a/public/nebula.css +++ b/public/nebula.css @@ -1,19 +1,19 @@ :root { - --background-primary: #191724; - --background-lighter: #16121f; - --navbar-color: #26233a; - --navbar-height: 60px; - --navbar-text-color: #7967dd; - --navbar-link-color: #e0def4; - --navbar-link-hover-color: gray; - --navbar-font: "Roboto"; - --input-text-color: #e0def4; - --input-placeholder-color: white; - --input-background-color: #1f1d2e; - --input-border-color: #eb6f92; - --input-border-size: 1.3px; - --navbar-logo-filter: none; - --dropdown-option-hover-color: #312a49; - --tab-color: var(--black); - --border-color: #16121f; + --background-primary: #191724; + --background-lighter: #16121f; + --navbar-color: #26233a; + --navbar-height: 60px; + --navbar-text-color: #7967dd; + --navbar-link-color: #e0def4; + --navbar-link-hover-color: gray; + --navbar-font: "Roboto"; + --input-text-color: #e0def4; + --input-placeholder-color: white; + --input-background-color: #1f1d2e; + --input-border-color: #eb6f92; + --input-border-size: 1.3px; + --navbar-logo-filter: none; + --dropdown-option-hover-color: #312a49; + --tab-color: var(--black); + --border-color: #16121f; } diff --git a/public/sw.js b/public/sw.js index 0dfee8c..d48ffab 100644 --- a/public/sw.js +++ b/public/sw.js @@ -5,17 +5,17 @@ importScripts("/uv/uv.config.js"); importScripts(__uv$config.sw || "/uv/uv.sw.js"); const uv = new UVServiceWorker(); self.addEventListener("fetch", function (event) { - if (event.request.url.startsWith(location.origin + __uv$config.prefix)) { - event.respondWith( - (async function () { - return await uv.fetch(event); - })() - ); - } else { - event.respondWith( - (async function () { - return await fetch(event.request); - })() - ); - } + if (event.request.url.startsWith(location.origin + __uv$config.prefix)) { + event.respondWith( + (async function () { + return await uv.fetch(event); + })() + ); + } else { + event.respondWith( + (async function () { + return await fetch(event.request); + })() + ); + } }); diff --git a/public/uv/uv.config.js b/public/uv/uv.config.js index 76b6594..dc4ab97 100644 --- a/public/uv/uv.config.js +++ b/public/uv/uv.config.js @@ -1,30 +1,30 @@ self.__uv$config = { - prefix: "/~/uv/", - bare: "/bare/", - encodeUrl: function encode(str) { - if (!str) return str; - return encodeURIComponent( - str - .toString() - .split("") - .map((char, ind) => (ind % 2 ? String.fromCharCode(char.charCodeAt() ^ 3) : char)) - .join("") - ); - }, - decodeUrl: function decode(str) { - if (!str) return str; - let [input, ...search] = str.split("?"); + prefix: "/~/uv/", + bare: "/bare/", + encodeUrl: function encode(str) { + if (!str) return str; + return encodeURIComponent( + str + .toString() + .split("") + .map((char, ind) => (ind % 2 ? String.fromCharCode(char.charCodeAt() ^ 3) : char)) + .join("") + ); + }, + decodeUrl: function decode(str) { + if (!str) return str; + let [input, ...search] = str.split("?"); - return ( - decodeURIComponent(input) - .split("") - .map((char, ind) => (ind % 2 ? String.fromCharCode(char.charCodeAt(0) ^ 3) : char)) - .join("") + (search.length ? "?" + search.join("?") : "") - ); - }, - handler: "/uv/uv.handler.js", - client: "/uv/uv.client.js", - bundle: "/uv/uv.bundle.js", - config: "/uv/uv.config.js", - sw: "/uv/uv.sw.js" + return ( + decodeURIComponent(input) + .split("") + .map((char, ind) => (ind % 2 ? String.fromCharCode(char.charCodeAt(0) ^ 3) : char)) + .join("") + (search.length ? "?" + search.join("?") : "") + ); + }, + handler: "/uv/uv.handler.js", + client: "/uv/uv.client.js", + bundle: "/uv/uv.bundle.js", + config: "/uv/uv.config.js", + sw: "/uv/uv.sw.js" }; diff --git a/server.js b/server.js index 8127829..0f55d76 100644 --- a/server.js +++ b/server.js @@ -3,10 +3,10 @@ import { createServer } from "node:http"; import path from "path"; import { fileURLToPath } from "url"; import { - createRammerhead, - routeRhRequest, - routeRhUpgrade, - shouldRouteRh + createRammerhead, + routeRhRequest, + routeRhUpgrade, + shouldRouteRh } from "@rubynetwork/rammerhead"; import express from "express"; import multer from "multer"; @@ -19,71 +19,71 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); //create the rh server. const rh = createRammerhead({ - logLevel: "debug", - reverseProxy: true, - disableLocalStorageSync: false, - disableHttp2: false + logLevel: "debug", + reverseProxy: true, + disableLocalStorageSync: false, + disableHttp2: false }); const app = express(); const publicPath = "dist/client"; const sequelize = new Sequelize("database", "user", "password", { - host: "localhost", - dialect: "sqlite", - logging: false, - // SQLite only - storage: "database.sqlite" + host: "localhost", + dialect: "sqlite", + logging: false, + // SQLite only + storage: "database.sqlite" }); // Auth middleware function auth_psk(req, res, next) { - if (!config.marketplace_enabled) { - let err = "Marketplace is disabled!"; - return next(err); - } + if (!config.marketplace_enabled) { + let err = "Marketplace is disabled!"; + return next(err); + } - if (req.headers.psk !== config.marketplace_psk) { - let err = "Bad PSK!"; - console.log("Bad psk"); - return next(err); - } + if (req.headers.psk !== config.marketplace_psk) { + let err = "Bad PSK!"; + console.log("Bad psk"); + return next(err); + } - return next(); + return next(); } var image_storage = multer.diskStorage({ - destination: function (req, file, cb) { - cb(null, "database_assets/image"); - }, - filename: function (req, file, cb) { - cb(null, file.originalname); //Appending extension - } + destination: function (req, file, cb) { + cb(null, "database_assets/image"); + }, + filename: function (req, file, cb) { + cb(null, file.originalname); //Appending extension + } }); var video_storage = multer.diskStorage({ - destination: function (req, file, cb) { - cb(null, "database_assets/video"); - }, - filename: function (req, file, cb) { - cb(null, file.originalname); //Appending extension - } + destination: function (req, file, cb) { + cb(null, "database_assets/video"); + }, + filename: function (req, file, cb) { + cb(null, file.originalname); //Appending extension + } }); var style_storage = multer.diskStorage({ - destination: function (req, file, cb) { - cb(null, "database_assets/styles"); - }, - filename: function (req, file, cb) { - cb(null, file.originalname); //Appending extension - } + destination: function (req, file, cb) { + cb(null, "database_assets/styles"); + }, + filename: function (req, file, cb) { + cb(null, file.originalname); //Appending extension + } }); var script_storage = multer.diskStorage({ - destination: function (req, file, cb) { - cb(null, "database_assets/scripts"); - }, - filename: function (req, file, cb) { - cb(null, file.originalname); //Appending extension - } + destination: function (req, file, cb) { + cb(null, "database_assets/scripts"); + }, + filename: function (req, file, cb) { + cb(null, file.originalname); //Appending extension + } }); var image_upload = multer({ storage: image_storage }); @@ -92,198 +92,198 @@ var style_upload = multer({ storage: style_storage }); var script_upload = multer({ storage: script_storage }); const catalog_assets = sequelize.define("catalog_assets", { - package_name: { - type: DataTypes.TEXT, - unique: true - }, - title: { - type: DataTypes.TEXT - }, - description: { - type: DataTypes.TEXT - }, - author: { - type: DataTypes.TEXT - }, - image: { - type: DataTypes.TEXT - }, - tags: { - type: DataTypes.JSON, - allowNull: true - }, - version: { - type: DataTypes.TEXT - }, - background_image: { - type: DataTypes.TEXT, - allowNull: true - }, - background_video: { - type: DataTypes.TEXT, - allowNull: true - }, - payload: { - type: DataTypes.TEXT - }, - type: { - type: DataTypes.TEXT - } + package_name: { + type: DataTypes.TEXT, + unique: true + }, + title: { + type: DataTypes.TEXT + }, + description: { + type: DataTypes.TEXT + }, + author: { + type: DataTypes.TEXT + }, + image: { + type: DataTypes.TEXT + }, + tags: { + type: DataTypes.JSON, + allowNull: true + }, + version: { + type: DataTypes.TEXT + }, + background_image: { + type: DataTypes.TEXT, + allowNull: true + }, + background_video: { + type: DataTypes.TEXT, + allowNull: true + }, + payload: { + type: DataTypes.TEXT + }, + type: { + type: DataTypes.TEXT + } }); app.use(express.json()); app.get("/api", function (request, reply) { - reply.send({ hello: "world" }); + reply.send({ hello: "world" }); }); // This API returns a list of the assets in the database (SW plugins and themes). // It also returns the number of pages in the database. // It can take a `?page=x` argument to display a different page, with a limit of 20 assets per page. app.get("/api/catalog-assets", async (request, reply) => { - try { - const page = parseInt(request.query.page, 10) || 1; // default to page 1 + try { + const page = parseInt(request.query.page, 10) || 1; // default to page 1 - const totalItems = await catalog_assets.count(); + const totalItems = await catalog_assets.count(); - if (page < 1) { - reply.status(400).send({ error: "Page must be a positive number!" }); - return; + if (page < 1) { + reply.status(400).send({ error: "Page must be a positive number!" }); + return; + } + + const offset = (page - 1) * 20; + + const db_assets = await catalog_assets.findAll({ + offset: offset, + limit: 20 + }); + + const assets = db_assets.reduce((acc, asset) => { + acc[asset.package_name] = { + title: asset.title, + description: asset.description, + author: asset.author, + image: asset.image, + tags: asset.tags, + version: asset.version, + background_image: asset.background_image, + background_video: asset.background_video, + payload: asset.payload, + type: asset.type + }; + return acc; + }, {}); + + reply.send({ assets, pages: Math.ceil(totalItems / 20) }); + } catch (error) { + reply.status(500).send({ error: "There was an error" }); } - - const offset = (page - 1) * 20; - - const db_assets = await catalog_assets.findAll({ - offset: offset, - limit: 20 - }); - - const assets = db_assets.reduce((acc, asset) => { - acc[asset.package_name] = { - title: asset.title, - description: asset.description, - author: asset.author, - image: asset.image, - tags: asset.tags, - version: asset.version, - background_image: asset.background_image, - background_video: asset.background_video, - payload: asset.payload, - type: asset.type - }; - return acc; - }, {}); - - reply.send({ assets, pages: Math.ceil(totalItems / 20) }); - } catch (error) { - reply.status(500).send({ error: "There was an error" }); - } }); // This API returns data about a single package. app.get("/api/packages/:package", async (request, reply) => { - try { - console.log(request.params.package); + try { + console.log(request.params.package); - const package_row = await catalog_assets.findOne({ - where: { package_name: request.params.package } - }); + const package_row = await catalog_assets.findOne({ + where: { package_name: request.params.package } + }); - if (!package_row) { - return reply.status(404).send({ error: "Package not found!" }); + if (!package_row) { + return reply.status(404).send({ error: "Package not found!" }); + } + + const details = { + title: package_row.get("title"), + description: package_row.get("description"), + image: package_row.get("image"), + author: package_row.get("author"), + tags: package_row.get("tags"), + version: package_row.get("version"), + background_image: package_row.get("background_image"), + background_video: package_row.get("background_video"), + payload: package_row.get("payload"), + type: package_row.get("type") + }; + reply.send(details); + } catch (error) { + reply.status(500).send({ error: "There was an error" }); } - - const details = { - title: package_row.get("title"), - description: package_row.get("description"), - image: package_row.get("image"), - author: package_row.get("author"), - tags: package_row.get("tags"), - version: package_row.get("version"), - background_image: package_row.get("background_image"), - background_video: package_row.get("background_video"), - payload: package_row.get("payload"), - type: package_row.get("type") - }; - reply.send(details); - } catch (error) { - reply.status(500).send({ error: "There was an error" }); - } }); // This API is responsible for image uploads // PSK authentication required. app.post("/api/upload-image", auth_psk, image_upload.single("file"), (req, res) => { - console.log("Request file:", req.file); + console.log("Request file:", req.file); - if (!req.file) { - return res.status(400).json({ error: "No file uploaded" }); - } + if (!req.file) { + return res.status(400).json({ error: "No file uploaded" }); + } - console.log(req.file.originalname); - res.json({ - message: "File uploaded successfully", - filename: req.file.originalname - }); + console.log(req.file.originalname); + res.json({ + message: "File uploaded successfully", + filename: req.file.originalname + }); }); // This API is responsible for video uploads // PSK authentication required. app.post("/api/upload-video", auth_psk, video_upload.single("file"), (req, res) => { - if (!req.file) { - return res.status(400).json({ error: "No file uploaded" }); - } + if (!req.file) { + return res.status(400).json({ error: "No file uploaded" }); + } - res.json({ - message: "File uploaded successfully", - filename: req.file.originalname - }); + res.json({ + message: "File uploaded successfully", + filename: req.file.originalname + }); }); // This API is responsible for stylesheet uploads // PSK authentication required. app.post("/api/upload-style", auth_psk, style_upload.single("file"), (req, res) => { - if (!req.file) { - return res.status(400).json({ error: "No file uploaded" }); - } + if (!req.file) { + return res.status(400).json({ error: "No file uploaded" }); + } - res.json({ - message: "File uploaded successfully", - filename: req.file.originalname - }); + res.json({ + message: "File uploaded successfully", + filename: req.file.originalname + }); }); // This API is responsible for script/plugin uploads // PSK authentication required. app.post("/api/upload-script", auth_psk, script_upload.single("file"), (req, res) => { - if (!req.file) { - return res.status(400).json({ error: "No file uploaded" }); - } + if (!req.file) { + return res.status(400).json({ error: "No file uploaded" }); + } - res.json({ - message: "File uploaded successfully", - filename: req.file.originalname - }); + res.json({ + message: "File uploaded successfully", + filename: req.file.originalname + }); }); // This API is responsible for creating packages in the database. // PSK authentication required. app.post("/api/create-package", auth_psk, async function (req, res) { - console.log(req.body); - await catalog_assets.create({ - package_name: req.body.uuid, - title: req.body.title, - image: req.body.image_path, - author: req.body.author, - version: req.body.version, - description: req.body.description, - tags: req.body.tags, - payload: req.body.payload, - background_video: req.body.background_video_path, - background_image: req.body.background_image_path, - type: req.body.type - }); - res.send({ hello: "world" }); + console.log(req.body); + await catalog_assets.create({ + package_name: req.body.uuid, + title: req.body.title, + image: req.body.image_path, + author: req.body.author, + version: req.body.version, + description: req.body.description, + tags: req.body.tags, + payload: req.body.payload, + background_video: req.body.background_video_path, + background_image: req.body.background_image_path, + type: req.body.type + }); + res.send({ hello: "world" }); }); app.use("/images/", express.static("./database_assets/image")); @@ -323,23 +323,23 @@ catalog_assets.sync(); const server = createServer(); server.on("request", (req, res) => { - res.setHeader("Cross-Origin-Opener-Policy", "same-origin"); - res.setHeader("Cross-Origin-Embedder-Policy", "require-corp"); - if (shouldRouteRh(req)) { - routeRhRequest(rh, req, res); - } else { - app(req, res); - } + res.setHeader("Cross-Origin-Opener-Policy", "same-origin"); + res.setHeader("Cross-Origin-Embedder-Policy", "require-corp"); + if (shouldRouteRh(req)) { + routeRhRequest(rh, req, res); + } else { + app(req, res); + } }); server.on("upgrade", (req, socket, head) => { - if (shouldRouteRh(req)) { - routeRhUpgrade(rh, req, socket, head); - } else if (req.url.endsWith("/wisp/")) { - wisp.routeRequest(req, socket, head); - } + if (shouldRouteRh(req)) { + routeRhUpgrade(rh, req, socket, head); + } else if (req.url.endsWith("/wisp/")) { + wisp.routeRequest(req, socket, head); + } }); server.listen({ - port: 8080 + port: 8080 }); diff --git a/src/components/Card.astro b/src/components/Card.astro index e972406..e146b2b 100644 --- a/src/components/Card.astro +++ b/src/components/Card.astro @@ -1,8 +1,8 @@ --- interface Props { - title: string; - body: string; - href: string; + title: string; + body: string; + href: string; } const { href, title, body } = Astro.props; diff --git a/src/components/catalog/CatalogCard.svelte b/src/components/catalog/CatalogCard.svelte index e07524d..706d8f6 100644 --- a/src/components/catalog/CatalogCard.svelte +++ b/src/components/catalog/CatalogCard.svelte @@ -3,9 +3,9 @@ import { Suspense } from "@svelte-drama/suspense"; import { Settings } from "@utils/settings/index"; export let page; async function getAssets() { - const response = await fetch("/api/catalog-assets?page=" + page); - const data = await response.json(); - return data.assets; + const response = await fetch("/api/catalog-assets?page=" + page); + const data = await response.json(); + return data.assets; } const assets = getAssets(); diff --git a/src/components/catalog/InstalledThemes.svelte b/src/components/catalog/InstalledThemes.svelte index f9b46f0..d53ab41 100644 --- a/src/components/catalog/InstalledThemes.svelte +++ b/src/components/catalog/InstalledThemes.svelte @@ -3,25 +3,25 @@ import { Suspense } from "@svelte-drama/suspense"; import { Settings, settings } from "@utils/settings/index"; import Parent from "./Parent.svelte"; async function getItem(item) { - try { - const response = await fetch(`/api/packages/${item}`); - const data = await response.json(); - return { - ...data, - package_name: item - }; - } catch (error) { - console.error("error: failed to fetch", error); - return null; - } + try { + const response = await fetch(`/api/packages/${item}`); + const data = await response.json(); + return { + ...data, + package_name: item + }; + } catch (error) { + console.error("error: failed to fetch", error); + return null; + } } async function getAssets() { - const items = JSON.parse(localStorage.getItem(Settings.AppearanceSettings.themes)) || []; - const promises = items.map(getItem); - const dataArray = await Promise.all(promises); - const accumulatedData = dataArray.filter((data) => data !== null); - console.log(JSON.stringify(accumulatedData)); - return accumulatedData; + const items = JSON.parse(localStorage.getItem(Settings.AppearanceSettings.themes)) || []; + const promises = items.map(getItem); + const dataArray = await Promise.all(promises); + const accumulatedData = dataArray.filter((data) => data !== null); + console.log(JSON.stringify(accumulatedData)); + return accumulatedData; } let assets = getAssets(); let compRef = []; diff --git a/src/components/settings/SettingsCard.astro b/src/components/settings/SettingsCard.astro index daad803..f918c57 100644 --- a/src/components/settings/SettingsCard.astro +++ b/src/components/settings/SettingsCard.astro @@ -1,30 +1,30 @@ --- interface Inputs { - input: boolean; - required?: boolean; - placeholder?: string; + input: boolean; + required?: boolean; + placeholder?: string; } interface SelectOptions { - value: string; - name: string; - disabled: boolean; + value: string; + name: string; + disabled: boolean; } interface Selects { - select: boolean; - name: string; - multiple?: boolean; - options?: SelectOptions[]; + select: boolean; + name: string; + multiple?: boolean; + options?: SelectOptions[]; } interface Buttons { - name: string; - id: string; + name: string; + id: string; } interface Props { - title: string; - description: string; - input: Inputs; - select: Selects; - button: Buttons; + title: string; + description: string; + input: Inputs; + select: Selects; + button: Buttons; } const { title, description, input, select, button } = Astro.props; diff --git a/src/components/toasts/Toast.svelte b/src/components/toasts/Toast.svelte index 14f400c..8334af1 100644 --- a/src/components/toasts/Toast.svelte +++ b/src/components/toasts/Toast.svelte @@ -3,38 +3,38 @@ import { type Position, type Props, type ToastType } from "@utils/toast.ts"; import toast from "svelte-french-toast"; export let toastProp: Props; function handleToast(toastProp: Props) { - switch (toastProp.toastType) { - case "success": - toast.success(toastProp.text, { - style: "background: var(--navbar-color); color: var(--input-text-color);", - icon: toastProp.emoji, - position: toastProp.position ?? "bottom-right", - duration: toastProp.duration - }); - break; - case "error": - toast.error(toastProp.text, { - style: "background: var(--navbar-color); color: var(--input-text-color);", - icon: toastProp.emoji, - position: toastProp.position ?? "bottom-right", - duration: toastProp.duration - }); - break; - case "promise": - throw new Error("Due to the way astro renders promise toasts are not available (ish)"); - break; - case "multiline": - toast(toastProp.text, { - style: "background: var(--navbar-color); color: var(--input-text-color);", - icon: toastProp.emoji, - position: toastProp.position ?? "bottom-right", - duration: toastProp.duration - }); - break; - default: - throw new Error("Something isn't right..."); - break; - } + switch (toastProp.toastType) { + case "success": + toast.success(toastProp.text, { + style: "background: var(--navbar-color); color: var(--input-text-color);", + icon: toastProp.emoji, + position: toastProp.position ?? "bottom-right", + duration: toastProp.duration + }); + break; + case "error": + toast.error(toastProp.text, { + style: "background: var(--navbar-color); color: var(--input-text-color);", + icon: toastProp.emoji, + position: toastProp.position ?? "bottom-right", + duration: toastProp.duration + }); + break; + case "promise": + throw new Error("Due to the way astro renders promise toasts are not available (ish)"); + break; + case "multiline": + toast(toastProp.text, { + style: "background: var(--navbar-color); color: var(--input-text-color);", + icon: toastProp.emoji, + position: toastProp.position ?? "bottom-right", + duration: toastProp.duration + }); + break; + default: + throw new Error("Something isn't right..."); + break; + } } diff --git a/src/i18n/en_US.json b/src/i18n/en_US.json index 9851f34..2882bc8 100644 --- a/src/i18n/en_US.json +++ b/src/i18n/en_US.json @@ -1,12 +1,12 @@ { - "header.home": "Home", - "header.games": "Games", - "header.settings": "Settings", - "header.morelinks": "Want more links?", - "header.catalog": "Nebula Catalog", - "home.placeholder": "Search the web freely", - "settings.settings": "Settings", - "settings.appearance": "Appearance", - "settings.proxy": "Proxy", - "settings.tab": "Tab" + "header.home": "Home", + "header.games": "Games", + "header.settings": "Settings", + "header.morelinks": "Want more links?", + "header.catalog": "Nebula Catalog", + "home.placeholder": "Search the web freely", + "settings.settings": "Settings", + "settings.appearance": "Appearance", + "settings.proxy": "Proxy", + "settings.tab": "Tab" } diff --git a/src/i18n/jp.json b/src/i18n/jp.json index 3ecc4d3..ffba9a9 100644 --- a/src/i18n/jp.json +++ b/src/i18n/jp.json @@ -1,12 +1,12 @@ { - "header.home": "ホーム", - "header.games": "ゲーム", - "header.settings": "設定", - "header.morelinks": "リンク一覧", - "header.catalog": "Nebula Catalog", - "home.placeholder": "検索欄", - "settings.settings": "Settings", - "settings.appearance": "Appearance", - "settings.proxy": "Proxy", - "settings.tab": "Tab" + "header.home": "ホーム", + "header.games": "ゲーム", + "header.settings": "設定", + "header.morelinks": "リンク一覧", + "header.catalog": "Nebula Catalog", + "home.placeholder": "検索欄", + "settings.settings": "Settings", + "settings.appearance": "Appearance", + "settings.proxy": "Proxy", + "settings.tab": "Tab" } diff --git a/src/i18n/ui.ts b/src/i18n/ui.ts index 9f09e58..257e6fe 100644 --- a/src/i18n/ui.ts +++ b/src/i18n/ui.ts @@ -4,6 +4,6 @@ import jp from "./jp.json"; export const defaultLang = "en_US"; export const ui = { - en_US, - jp + en_US, + jp }; diff --git a/src/i18n/utils.ts b/src/i18n/utils.ts index 2b33c01..2fd1263 100644 --- a/src/i18n/utils.ts +++ b/src/i18n/utils.ts @@ -3,13 +3,13 @@ import { defaultLang, ui } from "./ui"; export const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; export function getLangFromUrl(url: URL) { - const [, lang] = url.pathname.split("/"); - if (lang in ui) return lang as keyof typeof ui; - return defaultLang; + const [, lang] = url.pathname.split("/"); + if (lang in ui) return lang as keyof typeof ui; + return defaultLang; } export function useTranslations(lang: keyof typeof ui) { - return function t(key: keyof (typeof ui)[typeof defaultLang]) { - return ui[lang][key] || ui[defaultLang][key]; - }; + return function t(key: keyof (typeof ui)[typeof defaultLang]) { + return ui[lang][key] || ui[defaultLang][key]; + }; } diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index b21a606..65e86cd 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -4,8 +4,8 @@ import Header from "@components/Header.astro"; import MobileNavigation from "@components/MobileNavigation.astro"; import SettingsLoader from "@components/settings/Loader.astro"; interface Props { - title: string; - noHeader?: string; + title: string; + noHeader?: string; } const { title, noHeader } = Astro.props; diff --git a/src/pages/[lang]/games.astro b/src/pages/[lang]/games.astro index 9aad7ce..8bdab4e 100644 --- a/src/pages/[lang]/games.astro +++ b/src/pages/[lang]/games.astro @@ -1,8 +1,8 @@ --- import Layout from "@layouts/Layout.astro"; export function getStaticPaths() { - const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; - return STATIC_PATHS; + const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; + return STATIC_PATHS; } export const prerender = true; --- diff --git a/src/pages/[lang]/index.astro b/src/pages/[lang]/index.astro index 27bd464..479ca63 100644 --- a/src/pages/[lang]/index.astro +++ b/src/pages/[lang]/index.astro @@ -3,8 +3,8 @@ import Logo from "@components/Logo.astro"; import Layout from "@layouts/Layout.astro"; import { getLangFromUrl, useTranslations } from "../../i18n/utils"; export function getStaticPaths() { - const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; - return STATIC_PATHS; + const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; + return STATIC_PATHS; } export const prerender = true; const lang = getLangFromUrl(Astro.url); diff --git a/src/pages/[lang]/settings/appearance.astro b/src/pages/[lang]/settings/appearance.astro index f052040..90897ee 100644 --- a/src/pages/[lang]/settings/appearance.astro +++ b/src/pages/[lang]/settings/appearance.astro @@ -8,8 +8,8 @@ import { getLangFromUrl, useTranslations } from "../../../i18n/utils"; const lang = getLangFromUrl(Astro.url); const t = useTranslations(lang); export function getStaticPaths() { - const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; - return STATIC_PATHS; + const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; + return STATIC_PATHS; } export const prerender = true; --- diff --git a/src/pages/[lang]/settings/pr.astro b/src/pages/[lang]/settings/pr.astro index 38d2a2f..57365d1 100644 --- a/src/pages/[lang]/settings/pr.astro +++ b/src/pages/[lang]/settings/pr.astro @@ -10,8 +10,8 @@ import { getLangFromUrl, useTranslations } from "../../../i18n/utils"; const lang = getLangFromUrl(Astro.url); const t = useTranslations(lang); export function getStaticPaths() { - const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; - return STATIC_PATHS; + const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; + return STATIC_PATHS; } export const prerender = true; --- diff --git a/src/pages/[lang]/settings/tab.astro b/src/pages/[lang]/settings/tab.astro index e178266..c5d5be3 100644 --- a/src/pages/[lang]/settings/tab.astro +++ b/src/pages/[lang]/settings/tab.astro @@ -9,8 +9,8 @@ import { getLangFromUrl, useTranslations } from "../../../i18n/utils"; const lang = getLangFromUrl(Astro.url); const t = useTranslations(lang); export function getStaticPaths() { - const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; - return STATIC_PATHS; + const STATIC_PATHS = [{ params: { lang: "en_US" } }, { params: { lang: "jp" } }]; + return STATIC_PATHS; } export const prerender = true; --- diff --git a/src/utils/registerSW.ts b/src/utils/registerSW.ts index b071719..3716beb 100644 --- a/src/utils/registerSW.ts +++ b/src/utils/registerSW.ts @@ -1,71 +1,71 @@ import { Settings, WispServerURLS } from "./settings/index"; function loadProxyScripts() { - //wrap everything in a promise to avoid race conditions - return new Promise((resolve) => { - //create and append then scripts tags to the body (this is how we lazy load things) - const epoxyScript = document.createElement("script"); - epoxyScript.src = "/epoxy/index.js"; - epoxyScript.defer = true; - document.body.appendChild(epoxyScript); - const libCurlScript = document.createElement("script"); - libCurlScript.src = "/libcurl/index.js"; - libCurlScript.defer = true; - document.body.appendChild(libCurlScript); - const uvBundle = document.createElement("script"); - uvBundle.src = "/uv/uv.bundle.js"; - uvBundle.defer = true; - document.body.appendChild(uvBundle); - const uvConfig = document.createElement("script"); - uvConfig.src = "/uv/uv.config.js"; - uvConfig.defer = true; - document.body.appendChild(uvConfig); - const bareMux = document.createElement("script"); - bareMux.src = "/baremux/bare.cjs"; - bareMux.defer = true; - document.body.appendChild(bareMux); - const checkScripts = setInterval(() => { - //If both of these aren't defined this will repeat until they are - //this allows use to wait for all of the scripts to be ready *before* we setup the serviceworker - if (typeof EpxMod !== "undefined" && typeof BareMux !== "undefined") { - clearInterval(checkScripts); - resolve(); - } - }, 100); - }); + //wrap everything in a promise to avoid race conditions + return new Promise((resolve) => { + //create and append then scripts tags to the body (this is how we lazy load things) + const epoxyScript = document.createElement("script"); + epoxyScript.src = "/epoxy/index.js"; + epoxyScript.defer = true; + document.body.appendChild(epoxyScript); + const libCurlScript = document.createElement("script"); + libCurlScript.src = "/libcurl/index.js"; + libCurlScript.defer = true; + document.body.appendChild(libCurlScript); + const uvBundle = document.createElement("script"); + uvBundle.src = "/uv/uv.bundle.js"; + uvBundle.defer = true; + document.body.appendChild(uvBundle); + const uvConfig = document.createElement("script"); + uvConfig.src = "/uv/uv.config.js"; + uvConfig.defer = true; + document.body.appendChild(uvConfig); + const bareMux = document.createElement("script"); + bareMux.src = "/baremux/bare.cjs"; + bareMux.defer = true; + document.body.appendChild(bareMux); + const checkScripts = setInterval(() => { + //If both of these aren't defined this will repeat until they are + //this allows use to wait for all of the scripts to be ready *before* we setup the serviceworker + if (typeof EpxMod !== "undefined" && typeof BareMux !== "undefined") { + clearInterval(checkScripts); + resolve(); + } + }, 100); + }); } function setTransport(transport?: string) { - //wrap in a promise so we don't register sw until a transport is set. - const wispServer = localStorage.getItem(Settings.ProxySettings.wispServerURL); - return new Promise((resolve) => { - switch (transport) { - case "epoxy": - BareMux.SetTransport("EpxMod.default", { - wisp: wispServer ? WispServerURLS[wispServer] : WispServerURLS.default - }); - break; - case "libcurl": - BareMux.SetTransport("CurlMod.default", { - wisp: wispServer ? WispServerURLS[wispServer] : WispServerURLS.default - }); - break; - } - resolve(); - }); + //wrap in a promise so we don't register sw until a transport is set. + const wispServer = localStorage.getItem(Settings.ProxySettings.wispServerURL); + return new Promise((resolve) => { + switch (transport) { + case "epoxy": + BareMux.SetTransport("EpxMod.default", { + wisp: wispServer ? WispServerURLS[wispServer] : WispServerURLS.default + }); + break; + case "libcurl": + BareMux.SetTransport("CurlMod.default", { + wisp: wispServer ? WispServerURLS[wispServer] : WispServerURLS.default + }); + break; + } + resolve(); + }); } function initSw() { - //this is wrapped in a promise to mostly solve the bare-mux v1 problems - return new Promise((resolve) => { - if ("serviceWorker" in navigator) { - navigator.serviceWorker.ready.then(async () => { - console.debug("Service worker ready!"); - await loadProxyScripts(); - resolve(); - }); - navigator.serviceWorker.register("/sw.js", { scope: "/" }); - } - }); + //this is wrapped in a promise to mostly solve the bare-mux v1 problems + return new Promise((resolve) => { + if ("serviceWorker" in navigator) { + navigator.serviceWorker.ready.then(async () => { + console.debug("Service worker ready!"); + await loadProxyScripts(); + resolve(); + }); + navigator.serviceWorker.register("/sw.js", { scope: "/" }); + } + }); } export { initSw, setTransport }; diff --git a/src/utils/search.ts b/src/utils/search.ts index 40881c8..cb81095 100644 --- a/src/utils/search.ts +++ b/src/utils/search.ts @@ -1,27 +1,27 @@ function search(input: string, template: string) { - try { - // input is a valid URL: - // eg: https://example.com, https://example.com/test?q=param - return new URL(input).toString(); - } catch (err) { - // input was not a valid URL - } + try { + // input is a valid URL: + // eg: https://example.com, https://example.com/test?q=param + return new URL(input).toString(); + } catch (err) { + // input was not a valid URL + } - try { - // input is a valid URL when http:// is added to the start: - // eg: example.com, https://example.com/test?q=param - const url = new URL(`http://${input}`); - // only if the hostname has a TLD/subdomain - if (url.hostname.includes(".")) return url.toString(); - } catch (err) { - // input was not valid URL - } + try { + // input is a valid URL when http:// is added to the start: + // eg: example.com, https://example.com/test?q=param + const url = new URL(`http://${input}`); + // only if the hostname has a TLD/subdomain + if (url.hostname.includes(".")) return url.toString(); + } catch (err) { + // input was not valid URL + } - // input may have been a valid URL, however the hostname was invalid + // input may have been a valid URL, however the hostname was invalid - // Attempts to convert the input to a fully qualified URL have failed - // Treat the input as a search query - return template.replace("%s", encodeURIComponent(input)); + // Attempts to convert the input to a fully qualified URL have failed + // Treat the input as a search query + return template.replace("%s", encodeURIComponent(input)); } export { search }; diff --git a/src/utils/settings/index.ts b/src/utils/settings/index.ts index 1a604d4..ea16d34 100644 --- a/src/utils/settings/index.ts +++ b/src/utils/settings/index.ts @@ -3,45 +3,45 @@ import { AppearanceSettings, marketPlaceSettings } from "./marketplace"; import { ProxySettings, proxySettings } from "./proxy"; import { TabSettings, cloak, tabSettings } from "./tab"; import { - type AbCloaks, - type OpenIn, - type Package, - type PackageType, - type Proxy, - type SearchEngine, - SearchEngines, - type TabCloaks, - type Transport, - WispServerURLS, - wispUrl + type AbCloaks, + type OpenIn, + type Package, + type PackageType, + type Proxy, + type SearchEngine, + SearchEngines, + type TabCloaks, + type Transport, + WispServerURLS, + wispUrl } from "./types"; const Settings = { - AppearanceSettings, - TabSettings, - ProxySettings + AppearanceSettings, + TabSettings, + ProxySettings }; const settings = { - marketPlaceSettings, - tabSettings, - proxySettings + marketPlaceSettings, + tabSettings, + proxySettings }; //export all of the stuffs export { - Settings, - settings, - SearchEngines, - WispServerURLS, - wispUrl, - cloak, - type TabCloaks, - type AbCloaks, - type OpenIn, - type Proxy, - type Transport, - type PackageType, - type Package, - type SearchEngine + Settings, + settings, + SearchEngines, + WispServerURLS, + wispUrl, + cloak, + type TabCloaks, + type AbCloaks, + type OpenIn, + type Proxy, + type Transport, + type PackageType, + type Package, + type SearchEngine }; diff --git a/src/utils/settings/marketplace.ts b/src/utils/settings/marketplace.ts index 1899850..549849b 100644 --- a/src/utils/settings/marketplace.ts +++ b/src/utils/settings/marketplace.ts @@ -1,102 +1,102 @@ //marketplace code & handlers import { type Package, type PackageType } from "./types"; const AppearanceSettings = { - themes: "nebula||themes", - stylePayload: "nebula||stylepayload", - video: "nebula||video", - image: "nebula||image" + themes: "nebula||themes", + stylePayload: "nebula||stylepayload", + video: "nebula||video", + image: "nebula||image" }; const marketPlaceSettings = { - install: function (p: Package, packageName: string, payload?: any) { - return new Promise((resolve) => { - if (p.theme) { - let themes = localStorage.getItem(AppearanceSettings.themes) as any; - themes ? (themes = JSON.parse(themes)) : (themes = []); - if (!themes.find((theme: any) => theme === packageName)) { - themes.push(packageName); - localStorage.setItem(AppearanceSettings.themes, JSON.stringify(themes)); - this.changeTheme(false, payload, p.theme.video, p.theme.bgImage); + install: function (p: Package, packageName: string, payload?: any) { + return new Promise((resolve) => { + if (p.theme) { + let themes = localStorage.getItem(AppearanceSettings.themes) as any; + themes ? (themes = JSON.parse(themes)) : (themes = []); + if (!themes.find((theme: any) => theme === packageName)) { + themes.push(packageName); + localStorage.setItem(AppearanceSettings.themes, JSON.stringify(themes)); + this.changeTheme(false, payload, p.theme.video, p.theme.bgImage); + } + resolve(); + } + }); + }, + uninstall: function (p: PackageType, packageName: string) { + return new Promise((resolve) => { + if (p === "theme") { + let items = localStorage.getItem(AppearanceSettings.themes) as any; + items ? (items = JSON.parse(items)) : (items = []); + if (items.find((theme: any) => theme === packageName)) { + const idx = items.indexOf(packageName); + items.splice(idx, 1); + localStorage.setItem(AppearanceSettings.themes, JSON.stringify(items)); + this.changeTheme(true); + } + resolve(); + } + }); + }, + changeTheme: async function ( + reset: Boolean, + payload?: any, + videoSource?: string, + bgSource?: string + ) { + async function resetCSS() { + const stylesheet = document.getElementById("stylesheet")! as HTMLLinkElement; + localStorage.removeItem(AppearanceSettings.stylePayload); + stylesheet.href = "/nebula.css"; } - resolve(); - } - }); - }, - uninstall: function (p: PackageType, packageName: string) { - return new Promise((resolve) => { - if (p === "theme") { - let items = localStorage.getItem(AppearanceSettings.themes) as any; - items ? (items = JSON.parse(items)) : (items = []); - if (items.find((theme: any) => theme === packageName)) { - const idx = items.indexOf(packageName); - items.splice(idx, 1); - localStorage.setItem(AppearanceSettings.themes, JSON.stringify(items)); - this.changeTheme(true); + function resetVideo() { + localStorage.removeItem(AppearanceSettings.video); + const source = document.getElementById("nebulaVideo")! as HTMLVideoElement; + source.src = ""; + } + function resetBGImage() { + localStorage.removeItem(AppearanceSettings.image); + const image = document.getElementById("nebulaImage")! as HTMLImageElement; + image.style.display = "none"; + image.src = ""; + } + if (reset === true) { + await resetCSS(); + await resetCSS(); + resetBGImage(); + resetVideo(); + } + if (videoSource || localStorage.getItem(AppearanceSettings.video)) { + resetBGImage(); + resetVideo(); + const source = document.getElementById("nebulaVideo")! as HTMLVideoElement; + if (!localStorage.getItem(AppearanceSettings.video)) { + localStorage.setItem(AppearanceSettings.video, videoSource as string); + } + source.src = `/videos/${videoSource ? videoSource : localStorage.getItem(AppearanceSettings.video)}`; + } + if (bgSource || localStorage.getItem(AppearanceSettings.image)) { + resetVideo(); + resetBGImage(); + const image = document.getElementById("nebulaImage")! as HTMLImageElement; + if (!localStorage.getItem(AppearanceSettings.image)) { + localStorage.setItem(AppearanceSettings.image, bgSource as string); + } + image.style.display = "block"; + image.src = `/images/${bgSource ? bgSource : localStorage.getItem(AppearanceSettings.image)}`; + } + if (payload) { + const stylesheet = document.getElementById("stylesheet")! as HTMLLinkElement; + if (localStorage.getItem(AppearanceSettings.stylePayload) !== payload) { + localStorage.setItem(AppearanceSettings.stylePayload, payload); + } + stylesheet.href = `/styles/${localStorage.getItem(AppearanceSettings.stylePayload)}`; + } else { + if (localStorage.getItem(AppearanceSettings.stylePayload)) { + const stylesheet = document.getElementById("stylesheet")! as HTMLLinkElement; + stylesheet.href = `/styles/${localStorage.getItem(AppearanceSettings.stylePayload)}`; + } } - resolve(); - } - }); - }, - changeTheme: async function ( - reset: Boolean, - payload?: any, - videoSource?: string, - bgSource?: string - ) { - async function resetCSS() { - const stylesheet = document.getElementById("stylesheet")! as HTMLLinkElement; - localStorage.removeItem(AppearanceSettings.stylePayload); - stylesheet.href = "/nebula.css"; } - function resetVideo() { - localStorage.removeItem(AppearanceSettings.video); - const source = document.getElementById("nebulaVideo")! as HTMLVideoElement; - source.src = ""; - } - function resetBGImage() { - localStorage.removeItem(AppearanceSettings.image); - const image = document.getElementById("nebulaImage")! as HTMLImageElement; - image.style.display = "none"; - image.src = ""; - } - if (reset === true) { - await resetCSS(); - await resetCSS(); - resetBGImage(); - resetVideo(); - } - if (videoSource || localStorage.getItem(AppearanceSettings.video)) { - resetBGImage(); - resetVideo(); - const source = document.getElementById("nebulaVideo")! as HTMLVideoElement; - if (!localStorage.getItem(AppearanceSettings.video)) { - localStorage.setItem(AppearanceSettings.video, videoSource as string); - } - source.src = `/videos/${videoSource ? videoSource : localStorage.getItem(AppearanceSettings.video)}`; - } - if (bgSource || localStorage.getItem(AppearanceSettings.image)) { - resetVideo(); - resetBGImage(); - const image = document.getElementById("nebulaImage")! as HTMLImageElement; - if (!localStorage.getItem(AppearanceSettings.image)) { - localStorage.setItem(AppearanceSettings.image, bgSource as string); - } - image.style.display = "block"; - image.src = `/images/${bgSource ? bgSource : localStorage.getItem(AppearanceSettings.image)}`; - } - if (payload) { - const stylesheet = document.getElementById("stylesheet")! as HTMLLinkElement; - if (localStorage.getItem(AppearanceSettings.stylePayload) !== payload) { - localStorage.setItem(AppearanceSettings.stylePayload, payload); - } - stylesheet.href = `/styles/${localStorage.getItem(AppearanceSettings.stylePayload)}`; - } else { - if (localStorage.getItem(AppearanceSettings.stylePayload)) { - const stylesheet = document.getElementById("stylesheet")! as HTMLLinkElement; - stylesheet.href = `/styles/${localStorage.getItem(AppearanceSettings.stylePayload)}`; - } - } - } }; export { AppearanceSettings, marketPlaceSettings }; diff --git a/src/utils/settings/proxy.ts b/src/utils/settings/proxy.ts index 8ff07a9..d5df943 100644 --- a/src/utils/settings/proxy.ts +++ b/src/utils/settings/proxy.ts @@ -1,29 +1,29 @@ //Proxy specific settings. import { type OpenIn, type Proxy, type SearchEngine, type Transport } from "./types"; const ProxySettings = { - proxy: "nebula||proxy", - openIn: "nebula||open", - searchEngine: "nebula||searchEngine", - wispServerURL: "nebula||wisp", - transport: "nebula||transport" + proxy: "nebula||proxy", + openIn: "nebula||open", + searchEngine: "nebula||searchEngine", + wispServerURL: "nebula||wisp", + transport: "nebula||transport" }; const proxySettings = { - changeProxy: function (proxy: Proxy | string) { - localStorage.setItem(ProxySettings.proxy, proxy); - }, - openIn: function (type: OpenIn | string) { - localStorage.setItem(ProxySettings.openIn, type); - }, - setSearchEngine: function (searchEngine: SearchEngine | string) { - localStorage.setItem(ProxySettings.searchEngine, searchEngine); - }, - setWispURL: function (server: string) { - localStorage.setItem(ProxySettings.wispServerURL, server); - }, - setTransport: function (transport: Transport | string) { - localStorage.setItem(ProxySettings.transport, transport); - } + changeProxy: function (proxy: Proxy | string) { + localStorage.setItem(ProxySettings.proxy, proxy); + }, + openIn: function (type: OpenIn | string) { + localStorage.setItem(ProxySettings.openIn, type); + }, + setSearchEngine: function (searchEngine: SearchEngine | string) { + localStorage.setItem(ProxySettings.searchEngine, searchEngine); + }, + setWispURL: function (server: string) { + localStorage.setItem(ProxySettings.wispServerURL, server); + }, + setTransport: function (transport: Transport | string) { + localStorage.setItem(ProxySettings.transport, transport); + } }; export { ProxySettings, proxySettings }; diff --git a/src/utils/settings/tab.ts b/src/utils/settings/tab.ts index 2bdab75..fd3abce 100644 --- a/src/utils/settings/tab.ts +++ b/src/utils/settings/tab.ts @@ -1,27 +1,27 @@ //Tab specific settings. import { type AbCloaks, type TabCloaks } from "./types"; const TabSettings = { - tabCloak: "nebula||tabCloak", - abblob: "nebula||abBlob" + tabCloak: "nebula||tabCloak", + abblob: "nebula||abBlob" }; function cloak(cloak: AbCloaks | string, redirect: string, url: string) { - switch (cloak) { - case "a:b": - window.location.replace(redirect); - const win = window.open(); - win!.document.body.style.margin = "0"; - win!.document.body.style.height = "100vh"; - const iframe = win!.document.createElement("iframe"); - iframe.style.border = "none"; - iframe.style.width = "100%"; - iframe.style.height = "100%"; - iframe.style.margin = "0"; - iframe.src = url; - win!.document.body.appendChild(iframe); - break; - case "blob": - const htmlContent = ` + switch (cloak) { + case "a:b": + window.location.replace(redirect); + const win = window.open(); + win!.document.body.style.margin = "0"; + win!.document.body.style.height = "100vh"; + const iframe = win!.document.createElement("iframe"); + iframe.style.border = "none"; + iframe.style.width = "100%"; + iframe.style.height = "100%"; + iframe.style.margin = "0"; + iframe.src = url; + win!.document.body.appendChild(iframe); + break; + case "blob": + const htmlContent = ` @@ -34,50 +34,50 @@ function cloak(cloak: AbCloaks | string, redirect: string, url: string) { `; - window.location.replace("https://google.com"); - const blob = new Blob([htmlContent], { type: "text/html" }); - const blobURL = URL.createObjectURL(blob); - window.open(blobURL, "_blank"); - break; - } + window.location.replace("https://google.com"); + const blob = new Blob([htmlContent], { type: "text/html" }); + const blobURL = URL.createObjectURL(blob); + window.open(blobURL, "_blank"); + break; + } } const tabSettings = { - cloakTab: function (cloak: TabCloaks | string) { - const faviconElement = document.getElementById("favicon") as HTMLLinkElement; - localStorage.setItem(TabSettings.tabCloak, cloak); - switch (cloak) { - case "google": - document.title = "Google"; - faviconElement.href = "/cloaks/google.png"; - break; - case "wikipedia": - document.title = "Wikipedia"; - faviconElement.href = "/cloaks/wikipedia.ico"; - break; - case "canvas": - document.title = "Dashboard"; - faviconElement.href = "/cloaks/canvas.ico"; - break; - case "classroom": - document.title = "Home"; - faviconElement.href = "/cloaks/classroom.png"; - break; - case "powerschool": - document.title = "PowerSchool"; - faviconElement.href = "/cloaks/ps.ico"; - break; - case "reset": - //force a reset of favicon & title - localStorage.setItem("nebula||tabCloak", "default"); - window.location.reload(); - default: - return; + cloakTab: function (cloak: TabCloaks | string) { + const faviconElement = document.getElementById("favicon") as HTMLLinkElement; + localStorage.setItem(TabSettings.tabCloak, cloak); + switch (cloak) { + case "google": + document.title = "Google"; + faviconElement.href = "/cloaks/google.png"; + break; + case "wikipedia": + document.title = "Wikipedia"; + faviconElement.href = "/cloaks/wikipedia.ico"; + break; + case "canvas": + document.title = "Dashboard"; + faviconElement.href = "/cloaks/canvas.ico"; + break; + case "classroom": + document.title = "Home"; + faviconElement.href = "/cloaks/classroom.png"; + break; + case "powerschool": + document.title = "PowerSchool"; + faviconElement.href = "/cloaks/ps.ico"; + break; + case "reset": + //force a reset of favicon & title + localStorage.setItem("nebula||tabCloak", "default"); + window.location.reload(); + default: + return; + } + }, + abCloak: function (type: AbCloaks | string) { + localStorage.setItem(TabSettings.abblob, type); + cloak(type as AbCloaks, "https://google.com", window.location.href); } - }, - abCloak: function (type: AbCloaks | string) { - localStorage.setItem(TabSettings.abblob, type); - cloak(type as AbCloaks, "https://google.com", window.location.href); - } }; export { tabSettings, TabSettings, cloak }; diff --git a/src/utils/settings/types.ts b/src/utils/settings/types.ts index 152189a..fe84dbb 100644 --- a/src/utils/settings/types.ts +++ b/src/utils/settings/types.ts @@ -6,34 +6,34 @@ type Proxy = "automatic" | "uv" | "rh"; type Transport = "epoxy" | "libcurl"; type PackageType = "theme" | "plugin"; interface Package { - theme?: { - payload: string; - video?: string; - bgImage?: string; - }; - plugin?: {}; + theme?: { + payload: string; + video?: string; + bgImage?: string; + }; + plugin?: {}; } const SearchEngines: Record = { - ddg: "https://duckduckgo.com/?q=%s", - google: "https://google.com/search?q=%s", - bing: "https://bing.com/search?q=%s" + ddg: "https://duckduckgo.com/?q=%s", + google: "https://google.com/search?q=%s", + bing: "https://bing.com/search?q=%s" }; type SearchEngine = "ddg" | "google" | "bing"; const WispServerURLS: Record = { - default: wispUrl, - ruby: "wss://ruby.rubynetwork.co/wisp/" + default: wispUrl, + ruby: "wss://ruby.rubynetwork.co/wisp/" }; export { - type TabCloaks, - type AbCloaks, - type OpenIn, - type Proxy, - type Transport, - type PackageType, - type Package, - SearchEngines, - type SearchEngine, - WispServerURLS, - wispUrl + type TabCloaks, + type AbCloaks, + type OpenIn, + type Proxy, + type Transport, + type PackageType, + type Package, + SearchEngines, + type SearchEngine, + WispServerURLS, + wispUrl }; diff --git a/src/utils/siteSupport.ts b/src/utils/siteSupport.ts index e1de798..dec922d 100644 --- a/src/utils/siteSupport.ts +++ b/src/utils/siteSupport.ts @@ -2,12 +2,12 @@ import type { Proxy } from "./settings"; type ProxyChoices = Exclude; const SupportedSites: Record = { - "discord.gg": "uv", - "discord.com": "uv", - "spotify.com": "rh", - "spotify.link": "rh", - "youtube.com": "uv", - "youtu.be": "uv" + "discord.gg": "uv", + "discord.com": "uv", + "spotify.com": "rh", + "spotify.link": "rh", + "youtube.com": "uv", + "youtu.be": "uv" }; export { SupportedSites }; diff --git a/src/utils/toast.ts b/src/utils/toast.ts index dcb6891..8193332 100644 --- a/src/utils/toast.ts +++ b/src/utils/toast.ts @@ -1,28 +1,28 @@ type ToastType = "success" | "error" | "multiline"; type Position = - | "top-left" - | "top-middle" - | "top-right" - | "bottom-left" - | "bottom-right" - | "bottom-center"; + | "top-left" + | "top-middle" + | "top-right" + | "bottom-left" + | "bottom-right" + | "bottom-center"; interface Props { - toastType: ToastType; - text: string; - class: string; - id?: string; - duration?: number; - emoji?: any; - position?: Position; + toastType: ToastType; + text: string; + class: string; + id?: string; + duration?: number; + emoji?: any; + position?: Position; } function toast(query: string) { - const wrapper = document.getElementById("toastwrapper") as HTMLDivElement; - wrapper.classList.remove("hidden"); - //this is a really hacky solution for toast notifications LOL - const element = document.querySelector(query) as HTMLElement; - //click the element - element.click(); + const wrapper = document.getElementById("toastwrapper") as HTMLDivElement; + wrapper.classList.remove("hidden"); + //this is a really hacky solution for toast notifications LOL + const element = document.querySelector(query) as HTMLElement; + //click the element + element.click(); } export { type ToastType, type Position, type Props, toast }; diff --git a/svelte.config.js b/svelte.config.js index a388127..3b3578e 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,5 +1,5 @@ import { vitePreprocess } from "@astrojs/svelte"; export default { - preprocess: vitePreprocess() + preprocess: vitePreprocess() }; diff --git a/tailwind.config.mjs b/tailwind.config.mjs index 8028336..79c0edf 100644 --- a/tailwind.config.mjs +++ b/tailwind.config.mjs @@ -1,21 +1,21 @@ /** @type {import('tailwindcss').Config} */ export default { - content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"], - theme: { - colors: { - primary: "var(--background-primary)", - lighter: "var(--background-lighter)", - "navbar-text-color": "var(--navbar-text-color)", - "navbar-color": "var(--navbar-color)", - "text-color": "var(--navbar-link-color)", - "text-hover-color": "var(--navbar-link-hover-color)", - input: "var(--input-background-color)", - "input-text": "var(--input-text-color)", - "input-border-color": "var(--input-border-color)", - "dropdown-option-hover-color": "var(--dropdown-option-hover-color)", - "border-color": "var(--border-color)" + content: ["./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}"], + theme: { + colors: { + primary: "var(--background-primary)", + lighter: "var(--background-lighter)", + "navbar-text-color": "var(--navbar-text-color)", + "navbar-color": "var(--navbar-color)", + "text-color": "var(--navbar-link-color)", + "text-hover-color": "var(--navbar-link-hover-color)", + input: "var(--input-background-color)", + "input-text": "var(--input-text-color)", + "input-border-color": "var(--input-border-color)", + "dropdown-option-hover-color": "var(--dropdown-option-hover-color)", + "border-color": "var(--border-color)" + }, + extend: {} }, - extend: {} - }, - plugins: [] + plugins: [] }; diff --git a/test_upload.js b/test_upload.js index 7bc0838..5b0b659 100644 --- a/test_upload.js +++ b/test_upload.js @@ -12,9 +12,9 @@ form.set("file", await fileFromPath("asgard.png")); console.log(config.marketplace_psk); console.log(form); await fetch("http://localhost:8080/api/upload-image", { - headers: { - PSK: config.marketplace_psk - }, - method: "post", - body: form + headers: { + PSK: config.marketplace_psk + }, + method: "post", + body: form }); diff --git a/tsconfig.json b/tsconfig.json index bb7289b..39294d7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,12 @@ { - "extends": "astro/tsconfigs/strict", - "include": ["src"], - "compilerOptions": { - "baseUrl": ".", - "paths": { - "@components/*": ["src/components/*"], - "@layouts/*": ["src/layouts/*"], - "@utils/*": ["src/utils/*"] + "extends": "astro/tsconfigs/strict", + "include": ["src"], + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@components/*": ["src/components/*"], + "@layouts/*": ["src/layouts/*"], + "@utils/*": ["src/utils/*"] + } } - } }