@samitouri / QOSami-HFS / commits / cdbc8098

better code: stop using deprecated api

Massimo Melina committed Dec 30, 2024 at 13:04 UTC cdbc8098ebcdda2347aa6a9fd6ed9637d90b8272
6 files changed +6 -7
src/SendList.ts
+1 -1
@@ -43,7 +43,7 @@ export class SendListReadable<T> extends Readable {
43 this.push(this.buffer)
44 this.buffer = []
45 }, bufferTime, { maxWait: bufferTime })
46 - this.on('end', () => {
46 + this.on('close', () => {
47 onEnd?.(this)
48 this.destroy()
49 })
src/api.get_file_list.ts
-1
@@ -68,7 +68,6 @@ export const get_file_list: ApiHandler = async ({ uri='/', offset, limit, search
68
69 async function* produceEntries() {
70 for await (const sub of walker) {
71 - if (ctx.aborted) break
71 let name = getNodeName(sub)
72 name = basename(name) || name // on windows, basename('C:') === ''
73 if (descriptIon.get() && name === DESCRIPT_ION)
src/api.vfs.ts
+1 -1
@@ -203,7 +203,7 @@ const apis: ApiHandlers = {
203 const matching = makeMatcher(fileMask)
204 path = isWindowsDrive(path) ? path + '\\' : resolve(path || '/')
205 for await (const entry of dirStream(path)) {
206 - if (ctx.req.aborted)
206 + if (ctx.req.destroyed)
207 return
208 const {path:name} = entry
209 const isDir = entry.isDirectory()
src/upload.ts
+1 -1
@@ -161,7 +161,7 @@ export function uploadWriter(base: VfsNode, baseUri: string, path: string, ctx:
161 writeStream.once('close', async () => {
162 try {
163 await new Promise(res => fileStream.close(res)) // this only seem to be necessary on Windows
164 - if (ctx.req.aborted) {
164 + if (ctx.req.aborted) { // doc says .aborted is deprecated, replaced by .destroyed, but in my tests the latter is true even for completed uploads, while .aborted is only for interrupted ones
165 if (resumableTempName && !resumableLost && !resuming) // we don't want to be left with 2 temp files
166 return rm(tempName)
167 const sec = deleteUnfinishedUploadsAfter.get()
src/vfs.ts
+1 -2
@@ -299,8 +299,7 @@ export async function* walkNode(parent: VfsNode, {
299 let lastDir = prefixPath.slice(0, -1) || '.'
300 parentsCache.set(lastDir, parent)
301 for await (const entry of dirStream(source, { depth, onlyFolders, hidden: showHiddenFiles.get() })) {
302 - if (ctx?.req.aborted)
303 - return
302 + if (ctx?.req.aborted) break // investigate: "aborted" is deprecated, but "destroyed" will cause failure of some tests
303 const {path} = entry
304 const isFolder = entry.isDirectory()
305 const name = prefixPath + (parent.rename?.[path] || path)
src/zip.ts
+2 -1
@@ -24,6 +24,7 @@ export async function zipStreamFromFolder(node: VfsNode, ctx: Koa.Context) {
24 const walker = !list ? walkNode(node, { ctx, requiredPerm: 'can_archive' })
25 : (async function*(): AsyncIterableIterator<VfsNode> {
26 for await (const uri of list) {
27 + if (ctx.req.destroyed) return
28 const subNode = await urlToNode(uri, ctx, node)
29 if (!subNode)
30 continue
@@ -44,7 +45,7 @@ export async function zipStreamFromFolder(node: VfsNode, ctx: Koa.Context) {
45 if (!hasPermission(el, 'can_archive', ctx)) return // the fact you see it doesn't mean you can get it
46 const { source } = el
47 const name = getNodeName(el)
47 - if (ctx.req.aborted || !filter(name))
48 + if (!filter(name))
49 return
50 try {
51 if (el.isFolder)