@axium/storage 0.6.7 → 0.6.9

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
@@ -83,4 +83,5 @@ export type ExternalLimitHandler = (userId?: string) => StorageLimits | Promise<
83
83
  export declare function useLimits(handler: ExternalLimitHandler): void;
84
84
  export declare function getLimits(userId?: string): Promise<StorageLimits>;
85
85
  export declare function getRecursive(id: string): AsyncGenerator<string>;
86
+ export declare function deleteRecursive(itemId: string, deleteSelf: boolean): Promise<void>;
86
87
  export {};
package/dist/server.js CHANGED
@@ -102,6 +102,14 @@ export async function* getRecursive(id) {
102
102
  yield* getRecursive(item.id);
103
103
  }
104
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
+ }
105
113
  addRoute({
106
114
  path: '/api/storage/item/:id',
107
115
  params: { id: z.uuid() },
@@ -143,10 +151,7 @@ addRoute({
143
151
  const itemId = event.params.id;
144
152
  const auth = await checkAuthForItem(event, 'storage', itemId, Permission.Manage);
145
153
  const item = parseItem(auth.item);
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));
154
+ await deleteRecursive(itemId, item.type != 'inode/directory');
150
155
  return item;
151
156
  },
152
157
  });
package/lib/Add.svelte CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  {#snippet _item(type: string, text: string, includeContent: boolean = false)}
18
18
  <span
19
- class="icon-text add-menu-item"
19
+ class="menu-item"
20
20
  onclick={() => {
21
21
  createType = type;
22
22
  createIncludesContent = includeContent;
@@ -33,12 +33,10 @@
33
33
  <button class="icon-text"><Icon i="plus" />Add</button>
34
34
  {/snippet}
35
35
 
36
- <div class="add-menu">
37
- <span class="icon-text add-menu-item" onclick={() => uploadDialog.showModal()}><Icon i="upload" />Upload</span>
38
- {@render _item('inode/directory', 'New Folder')}
39
- {@render _item('text/plain', 'Plain Text')}
40
- {@render _item('text/x-uri', 'URL', true)}
41
- </div>
36
+ <span class="menu-item" onclick={() => uploadDialog.showModal()}><Icon i="upload" />Upload</span>
37
+ {@render _item('inode/directory', 'New Folder')}
38
+ {@render _item('text/plain', 'Plain Text')}
39
+ {@render _item('text/x-uri', 'URL', true)}
42
40
  </Popover>
43
41
 
44
42
  <FormDialog
@@ -76,17 +74,7 @@
76
74
  </FormDialog>
77
75
 
78
76
  <style>
79
- .add-menu {
80
- display: flex;
81
- flex-direction: column;
82
- }
83
-
84
- .add-menu-item {
85
- border-radius: 0.5em;
86
- padding: 0.25em 0.25em;
87
- }
88
-
89
- .add-menu-item:hover {
77
+ .menu-item:hover {
90
78
  cursor: pointer;
91
79
  background-color: #4455;
92
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {
@@ -40,7 +40,7 @@
40
40
  "peerDependencies": {
41
41
  "@axium/client": ">=0.1.0",
42
42
  "@axium/core": ">=0.5.4",
43
- "@axium/server": ">=0.22.0",
43
+ "@axium/server": ">=0.22.5",
44
44
  "@sveltejs/kit": "^2.27.3",
45
45
  "utilium": "^2.3.8"
46
46
  },
@@ -1,11 +1,14 @@
1
1
  import { getCurrentSession } from '@axium/client/user';
2
2
  import { redirect } from '@sveltejs/kit';
3
3
  import type { LayoutLoadEvent, LayoutRouteId } from './$types';
4
+ import type { Session } from '@axium/core';
4
5
 
5
6
  export const ssr = false;
6
7
 
7
- export async function load({ url, route }: LayoutLoadEvent) {
8
- const session = await getCurrentSession().catch(() => null);
8
+ export async function load({ url, route, parent }: LayoutLoadEvent) {
9
+ let { session }: { session?: Session | null } = await parent();
10
+
11
+ session ||= await getCurrentSession().catch(() => null);
9
12
 
10
13
  if (!session) redirect(307, '/login?after=' + url.pathname);
11
14