@axium/storage 0.3.17 → 0.4.0

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/client.d.ts CHANGED
@@ -13,7 +13,7 @@ export declare function downloadItem(fileId: string): Promise<Blob>;
13
13
  export declare function updateItemMetadata(fileId: string, metadata: StorageItemUpdate): Promise<StorageItemMetadata>;
14
14
  export declare function deleteItem(fileId: string): Promise<StorageItemMetadata>;
15
15
  export declare function getUserFiles(userId: string): Promise<UserFilesInfo>;
16
- export interface _Sidebar {
16
+ export interface SidebarContext {
17
17
  selection: ItemSelection<string, StorageItemMetadata>;
18
18
  items: StorageItemMetadata[];
19
19
  getDirectory(id: string, assignTo?: StorageItemMetadata[]): Promise<StorageItemMetadata[]>;
package/dist/server.js CHANGED
@@ -62,7 +62,8 @@ export async function currentUsage(userId) {
62
62
  .select(eb => eb.fn.countAll().as('items'))
63
63
  .select(eb => eb.fn.sum('size').as('bytes'))
64
64
  .executeTakeFirstOrThrow();
65
- result.bytes ||= 0;
65
+ result.bytes = Number(result.bytes || 0);
66
+ result.items = Number(result.items);
66
67
  return result;
67
68
  }
68
69
  export async function get(itemId) {
@@ -5,9 +5,8 @@
5
5
  import { deleteItem, getDirectoryMetadata, updateItemMetadata } from '@axium/storage/client';
6
6
  import type { StorageItemMetadata } from '@axium/storage/common';
7
7
 
8
- const { id }: { id: string } = $props();
8
+ let { id, items = $bindable([]) }: { id: string; items?: StorageItemMetadata[] } = $props();
9
9
 
10
- let items = $state<StorageItemMetadata[]>([]);
11
10
  let activeIndex = $state<number>(-1);
12
11
  let activeItem = $derived(items[activeIndex]);
13
12
  const dialogs = $state<Record<string, HTMLDialogElement>>({});
@@ -36,7 +35,7 @@
36
35
  {/snippet}
37
36
 
38
37
  <div class="StorageList">
39
- {#await getDirectoryMetadata(id).then(data => (items = data)) then}
38
+ {#await items.length || getDirectoryMetadata(id).then(data => (items = data)) then}
40
39
  <div class="StorageListItem header">
41
40
  <span></span>
42
41
  <span>Name</span>
@@ -45,7 +44,7 @@
45
44
  </div>
46
45
  {#each items as item, i (item.id)}
47
46
  <div class="StorageListItem">
48
- <Icon i={iconForMime(item.type)} />
47
+ <dfn title={item.type}><Icon i={iconForMime(item.type)} /></dfn>
49
48
  <span class="name">{item.name}</span>
50
49
  <span>{item.modifiedAt.toLocaleString()}</span>
51
50
  <span>{formatBytes(item.size)}</span>
@@ -1,17 +1,17 @@
1
1
  <script lang="ts">
2
- import { getDirectoryMetadata, type _Sidebar } from '@axium/storage/client';
2
+ import { getDirectoryMetadata, type SidebarContext } from '@axium/storage/client';
3
3
  import type { StorageItemMetadata } from '@axium/storage/common';
4
4
  import { ItemSelection } from '@axium/storage/selection';
5
5
  import { setContext } from 'svelte';
6
6
  import StorageSidebarItem from './StorageSidebarItem.svelte';
7
7
 
8
- const { root }: { root: string | StorageItemMetadata[] } = $props();
8
+ let { root, sidebar = $bindable() }: { root: string | StorageItemMetadata[]; sidebar?: SidebarContext } = $props();
9
9
 
10
10
  let items = $state<StorageItemMetadata[]>([]);
11
11
 
12
12
  const allItems: StorageItemMetadata[] = [];
13
13
 
14
- const sidebar = $state<_Sidebar>({
14
+ sidebar = {
15
15
  selection: new ItemSelection(allItems),
16
16
  items: allItems,
17
17
  async getDirectory(id: string, assignTo?: StorageItemMetadata[]) {
@@ -20,19 +20,24 @@
20
20
  assignTo = data;
21
21
  return data;
22
22
  },
23
- });
23
+ };
24
24
 
25
- setContext('files:sidebar', () => sidebar);
25
+ setContext('storage:sidebar', () => sidebar);
26
26
 
27
- if (typeof root == 'string') allItems.push(...items);
27
+ if (typeof root != 'string') {
28
+ allItems.push(...root);
29
+ items = root;
30
+ }
28
31
  </script>
29
32
 
30
- <div id="FilesSidebar">
33
+ <div id="StorageSidebar">
31
34
  {#await typeof root == 'string' ? sidebar.getDirectory(root, items) : root}
32
35
  <i>Loading...</i>
33
36
  {:then}
34
37
  {#each items as _, i (_.id)}
35
38
  <StorageSidebarItem bind:item={items[i]} bind:items />
39
+ {:else}
40
+ <i>No files yet</i>
36
41
  {/each}
37
42
  {:catch error}
38
43
  <i style:color="#c44">{error.message}</i>
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import * as icon from '@axium/core/icons';
3
3
  import { ClipboardCopy, FormDialog, Icon } from '@axium/server/components';
4
- import { deleteItem, updateItemMetadata, type _Sidebar } from '@axium/storage/client';
4
+ import { deleteItem, updateItemMetadata, type SidebarContext } from '@axium/storage/client';
5
5
  import type { StorageItemMetadata } from '@axium/storage/common';
6
6
  import { getContext } from 'svelte';
7
7
  import StorageSidebarItem from './StorageSidebarItem.svelte';
@@ -17,7 +17,7 @@
17
17
  debug?: boolean;
18
18
  } = $props();
19
19
 
20
- const sb = getContext<() => _Sidebar>('files:sidebar')();
20
+ const sb = getContext<() => SidebarContext>('storage:sidebar')();
21
21
 
22
22
  const dialogs = $state<Record<string, HTMLDialogElement>>({});
23
23
  let popover = $state<HTMLDivElement>();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.3.17",
3
+ "version": "0.4.0",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {