@axium/storage 0.6.6 → 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 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,16 +143,10 @@ 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 results = await database
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
- }
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)
149
+ unlinkSync(join(config.storage.data, id));
147
150
  return item;
148
151
  },
149
152
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {