Download src/index.tsx from linuxrun/convert: direct link, hf CLI and curl.
- Browser
- Download file 2.51 kB
-
https://huggingface.co/spaces/linuxrun/convert/resolve/main/src/index.tsx
- Command line
-
hf download hf://spaces/linuxrun/convert/src/index.tsx
-
curl -L -o index.tsx https://huggingface.co/spaces/linuxrun/convert/resolve/main/src/index.tsx
2.51 kB
| import { rmSync } from "node:fs"; | |
| import { mkdir } from "node:fs/promises"; | |
| import { html } from "@elysiajs/html"; | |
| import { staticPlugin } from "@elysiajs/static"; | |
| import { Elysia } from "elysia"; | |
| import "./helpers/printVersions"; | |
| import db from "./db/db"; | |
| import { Jobs } from "./db/types"; | |
| import { AUTO_DELETE_EVERY_N_HOURS, WEBROOT } from "./helpers/env"; | |
| import { chooseConverter } from "./pages/chooseConverter"; | |
| import { convert } from "./pages/convert"; | |
| import { deleteFile } from "./pages/deleteFile"; | |
| import { download } from "./pages/download"; | |
| import { history } from "./pages/history"; | |
| import { listConverters } from "./pages/listConverters"; | |
| import { results } from "./pages/results"; | |
| import { root } from "./pages/root"; | |
| import { upload } from "./pages/upload"; | |
| import { user } from "./pages/user"; | |
| mkdir("./data", { recursive: true }).catch(console.error); | |
| export const uploadsDir = "./data/uploads/"; | |
| export const outputDir = "./data/output/"; | |
| const app = new Elysia({ | |
| serve: { | |
| maxRequestBodySize: Number.MAX_SAFE_INTEGER, | |
| }, | |
| prefix: WEBROOT, | |
| }) | |
| .use(html()) | |
| .use( | |
| staticPlugin({ | |
| assets: "public", | |
| prefix: "", | |
| }), | |
| ) | |
| .use(user) | |
| .use(root) | |
| .use(upload) | |
| .use(history) | |
| .use(convert) | |
| .use(download) | |
| .use(results) | |
| .use(deleteFile) | |
| .use(listConverters) | |
| .use(chooseConverter) | |
| .onError(({ error }) => { | |
| console.error(error); | |
| }); | |
| if (process.env.NODE_ENV !== "production") { | |
| await import("./helpers/tailwind").then(async ({ generateTailwind }) => { | |
| const result = await generateTailwind(); | |
| app.get("/generated.css", ({ set }) => { | |
| set.headers["content-type"] = "text/css"; | |
| return result; | |
| }); | |
| }); | |
| } | |
| app.listen(3000); | |
| console.log(`🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}${WEBROOT}`); | |
| const clearJobs = () => { | |
| const jobs = db | |
| .query("SELECT * FROM jobs WHERE date_created < ?") | |
| .as(Jobs) | |
| .all(new Date(Date.now() - AUTO_DELETE_EVERY_N_HOURS * 60 * 60 * 1000).toISOString()); | |
| for (const job of jobs) { | |
| // delete the directories | |
| rmSync(`${outputDir}${job.user_id}/${job.id}`, { | |
| recursive: true, | |
| force: true, | |
| }); | |
| rmSync(`${uploadsDir}${job.user_id}/${job.id}`, { | |
| recursive: true, | |
| force: true, | |
| }); | |
| // delete the job | |
| db.query("DELETE FROM jobs WHERE id = ?").run(job.id); | |
| } | |
| setTimeout(clearJobs, AUTO_DELETE_EVERY_N_HOURS * 60 * 60 * 1000); | |
| }; | |
| if (AUTO_DELETE_EVERY_N_HOURS > 0) { | |
| clearJobs(); | |
| } | |