Skip to content

Commit

Permalink
feat: 增加下载
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwei committed Jun 25, 2024
1 parent 7f3c73b commit 2e3ff42
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ dist-ssr
*.sln
*.sw?
stats.html
/public/uploads/
/src/server/static/
11 changes: 11 additions & 0 deletions src/client/views/fileUpload/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="file-upload">
<input ref="uploadRef" type="file" :multiple="multiple" :accept="accept" />
<button @click="handleUpload">上传</button>
<button @click="handleDownload">下载</button>
</div>
</template>

Expand Down Expand Up @@ -34,4 +35,14 @@ const handleUpload = async () => {
const res = await fileUploadApi(formData);
console.log(res);
};
const handleDownload = () => {
const url = "/src/server/3Nu7ZJcKdMb_z9AYfNyAhmQc.crt";
const a = document.createElement("a");
a.href = url;
a.download = "3Nu7ZJcKdMb_z9AYfNyAhmQc.crt";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
</script>
5 changes: 2 additions & 3 deletions src/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ app.use(express.json());

// 添加/api前缀
app.use("/api", router);

// 部署
router.use("/deploy", deploy);

// 壁纸
router.use("/wallpaper", wallpaper);

// 上传
router.use("/upload", upload);

const server = app.listen(3001, "0.0.0.0", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/server/upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const multipartyUpload = (req) => {
const form = new multiparty.Form({
maxFilesSize: 1024 * 1024 * 1024,
});
form.uploadDir = "./public/uploads";
form.uploadDir = "./src/server/static";
form.parse(req, (err, fields, files) => {
if (err) {
reject(err);
Expand Down

0 comments on commit 2e3ff42

Please sign in to comment.