@axium/storage 0.7.4 → 0.7.5

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.
@@ -1,10 +1,11 @@
1
1
  <script lang="ts">
2
- import { FormDialog, Icon } from '@axium/client/components';
2
+ import { page } from '$app/state';
3
3
  import { copy } from '@axium/client/clipboard';
4
+ import { FormDialog, Icon } from '@axium/client/components';
4
5
  import * as icon from '@axium/core/icons';
5
6
  import { deleteItem, updateItemMetadata } from '@axium/storage/client';
6
7
  import type { StorageItemMetadata } from '@axium/storage/common';
7
- import { getDirectory, preferences, selection, toggle, toggleRange } from '@axium/storage/sidebar';
8
+ import { getDirectory, selection, toggle, toggleRange } from '@axium/storage/sidebar';
8
9
  import SidebarItem from './SidebarItem.svelte';
9
10
 
10
11
  let {
@@ -105,7 +106,7 @@
105
106
  {#if item.type == 'cas_item'}
106
107
  {@render action('download', 'download', 'Download')}
107
108
  {/if}
108
- {#if preferences.debug}
109
+ {#if page.data.session?.user.preferences.debug}
109
110
  <div class="action icon-text" onclick={() => copy('text/plain', item.id)}>
110
111
  <Icon i="copy" --size="14px" />
111
112
  Copy ID
package/lib/Usage.svelte CHANGED
@@ -4,21 +4,25 @@
4
4
  import { getUserStorageInfo } from '@axium/storage/client';
5
5
  import type { UserStorageInfo } from '@axium/storage/common';
6
6
 
7
- const { userId, info }: { userId: string; info?: UserStorageInfo } = $props();
7
+ const { userId, info }: { userId?: string; info?: UserStorageInfo } = $props();
8
8
  </script>
9
9
 
10
- {#await info || getUserStorageInfo(userId) then info}
11
- <p>
12
- <a href="/files/usage">
13
- <NumberBar
14
- max={info.limits.user_size * 1_000_000}
15
- value={info.usage.bytes}
16
- text="Using {formatBytes(info.usage.bytes)} of {formatBytes(info.limits.user_size * 1_000_000)}"
17
- --fill="#345"
18
- />
19
- </a>
20
- </p>
21
- {:catch error}
22
- <p>Couldn't load your uploads.</p>
23
- <p>{error.message}</p>
24
- {/await}
10
+ {#if !info && !userId}
11
+ <p>Log in to see storage usage.</p>
12
+ {:else}
13
+ {#await info || getUserStorageInfo(userId!) then info}
14
+ <p>
15
+ <a href="/files/usage">
16
+ <NumberBar
17
+ max={info.limits.user_size * 1_000_000}
18
+ value={info.usage.bytes}
19
+ text="Using {formatBytes(info.usage.bytes)} of {formatBytes(info.limits.user_size * 1_000_000)}"
20
+ --fill="#345"
21
+ />
22
+ </a>
23
+ </p>
24
+ {:catch error}
25
+ <p>Couldn't load your uploads.</p>
26
+ <p>{error.message}</p>
27
+ {/await}
28
+ {/if}
@@ -1,9 +1,6 @@
1
- import type { StorageItemMetadata } from '@axium/storage/common';
2
1
  import { getDirectoryMetadata } from '@axium/storage/client';
2
+ import type { StorageItemMetadata } from '@axium/storage/common';
3
3
  import { SvelteSet } from 'svelte/reactivity';
4
- import { preferenceDefaults, type Preferences } from '@axium/core';
5
-
6
- export const preferences = $state<Preferences>(preferenceDefaults);
7
4
 
8
5
  export const selection = $state(new SvelteSet());
9
6
 
package/lib/tsconfig.json CHANGED
@@ -4,7 +4,8 @@
4
4
  "rootDir": "..",
5
5
  "noEmit": true,
6
6
  "module": "preserve",
7
- "moduleResolution": "Bundler"
7
+ "moduleResolution": "Bundler",
8
+ "types": ["@sveltejs/kit"]
8
9
  },
9
10
  "include": ["**/*.svelte", "**/*.ts"],
10
11
  "exclude": [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {
@@ -13,7 +13,7 @@
13
13
  {/each}
14
14
 
15
15
  <div class="usage">
16
- <StorageUsage userId={data.session.userId} />
16
+ <StorageUsage userId={data.session?.userId} />
17
17
  </div>
18
18
  </div>
19
19
 
@@ -1,17 +1,14 @@
1
1
  import { getCurrentSession } from '@axium/client/user';
2
- import { redirect } from '@sveltejs/kit';
3
- import type { LayoutLoadEvent, LayoutRouteId } from './$types';
4
2
  import type { Session } from '@axium/core';
3
+ import type { LayoutRouteId } from './$types';
5
4
 
6
5
  export const ssr = false;
7
6
 
8
- export async function load({ url, route, parent }: LayoutLoadEvent) {
7
+ export async function load({ url, route, parent }) {
9
8
  let { session }: { session?: Session | null } = await parent();
10
9
 
11
10
  session ||= await getCurrentSession().catch(() => null);
12
11
 
13
- if (!session) redirect(307, '/login?after=' + url.pathname);
14
-
15
12
  const tabs = [
16
13
  { name: 'files', href: '/files', icon: 'folders', active: route.id.endsWith('/files/[id]') || route.id.endsWith('/files') },
17
14
  { name: 'trash', href: '/files/trash', icon: 'trash', active: route.id.endsWith('/files/trash') },
@@ -1,12 +1,12 @@
1
1
  import { getUserStorageRoot } from '@axium/storage/client';
2
- import type { LoadEvent } from '@sveltejs/kit';
2
+ import { redirect } from '@sveltejs/kit';
3
3
 
4
4
  export const ssr = false;
5
5
 
6
- export async function load({ parent }: LoadEvent) {
6
+ export async function load({ parent }) {
7
7
  const { session } = await parent();
8
8
 
9
- return {
10
- items: await getUserStorageRoot(session.userId),
11
- };
9
+ if (!session) redirect(307, '/login?after=/files');
10
+
11
+ return { items: await getUserStorageRoot(session.userId) };
12
12
  }
@@ -4,7 +4,7 @@ import type { StorageItemMetadata } from '@axium/storage/common';
4
4
 
5
5
  export const ssr = false;
6
6
 
7
- export async function load({ parent, params }: PageLoadEvent) {
7
+ export async function load({ params }: PageLoadEvent) {
8
8
  const item = await getItemMetadata(params.id);
9
9
 
10
10
  let items: StorageItemMetadata[] | undefined;
@@ -1,12 +1,12 @@
1
- import type { LoadEvent } from '@sveltejs/kit';
2
1
  import { itemsSharedWith } from '@axium/storage/client';
2
+ import { redirect } from '@sveltejs/kit';
3
3
 
4
4
  export const ssr = false;
5
5
 
6
- export async function load({ parent }: LoadEvent) {
6
+ export async function load({ parent }) {
7
7
  const { session } = await parent();
8
8
 
9
- return {
10
- items: await itemsSharedWith(session.userId),
11
- };
9
+ if (!session) redirect(307, '/login?after=/files/shared');
10
+
11
+ return { items: await itemsSharedWith(session.userId) };
12
12
  }
@@ -1,12 +1,12 @@
1
1
  import { getUserTrash } from '@axium/storage/client';
2
- import type { LoadEvent } from '@sveltejs/kit';
2
+ import { redirect } from '@sveltejs/kit';
3
3
 
4
4
  export const ssr = false;
5
5
 
6
- export async function load({ parent }: LoadEvent) {
6
+ export async function load({ parent }) {
7
7
  const { session } = await parent();
8
8
 
9
- return {
10
- items: await getUserTrash(session.userId),
11
- };
9
+ if (!session) redirect(307, '/login?after=/files/trash');
10
+
11
+ return { items: await getUserTrash(session.userId) };
12
12
  }