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

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ node_modules
.env
.data
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,
"maxDiscordFileSize": 26214400,
"targetGuild": "1024080490677936248",
"targetChannel": "1024080525993971913",
"maxDiscordFiles": 50,
"maxDiscordFileSize": 10485760,
"targetGuild": "906767804575928390",
"targetChannel": "1160783463696302182",
"requestTimeout": 120000,
"maxUploadIdLength": 30,
"accounts": {
"registrationEnabled": true,
"requiredForUpload": false
},
"webdrop": {
"accountRequired": false
},
"mail": {
"transport": {
"host": "smtp.fastmail.com",
@ -25,7 +19,6 @@
"from": "mono@fyle.uk"
}
},
"trustProxy": true,
"forceSSL": false
}

View file

@ -5,7 +5,10 @@
"main": "index.js",
"scripts": {
"start": "node ./out/server/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"keywords": [],
"author": "nbitzz",
@ -25,17 +28,18 @@
"discord.js": "^14.7.1",
"dotenv": "^16.0.2",
"express": "^4.18.1",
"hono": "^3.8.3",
"multer": "^1.4.5-lts.1",
"nodemailer": "^6.9.3",
"typescript": "^4.8.3"
"typescript": "^5.2.2"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.1",
"@sveltejs/vite-plugin-svelte": "^2.4.6",
"@types/bytes": "^3.1.1",
"@types/cookie-parser": "^1.4.3",
"rollup": "^3.11.0",
"rollup-plugin-svelte": "^7.1.0",
"@types/range-parser": "^1.2.6",
"sass": "^1.57.1",
"svelte": "^3.55.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
rel="stylesheet"
href="/static/style/downloads.css"
href="./style/downloads.scss"
>
<link

View file

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

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

View file

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

View file

@ -16,7 +16,7 @@ export = (files: Files): Handler =>
}
const template = await fs
.readFile(process.cwd() + "/pages/download.html", "utf8")
.readFile(process.cwd() + "/dist/download.html", "utf8")
.catch(() => {
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({})],
})