@axium/storage 0.6.6 → 0.6.8
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 +2 -0
- package/dist/server.js +18 -10
- package/package.json +1 -1
package/dist/server.d.ts
CHANGED
|
@@ -82,4 +82,6 @@ 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>;
|
|
86
|
+
export declare function deleteRecursive(itemId: string, deleteSelf: boolean): Promise<void>;
|
|
85
87
|
export {};
|
package/dist/server.js
CHANGED
|
@@ -93,6 +93,23 @@ 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
|
+
}
|
|
105
|
+
export async function deleteRecursive(itemId, deleteSelf) {
|
|
106
|
+
const toDelete = await Array.fromAsync(getRecursive(itemId)).catch(withError('Could not get items to delete'));
|
|
107
|
+
if (deleteSelf)
|
|
108
|
+
toDelete.push(itemId);
|
|
109
|
+
await database.deleteFrom('storage').where('id', '=', itemId).returningAll().execute().catch(withError('Could not delete item'));
|
|
110
|
+
for (const id of toDelete)
|
|
111
|
+
unlinkSync(join(config.storage.data, id));
|
|
112
|
+
}
|
|
96
113
|
addRoute({
|
|
97
114
|
path: '/api/storage/item/:id',
|
|
98
115
|
params: { id: z.uuid() },
|
|
@@ -134,16 +151,7 @@ addRoute({
|
|
|
134
151
|
const itemId = event.params.id;
|
|
135
152
|
const auth = await checkAuthForItem(event, 'storage', itemId, Permission.Manage);
|
|
136
153
|
const item = parseItem(auth.item);
|
|
137
|
-
|
|
138
|
-
.deleteFrom('storage')
|
|
139
|
-
.where('id', '=', itemId)
|
|
140
|
-
.returningAll()
|
|
141
|
-
.execute()
|
|
142
|
-
.catch(withError('Could not delete item'));
|
|
143
|
-
for (const { id, type } of results) {
|
|
144
|
-
if (type != 'inode/directory')
|
|
145
|
-
unlinkSync(join(config.storage.data, id));
|
|
146
|
-
}
|
|
154
|
+
await deleteRecursive(itemId, item.type != 'inode/directory');
|
|
147
155
|
return item;
|
|
148
156
|
},
|
|
149
157
|
});
|