store uploader for folders too

Massimo Melina committed Jun 30, 2023 at 15:52 UTC c7b19fd7c5270609ce63a1f1578195c80aa8495e
2 files changed +12 -6
plugins/list-uploader/public/main.js
+1 -1
@@ -2,7 +2,7 @@
2 const { display } = HFS.getPluginConfig()
3
4 HFS.onEvent('additionalEntryDetails', ({ entry }) =>
5 - !entry.isFolder && HFS.h(Uploader, entry))
5 + HFS.h(Uploader, entry))
6
7 const cache = {}
8
src/upload.ts
+11 -5
@@ -28,6 +28,14 @@ export function getUploadMeta(path: string) {
28 return loadFileAttr(path, ATTR_UPLOADER)
29 }
30
31 +function setUploadMeta(path: string, ctx: Koa.Context) {
32 + return storeFileAttr(path, ATTR_UPLOADER, {
33 + username: getCurrentUsername(ctx),
34 + ip: ctx.ip,
35 + })
36 +}
37 +
38 +// stay sync because we use this function with formidable()
39 export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
40 if (dirTraversal(path))
41 return fail(HTTP_FOOL)
@@ -50,7 +58,8 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
58 }
59 if (ctx.query.skipExisting && fs.existsSync(fullPath))
60 return fail(HTTP_CONFLICT)
53 - fs.mkdirSync(dir, { recursive: true })
61 + if (fs.mkdirSync(dir, { recursive: true }))
62 + setUploadMeta(dir, ctx)
63 const keepName = basename(fullPath).slice(-200)
64 let tempName = join(dir, 'hfs$upload-' + keepName)
65 const resumable = fs.existsSync(tempName) && tempName
@@ -85,10 +94,7 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
94 ret.once('close', async () => {
95 if (!ctx.req.aborted) {
96 let dest = fullPath
88 - await storeFileAttr(tempName, ATTR_UPLOADER, {
89 - username: getCurrentUsername(ctx),
90 - ip: ctx.ip,
91 - })
97 + await setUploadMeta(tempName, ctx)
98 if (dontOverwriteUploading.get() && fs.existsSync(dest)) {
99 const ext = extname(dest)
100 const base = dest.slice(0, -ext.length)