plugins: ctx.state.uploadDestinationPath

Massimo Melina committed May 16, 2024 at 17:33 UTC 1e22b7649a50724d8ee4407058e5a98b5870f7ef
1 file changed +8
src/upload.ts
+8
@@ -99,6 +99,7 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
99 tempName = resumable
100 }
101 cancelDeletion(tempName)
102 + ctx.state.uploadDestinationPath = tempName
103 trackProgress()
104 writeStream.once('close', async () => {
105 if (ctx.req.aborted) {
@@ -115,6 +116,7 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
116 do dest = `${base} (${i++})${ext}`
117 while (fs.existsSync(dest))
118 }
119 + ctx.state.uploadDestinationPath = dest
120 return fs.rename(tempName, dest, err => {
121 setUploadMeta(err ? tempName : dest, ctx)
122 if (err)
@@ -172,4 +174,10 @@ export function uploadWriter(base: VfsNode, path: string, ctx: Koa.Context) {
174 ctx.status = status
175 notifyClient(ctx, 'upload.status', { [path]: ctx.status }) // allow browsers to detect failure while still sending body
176 }
177 +}
178 +
179 +declare module "koa" {
180 + interface DefaultState {
181 + uploadDestinationPath?: string
182 + }
183 }
\ No newline at end of file