From d766e2ae6a63fca60f22f9658321ac55ddae2d3c Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Tue, 18 Mar 2025 17:28:21 +0800 Subject: [PATCH] add bun backend and add upload bitstream component --- bun.lock | 7 ++++ package.json | 5 ++- server/DataBase.ts | 0 server/index.ts | 39 +++++++++++++++++++ src/components/Sidebar.vue | 32 +++++++++++---- src/components/UploadCard.vue | 52 +++++++++++++++++++++++++ src/main.ts | 2 + src/router/index.ts | 4 +- src/views/{TestSVG.vue => TestView.vue} | 0 src/views/UserView.vue | 10 ++++- tsconfig.app.json | 15 +++++-- tsconfig.bun.json | 26 +++++++++++++ tsconfig.json | 3 ++ 13 files changed, 178 insertions(+), 17 deletions(-) create mode 100644 server/DataBase.ts create mode 100644 server/index.ts create mode 100644 src/components/UploadCard.vue rename src/views/{TestSVG.vue => TestView.vue} (100%) create mode 100644 tsconfig.bun.json diff --git a/bun.lock b/bun.lock index bc0928e..8a25b94 100644 --- a/bun.lock +++ b/bun.lock @@ -13,6 +13,7 @@ "devDependencies": { "@tailwindcss/postcss": "^4.0.12", "@tsconfig/node22": "^22.0.0", + "@types/bun": "^1.2.5", "@types/node": "^22.13.4", "@vitejs/plugin-vue": "^5.2.1", "@vitejs/plugin-vue-jsx": "^4.1.1", @@ -231,10 +232,14 @@ "@tsconfig/node22": ["@tsconfig/node22@22.0.0", "", {}, "sha512-twLQ77zevtxobBOD4ToAtVmuYrpeYUh3qh+TEp+08IWhpsrIflVHqQ1F1CiPxQGL7doCdBIOOCF+1Tm833faNg=="], + "@types/bun": ["@types/bun@1.2.5", "", { "dependencies": { "bun-types": "1.2.5" } }, "sha512-w2OZTzrZTVtbnJew1pdFmgV99H0/L+Pvw+z1P67HaR18MHOzYnTYOi6qzErhK8HyT+DB782ADVPPE92Xu2/Opg=="], + "@types/estree": ["@types/estree@1.0.6", "", {}, "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw=="], "@types/node": ["@types/node@22.13.9", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-acBjXdRJ3A6Pb3tqnw9HZmyR3Fiol3aGxRCK1x3d+6CDAMjl7I649wpSd+yNURCjbOUGu9tqtLKnTGxmK6CyGw=="], + "@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="], + "@vitejs/plugin-vue": ["@vitejs/plugin-vue@5.2.1", "", { "peerDependencies": { "vite": "^5.0.0 || ^6.0.0", "vue": "^3.2.25" } }, "sha512-cxh314tzaWwOLqVes2gnnCtvBDcM1UMdn+iFR+UjAn411dPT3tOmqrJjbMd7koZpMAmBM/GqeV4n9ge7JSiJJQ=="], "@vitejs/plugin-vue-jsx": ["@vitejs/plugin-vue-jsx@4.1.1", "", { "dependencies": { "@babel/core": "^7.26.0", "@babel/plugin-transform-typescript": "^7.25.9", "@vue/babel-plugin-jsx": "^1.2.5" }, "peerDependencies": { "vite": "^5.0.0 || ^6.0.0", "vue": "^3.0.0" } }, "sha512-uMJqv/7u1zz/9NbWAD3XdjaY20tKTf17XVfQ9zq4wY1BjsB/PjpJPMe2xiG39QpP4ZdhYNhm4Hvo66uJrykNLA=="], @@ -299,6 +304,8 @@ "bun-plugin-tailwind": ["bun-plugin-tailwind@0.0.15", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-qtAXMNGG4R0UGGI8zWrqm2B7BdXqx48vunJXBPzfDOHPA5WkRUZdTSbE7TFwO4jLhYqSE23YMWsM9NhE6ovobw=="], + "bun-types": ["bun-types@1.2.5", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-3oO6LVGGRRKI4kHINx5PIdIgnLRb7l/SprhzqXapmoYkFl5m4j6EvALvbDVuuBFaamB46Ap6HCUxIXNLCGy+tg=="], + "bundle-name": ["bundle-name@4.1.0", "", { "dependencies": { "run-applescript": "^7.0.0" } }, "sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q=="], "caniuse-lite": ["caniuse-lite@1.0.30001702", "", {}, "sha512-LoPe/D7zioC0REI5W73PeR1e1MLCipRGq/VkovJnd6Df+QVqT+vT33OXCp8QUd7kA7RZrHWxb1B36OQKI/0gOA=="], diff --git a/package.json b/package.json index ffb79ab..9833126 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,14 @@ "version": "0.0.0", "private": true, "type": "module", + "main": "./server/index.ts", "scripts": { "dev": "bunx --bun vite", "build": "run-p type-check \"build-only {@}\" --", "preview": "bunx --bun vite preview", "build-only": "bunx --bun vite build", - "type-check": "bunx --bun vue-tsc --build" + "type-check": "bunx --bun vue-tsc --build", + "server": "bun run ./server/index.ts" }, "dependencies": { "log-symbols": "^7.0.0", @@ -20,6 +22,7 @@ "devDependencies": { "@tailwindcss/postcss": "^4.0.12", "@tsconfig/node22": "^22.0.0", + "@types/bun": "^1.2.5", "@types/node": "^22.13.4", "@vitejs/plugin-vue": "^5.2.1", "@vitejs/plugin-vue-jsx": "^4.1.1", diff --git a/server/DataBase.ts b/server/DataBase.ts new file mode 100644 index 0000000..e69de29 diff --git a/server/index.ts b/server/index.ts new file mode 100644 index 0000000..c7768d7 --- /dev/null +++ b/server/index.ts @@ -0,0 +1,39 @@ +import { serve } from "bun"; + +serve({ + port: 3001, + // hostname: "fpga.swordlost.com", + routes: { + // Static routes + "/api/status": new Response("OK"), + + // Dynamic routes + "/users/:id": req => { + return new Response(`Hello User ${req.params.id}!`); + }, + + // Per-HTTP method handlers + "/api/posts": { + GET: () => new Response("List posts"), + POST: async req => { + const body = await req.json(); + + if (body !== null) { + return Response.json({ created: true, ...body }); + } else { + return Response.json({}) + } + }, + }, + + // Wildcard route for all routes that start with "/api/" and aren't otherwise matched + "/api/*": Response.json({ message: "Not found" }, { status: 404 }), + + // Serve a file by buffering it in memory + // "/favicon.ico": new Response(await Bun.file("../public/favicon.icon").bytes(), { + // headers: { + // "Content-Type": "image/x-icon", + // }, + // }), + } +}); diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index cdc8e87..38d0561 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -1,8 +1,15 @@