@appstrate/core 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/storage.ts +6 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appstrate/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "files": ["src"],
6
6
  "exports": {
package/src/storage.ts CHANGED
@@ -30,21 +30,23 @@ export function createStorage(storageDir: string): Storage {
30
30
  path: string,
31
31
  data: Uint8Array | Buffer,
32
32
  ): Promise<string> {
33
- const fullDir = join(storageDir, bucket, ...path.split("/").slice(0, -1));
33
+ const fullPath = safePath(bucket, path);
34
+ const fullDir = join(fullPath, "..");
34
35
  await mkdir(fullDir, { recursive: true });
35
- const fullPath = join(storageDir, bucket, path);
36
36
  await Bun.write(fullPath, data);
37
37
  return fullPath;
38
38
  }
39
39
 
40
40
  async function downloadFile(bucket: string, path: string): Promise<Uint8Array | null> {
41
- const file = Bun.file(join(storageDir, bucket, path));
41
+ const fullPath = safePath(bucket, path);
42
+ const file = Bun.file(fullPath);
42
43
  if (!(await file.exists())) return null;
43
44
  return new Uint8Array(await file.arrayBuffer());
44
45
  }
45
46
 
46
47
  async function deleteFile(bucket: string, path: string): Promise<void> {
47
- await rm(join(storageDir, bucket, path), { force: true });
48
+ const fullPath = safePath(bucket, path);
49
+ await rm(fullPath, { force: true });
48
50
  }
49
51
 
50
52
  async function listFiles(bucket: string, prefix = ""): Promise<string[]> {