From 8f1feb8cff614411bb7c3015249500f4d658e6e5 Mon Sep 17 00:00:00 2001 From: MotorTruck1221 Date: Fri, 4 Oct 2024 00:49:10 -0600 Subject: [PATCH] Run a format --- astro.config.mjs | 96 ++++----- biome.json | 54 ++--- config.json | 8 +- package.json | 7 +- public/sw.js | 38 ++-- public/uv/uv.config.js | 54 ++--- server.js | 152 ++++++-------- src/components/Card.astro | 6 +- src/components/Header.astro | 4 +- src/components/MobileNavigation.astro | 2 +- src/components/catalog/CatalogCard.svelte | 14 +- src/components/catalog/InstalledThemes.svelte | 108 +++++----- src/components/settings/SettingsCard.astro | 34 ++-- src/components/toasts/Toast.svelte | 74 +++---- src/components/toasts/ToastWrapper.svelte | 2 +- src/i18n/en_US.json | 4 +- src/i18n/jp.json | 4 +- src/i18n/ui.ts | 2 +- src/i18n/utils.ts | 7 +- src/layouts/Layout.astro | 4 +- src/pages/[lang]/games.astro | 5 +- src/pages/[lang]/index.astro | 7 +- src/pages/[lang]/settings/appearance.astro | 13 +- src/pages/[lang]/settings/pr.astro | 11 +- src/pages/[lang]/settings/tab.astro | 11 +- src/pages/assets/[...package_name].astro | 4 +- src/pages/catalog/[...page].astro | 2 +- src/pages/index.astro | 2 +- src/utils/registerSW.ts | 120 +++++------ src/utils/search.ts | 42 ++-- src/utils/settings.ts | 190 +++++++++--------- src/utils/toast.ts | 42 ++-- svelte.config.js | 6 +- tailwind.config.mjs | 6 +- test_upload.js | 10 +- tsconfig.json | 12 +- 36 files changed, 565 insertions(+), 592 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 13967c5..30cf99e 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,80 +1,80 @@ -import { defineConfig } from "astro/config"; -import tailwind from "@astrojs/tailwind"; -import icon from "astro-icon"; -import svelte from "@astrojs/svelte"; import node from "@astrojs/node"; +import svelte from "@astrojs/svelte"; +import tailwind from "@astrojs/tailwind"; +import { baremuxPath } from "@mercuryworkshop/bare-mux"; +import { epoxyPath } from "@mercuryworkshop/epoxy-transport"; +import { libcurlPath } from "@mercuryworkshop/libcurl-transport"; +import { uvPath } from "@titaniumnetwork-dev/ultraviolet"; +import icon from "astro-icon"; +import { defineConfig } from "astro/config"; import { viteStaticCopy } from "vite-plugin-static-copy"; -import { baremuxPath } from '@mercuryworkshop/bare-mux'; -import { epoxyPath } from '@mercuryworkshop/epoxy-transport'; -import { libcurlPath } from '@mercuryworkshop/libcurl-transport'; -import { uvPath } from '@titaniumnetwork-dev/ultraviolet'; 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 - } - ] - }) + 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/, ""), + rewrite: (path) => path.replace(/^\/api\/catalog-assets/, "") }, "/images": { target: "http://localhost:8080", - changeOrigin: true, + changeOrigin: true }, "/videos": { target: "http://localhost:8080", - changeOrigin: true, + changeOrigin: true }, - "/wisp/" : { - target: "ws://localhost:8080/wisp/", - changeOrigin: true, - ws: true, - rewrite: (path) => path.replace(/^\/wisp\//, '') + "/wisp/": { + target: "ws://localhost:8080/wisp/", + changeOrigin: true, + ws: true, + rewrite: (path) => path.replace(/^\/wisp\//, "") }, "/styles": { target: "http://localhost:8080", - changeOrigin: true, + changeOrigin: true }, "/api/packages": { target: "http://localhost:8080", - changeOrigin: true, + changeOrigin: true }, "/api/catalog-pages": { target: "http://localhost:8080", - changeOrigin: true, - }, - }, - }, + changeOrigin: true + } + } + } }, output: "server", adapter: node({ - mode: "hybrid", - }), + mode: "hybrid" + }) }); diff --git a/biome.json b/biome.json index edf4aaa..0750cf9 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/**"] + "$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 }, "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 - }, - "formatter": { - "indentStyle": "space", - "trailingCommas": "none" - } + "indentStyle": "space", + "trailingCommas": "none" } + } } diff --git a/config.json b/config.json index 7533dce..51f5da4 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "marketplace_enabled": true, - "marketplace_psk": "CHANGE_THIS_THIS_IS_INSECURE", - "marketplace_level": "1" -} \ No newline at end of file + "marketplace_enabled": true, + "marketplace_psk": "CHANGE_THIS_THIS_IS_INSECURE", + "marketplace_level": "1" +} diff --git a/package.json b/package.json index 0b55293..71de9d1 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,14 @@ "version": "0.0.1", "scripts": { "dev": "concurrently \"astro dev\" \"node server.js\"", - "start": "astro dev", + "start": "node server.js", "build": "astro check && astro build", "bstart": "astro build && node server.js", "preview": "astro preview", - "astro": "astro" + "astro": "astro", + "format:code": "biome format . --write", + "format:imports": "biome check . --write", + "format": "concurrently -m 1 \"npm:format:code\" \"npm:format:imports\"" }, "dependencies": { "@astrojs/check": "^0.8.3", diff --git a/public/sw.js b/public/sw.js index c2dac95..0dfee8c 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,21 +1,21 @@ -importScripts('/epoxy/index.js'); -importScripts('/libcurl/index.js'); -importScripts('/uv/uv.bundle.js'); -importScripts('/uv/uv.config.js'); -importScripts(__uv$config.sw || '/uv/uv.sw.js'); +importScripts("/epoxy/index.js"); +importScripts("/libcurl/index.js"); +importScripts("/uv/uv.bundle.js"); +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); - })() - ); - } +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); + })() + ); + } }); diff --git a/public/uv/uv.config.js b/public/uv/uv.config.js index e58c493..76b6594 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 c5a351e..fffc940 100644 --- a/server.js +++ b/server.js @@ -1,12 +1,12 @@ -import express from "express"; +import fs from "fs"; import { createServer } from "node:http"; import path from "path"; -import wisp from "wisp-server-node"; -import { Sequelize, DataTypes } from "sequelize"; import { fileURLToPath } from "url"; -import { handler as ssrHandler } from "./dist/server/entry.mjs"; +import express from "express"; import multer from "multer"; -import fs from "fs"; +import { DataTypes, Sequelize } from "sequelize"; +import wisp from "wisp-server-node"; +import { handler as ssrHandler } from "./dist/server/entry.mjs"; const config = JSON.parse(fs.readFileSync("config.json", "utf8")); const __filename = fileURLToPath(import.meta.url); @@ -18,7 +18,7 @@ const sequelize = new Sequelize("database", "user", "password", { dialect: "sqlite", logging: false, // SQLite only - storage: "database.sqlite", + storage: "database.sqlite" }); // Auth middleware @@ -43,7 +43,7 @@ var image_storage = multer.diskStorage({ }, filename: function (req, file, cb) { cb(null, file.originalname); //Appending extension - }, + } }); var video_storage = multer.diskStorage({ @@ -52,7 +52,7 @@ var video_storage = multer.diskStorage({ }, filename: function (req, file, cb) { cb(null, file.originalname); //Appending extension - }, + } }); var style_storage = multer.diskStorage({ @@ -61,7 +61,7 @@ var style_storage = multer.diskStorage({ }, filename: function (req, file, cb) { cb(null, file.originalname); //Appending extension - }, + } }); var script_storage = multer.diskStorage({ @@ -70,7 +70,7 @@ var script_storage = multer.diskStorage({ }, filename: function (req, file, cb) { cb(null, file.originalname); //Appending extension - }, + } }); var image_upload = multer({ storage: image_storage }); @@ -81,41 +81,41 @@ var script_upload = multer({ storage: script_storage }); const catalog_assets = sequelize.define("catalog_assets", { package_name: { type: DataTypes.TEXT, - unique: true, + unique: true }, title: { - type: DataTypes.TEXT, + type: DataTypes.TEXT }, description: { - type: DataTypes.TEXT, + type: DataTypes.TEXT }, author: { - type: DataTypes.TEXT, + type: DataTypes.TEXT }, image: { - type: DataTypes.TEXT, + type: DataTypes.TEXT }, tags: { type: DataTypes.JSON, - allowNull: true, + allowNull: true }, version: { - type: DataTypes.TEXT, + type: DataTypes.TEXT }, background_image: { type: DataTypes.TEXT, - allowNull: true, + allowNull: true }, background_video: { type: DataTypes.TEXT, - allowNull: true, + allowNull: true }, payload: { - type: DataTypes.TEXT, + type: DataTypes.TEXT }, type: { - type: DataTypes.TEXT, - }, + type: DataTypes.TEXT + } }); app.use(express.json()); @@ -142,7 +142,7 @@ app.get("/api/catalog-assets", async (request, reply) => { const db_assets = await catalog_assets.findAll({ offset: offset, - limit: 20, + limit: 20 }); const assets = db_assets.reduce((acc, asset) => { @@ -156,7 +156,7 @@ app.get("/api/catalog-assets", async (request, reply) => { background_image: asset.background_image, background_video: asset.background_video, payload: asset.payload, - type: asset.type, + type: asset.type }; return acc; }, {}); @@ -173,7 +173,7 @@ app.get("/api/packages/:package", async (request, reply) => { console.log(request.params.package); const package_row = await catalog_assets.findOne({ - where: { package_name: request.params.package }, + where: { package_name: request.params.package } }); if (!package_row) { @@ -190,7 +190,7 @@ app.get("/api/packages/:package", async (request, reply) => { background_image: package_row.get("background_image"), background_video: package_row.get("background_video"), payload: package_row.get("payload"), - type: package_row.get("type"), + type: package_row.get("type") }; reply.send(details); } catch (error) { @@ -200,78 +200,58 @@ app.get("/api/packages/:package", async (request, reply) => { // 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); +app.post("/api/upload-image", auth_psk, image_upload.single("file"), (req, res) => { + console.log("Request file:", req.file); - 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, - }); + 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 + }); +}); // 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" }); - } - - res.json({ - message: "File uploaded successfully", - filename: req.file.originalname, - }); +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" }); } -); + + 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" }); - } - - res.json({ - message: "File uploaded successfully", - filename: req.file.originalname, - }); +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" }); } -); + + 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" }); - } - - res.json({ - message: "File uploaded successfully", - filename: req.file.originalname, - }); +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" }); } -); + + res.json({ + message: "File uploaded successfully", + filename: req.file.originalname + }); +}); // This API is responsible for creating packages in the database. // PSK authentication required. @@ -288,7 +268,7 @@ app.post("/api/create-package", auth_psk, async function (req, res) { payload: req.body.payload, background_video: req.body.background_video_path, background_image: req.body.background_image_path, - type: req.body.type, + type: req.body.type }); res.send({ hello: "world" }); }); @@ -342,5 +322,5 @@ server.on("upgrade", (req, socket, head) => { }); server.listen({ - port: 8080, + port: 8080 }); diff --git a/src/components/Card.astro b/src/components/Card.astro index bd6d597..e972406 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/Header.astro b/src/components/Header.astro index 63c5f7b..986e3c3 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -1,9 +1,9 @@ --- +import { Icon } from "astro-icon/components"; import { getLangFromUrl, useTranslations } from "../i18n/utils"; import { isMobileNavOpen } from "../store.js"; -import Logo from "./Logo.astro"; import HeaderButton from "./HeaderButton.astro"; -import { Icon } from "astro-icon/components"; +import Logo from "./Logo.astro"; const lang = getLangFromUrl(Astro.url); const t = useTranslations(lang); diff --git a/src/components/MobileNavigation.astro b/src/components/MobileNavigation.astro index fb76088..a2f7fde 100644 --- a/src/components/MobileNavigation.astro +++ b/src/components/MobileNavigation.astro @@ -1,7 +1,7 @@ --- +import { Icon } from "astro-icon/components"; import { getLangFromUrl, useTranslations } from "../i18n/utils"; import HeaderButton from "./HeaderButton.astro"; -import { Icon } from "astro-icon/components"; const lang = getLangFromUrl(Astro.url); const t = useTranslations(lang); --- diff --git a/src/components/catalog/CatalogCard.svelte b/src/components/catalog/CatalogCard.svelte index 99a10d9..746c1e6 100644 --- a/src/components/catalog/CatalogCard.svelte +++ b/src/components/catalog/CatalogCard.svelte @@ -1,11 +1,11 @@
diff --git a/src/components/catalog/InstalledThemes.svelte b/src/components/catalog/InstalledThemes.svelte index ac03dea..923d0fa 100644 --- a/src/components/catalog/InstalledThemes.svelte +++ b/src/components/catalog/InstalledThemes.svelte @@ -1,66 +1,66 @@ {#await assetPromise} diff --git a/src/components/settings/SettingsCard.astro b/src/components/settings/SettingsCard.astro index f918c57..daad803 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 c382524..14f400c 100644 --- a/src/components/toasts/Toast.svelte +++ b/src/components/toasts/Toast.svelte @@ -1,41 +1,41 @@ diff --git a/src/components/toasts/ToastWrapper.svelte b/src/components/toasts/ToastWrapper.svelte index 0b1afa5..6721c5f 100644 --- a/src/components/toasts/ToastWrapper.svelte +++ b/src/components/toasts/ToastWrapper.svelte @@ -1,5 +1,5 @@