@axium/storage 0.6.5 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.d.ts +1 -0
- package/dist/server.js +12 -7
- package/package.json +1 -1
package/dist/server.d.ts
CHANGED
|
@@ -82,4 +82,5 @@ export type ExternalLimitHandler = (userId?: string) => StorageLimits | Promise<
|
|
|
82
82
|
*/
|
|
83
83
|
export declare function useLimits(handler: ExternalLimitHandler): void;
|
|
84
84
|
export declare function getLimits(userId?: string): Promise<StorageLimits>;
|
|
85
|
+
export declare function getRecursive(id: string): AsyncGenerator<string>;
|
|
85
86
|
export {};
|
package/dist/server.js
CHANGED
|
@@ -93,6 +93,15 @@ export async function getLimits(userId) {
|
|
|
93
93
|
return config.storage.limits;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
+
export async function* getRecursive(id) {
|
|
97
|
+
const items = await database.selectFrom('storage').where('parentId', '=', id).selectAll().execute();
|
|
98
|
+
for (const item of items) {
|
|
99
|
+
if (item.type != 'inode/directory')
|
|
100
|
+
yield item.id;
|
|
101
|
+
else
|
|
102
|
+
yield* getRecursive(item.id);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
96
105
|
addRoute({
|
|
97
106
|
path: '/api/storage/item/:id',
|
|
98
107
|
params: { id: z.uuid() },
|
|
@@ -134,13 +143,9 @@ addRoute({
|
|
|
134
143
|
const itemId = event.params.id;
|
|
135
144
|
const auth = await checkAuthForItem(event, 'storage', itemId, Permission.Manage);
|
|
136
145
|
const item = parseItem(auth.item);
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
.returningAll()
|
|
141
|
-
.execute()
|
|
142
|
-
.catch(withError('Could not delete item'));
|
|
143
|
-
for (const { id } of results)
|
|
146
|
+
const toDelete = await Array.fromAsync(getRecursive(itemId)).catch(withError('Could not get items to delete'));
|
|
147
|
+
await database.deleteFrom('storage').where('id', '=', itemId).returningAll().execute().catch(withError('Could not delete item'));
|
|
148
|
+
for (const id of toDelete)
|
|
144
149
|
unlinkSync(join(config.storage.data, id));
|
|
145
150
|
return item;
|
|
146
151
|
},
|