@axium/storage 0.22.0 → 0.22.1

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.
@@ -64,7 +64,6 @@ export async function uploadItem(file, opt = {}) {
64
64
  if (!opt.name)
65
65
  throw 'item name is required';
66
66
  const content = await file.bytes();
67
- opt.onProgress?.(0, content.length);
68
67
  /** For big files, it takes a *really* long time to compute the hash, so we just don't do it ahead of time and leave it up to the server. */
69
68
  const hash = content.length < uploadConfig.hashThreshold * 1_000_000 ? blake2b(content).toHex() : null;
70
69
  const upload = await fetchAPI('PUT', 'storage', {
@@ -77,6 +76,7 @@ export async function uploadItem(file, opt = {}) {
77
76
  if (upload.status == 'created')
78
77
  return upload.item;
79
78
  const chunkSize = Math.min(upload.max_transfer_size, globalThis.navigator?.connection ? conTypeToSpeed[globalThis.navigator.connection.effectiveType] : uploadConfig.uxChunkSize) * 1_000_000;
79
+ opt.onProgress?.(0, content.length);
80
80
  let response;
81
81
  for (let offset = 0; offset < content.length; offset += chunkSize) {
82
82
  const size = Math.min(chunkSize, content.length - offset);
@@ -87,6 +87,7 @@ export async function uploadItem(file, opt = {}) {
87
87
  'x-offset': offset.toString(),
88
88
  'content-length': size.toString(),
89
89
  'content-type': 'application/octet-stream',
90
+ authorization: 'Bearer ' + token,
90
91
  },
91
92
  body: content.slice(offset, offset + size),
92
93
  }).catch(handleFetchFailed);
@@ -117,6 +118,7 @@ export async function uploadItemStream(stream, opt) {
117
118
  'x-offset': offset.toString(),
118
119
  'content-length': size.toString(),
119
120
  'content-type': 'application/octet-stream',
121
+ authorization: 'Bearer ' + token,
120
122
  },
121
123
  body: new ReadableStream({
122
124
  type: 'bytes',
@@ -59,6 +59,7 @@ import { Readable } from 'node:stream';
59
59
  import { colorItem, formatItems } from '../../node.js';
60
60
  import * as api from '../api.js';
61
61
  import { getDirectory, resolveItem, resolvePathWithParent, syncCache, writeCache } from '../local.js';
62
+ import { formatBytes } from '@axium/core';
62
63
  export const ls = new Command('ls')
63
64
  .alias('list')
64
65
  .description('List the contents of a folder')
@@ -140,10 +141,9 @@ export const upload = new Command('upload')
140
141
  size: stats.size,
141
142
  type,
142
143
  onProgress(uploaded, total) {
143
- io.progress(uploaded, total, Math.round((uploaded / total) * 100) + '%');
144
+ io.progress(uploaded, total, Math.round((uploaded / total) * 100) + '%', `${formatBytes(BigInt(uploaded))}/${formatBytes(BigInt(total))}`);
144
145
  },
145
146
  });
146
- io.done();
147
147
  const { items } = await syncCache();
148
148
  items.push(item);
149
149
  writeCache();
@@ -169,18 +169,18 @@ export const download = new Command('download')
169
169
  if (item.type == 'inode/directory')
170
170
  throw "Can't download directories yet.";
171
171
  localPath ||= item.name;
172
- const _ = __addDisposableResource(env_2, io.start('Downloading to' + localPath), false);
172
+ const _ = __addDisposableResource(env_2, io.start('Downloading to ' + localPath), false);
173
173
  const stream = await api.downloadItemStream(item.id);
174
- io.progress(0, Number(item.size));
174
+ const size = Number(item.size);
175
+ io.progress(0, size);
175
176
  let downloaded = 0;
176
177
  const fileStream = fs.createWriteStream(localPath);
177
178
  for await (const chunk of stream) {
178
179
  fileStream.write(chunk);
179
180
  downloaded += chunk.length;
180
- io.progress(downloaded, Number(item.size));
181
+ io.progress(downloaded, size, Math.round((downloaded / size) * 100) + '%', `${formatBytes(BigInt(downloaded))}/${formatBytes(item.size)}`);
181
182
  }
182
183
  fileStream.end();
183
- io.done();
184
184
  }
185
185
  catch (e_2) {
186
186
  env_2.error = e_2;
@@ -4,13 +4,13 @@ import { UserPublic } from '@axium/core';
4
4
  import * as io from 'ioium/node';
5
5
  import { ENOENT, ENOTDIR } from 'node:constants';
6
6
  import { stat } from 'node:fs/promises';
7
- import { join, parse } from 'node:path';
7
+ import { join, parse, resolve } from 'node:path';
8
8
  import * as z from 'zod';
9
9
  import { StorageItemMetadata } from '../common.js';
10
10
  import { getUserStats, getUserStorage } from './api.js';
11
11
  export let remotePWD = '/';
12
12
  export function resolvePath(path) {
13
- path = join(remotePWD, path);
13
+ path = resolve(remotePWD, path);
14
14
  if (path != '/' && path.endsWith('/'))
15
15
  path = path.slice(0, -1);
16
16
  return path;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {
@@ -45,7 +45,7 @@
45
45
  "@axium/server": ">=0.39.0",
46
46
  "@sveltejs/kit": "^2.27.3",
47
47
  "commander": "^14.0.0",
48
- "ioium": "^1.1.0",
48
+ "ioium": "^1.2.0",
49
49
  "kysely": "^0.28.15",
50
50
  "mime": "^4.1.0",
51
51
  "utilium": "^3.1.0"