refactor: ♻️ Use Vite instead of Rollup

Soon: Hono instead of Express
This commit is contained in:
Jack W. 2023-10-24 17:18:36 -04:00
parent b71963a491
commit 6220cd8b0f
No known key found for this signature in database
16 changed files with 1580 additions and 138 deletions

3
.gitignore vendored
View file

@ -1,4 +1,5 @@
node_modules node_modules
.env .env
.data .data
out out
dist

6
.prettierrc Normal file
View file

@ -0,0 +1,6 @@
{
"useTabs": false,
"semi": false,
"trailingComma": "es5",
"tabWidth": 4
}

View file

@ -1,20 +1,14 @@
{ {
"maxDiscordFiles": 20, "maxDiscordFiles": 50,
"maxDiscordFileSize": 26214400, "maxDiscordFileSize": 10485760,
"targetGuild": "1024080490677936248", "targetGuild": "906767804575928390",
"targetChannel": "1024080525993971913", "targetChannel": "1160783463696302182",
"requestTimeout":120000, "requestTimeout": 120000,
"maxUploadIdLength":30, "maxUploadIdLength": 30,
"accounts": { "accounts": {
"registrationEnabled": true, "registrationEnabled": true,
"requiredForUpload": false "requiredForUpload": false
}, },
"webdrop": {
"accountRequired": false
},
"mail": { "mail": {
"transport": { "transport": {
"host": "smtp.fastmail.com", "host": "smtp.fastmail.com",
@ -25,7 +19,6 @@
"from": "mono@fyle.uk" "from": "mono@fyle.uk"
} }
}, },
"trustProxy": true, "trustProxy": true,
"forceSSL": false "forceSSL": false
} }

View file

@ -1,41 +1,45 @@
{ {
"name": "monofile", "name": "monofile",
"version": "1.4.0-dev", "version": "1.4.0-dev",
"description": "Discord-based file sharing", "description": "Discord-based file sharing",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "node ./out/server/index.js", "start": "node ./out/server/index.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1",
}, "dev": "vite",
"keywords": [], "build": "tsc && vite build",
"author": "nbitzz", "preview": "vite preview"
"license": "Unlicense", },
"engines": { "keywords": [],
"node": ">=v16.11" "author": "nbitzz",
}, "license": "Unlicense",
"dependencies": { "engines": {
"@types/body-parser": "^1.19.2", "node": ">=v16.11"
"@types/express": "^4.17.14", },
"@types/multer": "^1.4.7", "dependencies": {
"@types/nodemailer": "^6.4.8", "@types/body-parser": "^1.19.2",
"axios": "^0.27.2", "@types/express": "^4.17.14",
"body-parser": "^1.20.0", "@types/multer": "^1.4.7",
"bytes": "^3.1.2", "@types/nodemailer": "^6.4.8",
"cookie-parser": "^1.4.6", "axios": "^0.27.2",
"discord.js": "^14.7.1", "body-parser": "^1.20.0",
"dotenv": "^16.0.2", "bytes": "^3.1.2",
"express": "^4.18.1", "cookie-parser": "^1.4.6",
"multer": "^1.4.5-lts.1", "discord.js": "^14.7.1",
"nodemailer": "^6.9.3", "dotenv": "^16.0.2",
"typescript": "^4.8.3" "express": "^4.18.1",
}, "hono": "^3.8.3",
"devDependencies": { "multer": "^1.4.5-lts.1",
"@rollup/plugin-node-resolve": "^15.0.1", "nodemailer": "^6.9.3",
"@types/bytes": "^3.1.1", "typescript": "^5.2.2"
"@types/cookie-parser": "^1.4.3", },
"rollup": "^3.11.0", "devDependencies": {
"rollup-plugin-svelte": "^7.1.0", "@sveltejs/vite-plugin-svelte": "^2.4.6",
"sass": "^1.57.1", "@types/bytes": "^3.1.1",
"svelte": "^3.55.1" "@types/cookie-parser": "^1.4.3",
} "@types/range-parser": "^1.2.6",
} "sass": "^1.57.1",
"svelte": "^3.55.1",
"vite": "^4.5.0"
}
}

View file

