@samitouri / QOSami-HFS / commits / 14a23bbd

update descript.ion on rename and delete operations

Massimo Melina committed Sep 25, 2023 at 18:42 UTC 14a23bbd4916e5a7ad54620799393ec69fd44418
1 file changed +14 -6
src/frontEndApis.ts
+14 -6
@@ -15,7 +15,7 @@ import { mkdir, rename, rm } from 'fs/promises'
15 import { dirname, join } from 'path'
16 import { getUploadMeta } from './upload'
17 import { apiAssertTypes } from './misc'
18 -import { setCommentFor } from './comments'
18 +import { getCommentFor, setCommentFor } from './comments'
19
20 export const frontEndApis: ApiHandlers = {
21 get_file_list,
@@ -77,6 +77,7 @@ export const frontEndApis: ApiHandlers = {
77 throw new ApiError(HTTP_UNAUTHORIZED)
78 try {
79 await rm(node.source, { recursive: true })
80 + setCommentFor(node.source, '').then()
81 return {}
82 }
83 catch (e: any) {
@@ -94,12 +95,19 @@ export const frontEndApis: ApiHandlers = {
95 if (!hasPermission(node, 'can_delete', ctx))
96 throw new ApiError(HTTP_UNAUTHORIZED)
97 try {
97 - if (node.name)
98 + if (node.name) // virtual name = virtual rename
99 node.name = dest
99 - else if (node.source)
100 - await rename(node.source, join(dirname(node.source), dest))
101 - else
102 - throw new ApiError(HTTP_SERVER_ERROR)
100 + else {
101 + if (!node.source)
102 + throw new ApiError(HTTP_FAILED_DEPENDENCY)
103 + const destSource = join(dirname(node.source), dest)
104 + await rename(node.source, destSource)
105 + getCommentFor(node.source).then(c => {
106 + if (!c) return
107 + setCommentFor(node.source!, '').then()
108 + setCommentFor(destSource, c).then()
109 + })
110 + }
111 return {}
112 }
113 catch (e: any) {