@ -1,47 +0,0 @@
<!--
for some reason (don't know why)
certain things break
when not in quirks mode
so i'm not adding in the
doctype html
-->
<html lang="en">
<head>
<link
rel="stylesheet"
href="/static/style/app.css"
>
<link
rel="icon"
type="image/svg"
href="/static/assets/icons/icon_temp.svg"
>
<link
rel="stylesheet"
href="/auth/customCSS"
>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=0"
>
<script type="module" src="/static/js/index.js"></script>
<title>monofile</title>
<meta name="title" content="monofile">
<meta name="description" content="The open-source Discord-based file sharing service">
<meta name="theme-color" content="rgb(30, 33, 36)">
</head>
<body>
</body>
</html>

1451
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,17 +0,0 @@
import svelte from 'rollup-plugin-svelte'
import resolve from "@rollup/plugin-node-resolve"
export default [
{
input: "src/client/index.js",
output: {
file: 'out/client/index.js',
format: 'esm',
sourcemap:true
},
plugins: [
resolve({ browser: true }),
svelte({})
]
}
]

View file

@ -1,5 +0,0 @@
import App from "../svelte/App.svelte"
new App({
target: document.body
})

View file

@ -14,7 +14,7 @@
<link <link
rel="stylesheet" rel="stylesheet"
href="/static/style/downloads.css" href="./style/downloads.scss"
> >
<link <link
@ -51,4 +51,4 @@
</div> </div>
</body> </body>
</html> </html>

View file

@ -6,7 +6,7 @@
<link <link
rel="stylesheet" rel="stylesheet"
href="/static/style/error.css" href="./style/error.scss"
> >
<link <link
@ -38,4 +38,4 @@
</p> </p>
</body> </body>
</html> </html>

38
src/index.html Normal file
View file

@ -0,0 +1,38 @@
<!--
for some reason (don't know why)
certain things break
when not in quirks mode
so i'm not adding in the
doctype html
-->
<html lang="en">
<head>
<link rel="stylesheet" href="./style/app.scss" />
<link
rel="icon"
type="image/svg"
href="/static/assets/icons/icon_temp.svg"
/>
<link rel="stylesheet" href="/auth/customCSS" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=0"
/>
<script type="module" src="./svelte/index.js"></script>
<title>monofile</title>
<meta name="title" content="monofile" />
<meta
name="description"
content="The open-source Discord-based file sharing service"
/>
<meta name="theme-color" content="rgb(30, 33, 36)" />
</head>
<body></body>
</html>

View file

@ -2,11 +2,7 @@ import cookieParser from "cookie-parser"
import { IntentsBitField, Client } from "discord.js" import { IntentsBitField, Client } from "discord.js"
import express from "express" import express from "express"
import fs from "fs" import fs from "fs"
import bytes from "bytes"
import ServeError from "./lib/errors"
import Files from "./lib/files" import Files from "./lib/files"
import * as Accounts from "./lib/accounts"
import { getAccount } from "./lib/middleware" import { getAccount } from "./lib/middleware"
import APIRouter from "./routes/api" import APIRouter from "./routes/api"
@ -19,8 +15,7 @@ let app = express()
let config = require(`${process.cwd()}/config.json`) let config = require(`${process.cwd()}/config.json`)
app.use("/static/assets", express.static("assets")) app.use("/static/assets", express.static("assets"))
app.use("/static/style", express.static("out/style")) app.use("/static/vite", express.static("dist/static/vite"))
app.use("/static/js", express.static("out/client"))
//app.use(bodyParser.text({limit:(config.maxDiscordFileSize*config.maxDiscordFiles)+1048576,type:["application/json","text/plain"]})) //app.use(bodyParser.text({limit:(config.maxDiscordFileSize*config.maxDiscordFiles)+1048576,type:["application/json","text/plain"]}))
@ -74,7 +69,7 @@ apiRouter.loadAPIMethods().then(() => {
// index, clone // index, clone
app.get("/", function (req, res) { app.get("/", function (req, res) {
res.sendFile(process.cwd() + "/pages/index.html") res.sendFile(process.cwd() + "/dist/index.html")
}) })
// serve download page // serve download page

View file

@ -18,7 +18,7 @@ export default async function ServeError(
if (!errorPage) { if (!errorPage) {
errorPage = errorPage =
( (
await readFile(`${process.cwd()}/pages/error.html`) await readFile(`${process.cwd()}/dist/error.html`)
.catch((err) => console.error(err)) .catch((err) => console.error(err))
|| "<pre>$code $text</pre>" || "<pre>$code $text</pre>"
) )

View file

@ -16,7 +16,7 @@ export = (files: Files): Handler =>
} }
const template = await fs const template = await fs
.readFile(process.cwd() + "/pages/download.html", "utf8") .readFile(process.cwd() + "/dist/download.html", "utf8")
.catch(() => { .catch(() => {
throw res.sendStatus(500) throw res.sendStatus(500)
}) })

5
src/svelte/index.js Normal file
View file

@ -0,0 +1,5 @@
import App from "./App.svelte"
new App({
target: document.body
})

18
vite.config.mjs Normal file
View file

@ -0,0 +1,18 @@
import { defineConfig } from "vite"
import { svelte } from "@sveltejs/vite-plugin-svelte"
import { resolve } from "path"
export default defineConfig({
root: "./src",
build: {
outDir: "../dist",
assetsDir: "static/vite",
rollupOptions: {
input: {
main: resolve(__dirname, "src/index.html"),
download: resolve(__dirname, "src/download.html"),
error: resolve(__dirname, "src/error.html"),
},
},
},
plugins: [svelte({})],
})