@concavejs/blobstore-node-fs 0.0.1-alpha.5 → 0.0.1-alpha.7
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/fs-storage.d.ts +2 -0
- package/dist/index.js +26 -19
- package/package.json +2 -2
package/dist/fs-storage.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare class FsBlobStore implements BlobStore {
|
|
|
10
10
|
constructor(baseDir?: string);
|
|
11
11
|
private ensureDirectories;
|
|
12
12
|
private pathExists;
|
|
13
|
+
private isNotFoundError;
|
|
13
14
|
private generateStorageId;
|
|
14
15
|
private getObjectPath;
|
|
15
16
|
private getMetadataPath;
|
|
@@ -22,4 +23,5 @@ export declare class FsBlobStore implements BlobStore {
|
|
|
22
23
|
* Get metadata for a stored object
|
|
23
24
|
*/
|
|
24
25
|
getMetadata(storageId: string): Promise<StorageMetadata | null>;
|
|
26
|
+
private unlinkIfExists;
|
|
25
27
|
}
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,9 @@ class FsBlobStore {
|
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
isNotFoundError(error) {
|
|
26
|
+
return !!error && typeof error === "object" && "code" in error && error.code === "ENOENT";
|
|
27
|
+
}
|
|
25
28
|
generateStorageId() {
|
|
26
29
|
return crypto.randomUUID();
|
|
27
30
|
}
|
|
@@ -62,31 +65,25 @@ class FsBlobStore {
|
|
|
62
65
|
async get(storageId) {
|
|
63
66
|
const objectPath = this.getObjectPath(storageId);
|
|
64
67
|
try {
|
|
65
|
-
const fileExists = await this.pathExists(objectPath);
|
|
66
|
-
if (!fileExists) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
68
|
const data = await readFile(objectPath);
|
|
70
69
|
const metadata = await this.getMetadata(storageId);
|
|
71
70
|
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
72
71
|
return new Blob([arrayBuffer], { type: metadata?.contentType || "application/octet-stream" });
|
|
73
72
|
} catch (error) {
|
|
73
|
+
if (this.isNotFoundError(error)) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
74
76
|
console.error("Error reading object from filesystem:", error);
|
|
75
|
-
|
|
77
|
+
throw error;
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
async delete(storageId) {
|
|
79
81
|
const objectPath = this.getObjectPath(storageId);
|
|
80
82
|
const metadataPath = this.getMetadataPath(storageId);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
]);
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error("Error deleting object from filesystem:", error);
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
83
|
+
await Promise.all([
|
|
84
|
+
this.unlinkIfExists(objectPath),
|
|
85
|
+
this.unlinkIfExists(metadataPath)
|
|
86
|
+
]);
|
|
90
87
|
}
|
|
91
88
|
async getUrl(storageId) {
|
|
92
89
|
const objectPath = this.getObjectPath(storageId);
|
|
@@ -100,15 +97,25 @@ class FsBlobStore {
|
|
|
100
97
|
async getMetadata(storageId) {
|
|
101
98
|
const metadataPath = this.getMetadataPath(storageId);
|
|
102
99
|
try {
|
|
103
|
-
const fileExists = await this.pathExists(metadataPath);
|
|
104
|
-
if (!fileExists) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
100
|
const data = await readFile(metadataPath, "utf-8");
|
|
108
101
|
return JSON.parse(data);
|
|
109
102
|
} catch (error) {
|
|
103
|
+
if (this.isNotFoundError(error)) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
110
106
|
console.error("Error reading metadata from filesystem:", error);
|
|
111
|
-
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async unlinkIfExists(path) {
|
|
111
|
+
try {
|
|
112
|
+
await unlink(path);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (this.isNotFoundError(error)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
console.error("Error deleting object from filesystem:", error);
|
|
118
|
+
throw error;
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
121
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@concavejs/blobstore-node-fs",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.7",
|
|
4
4
|
"license": "FSL-1.1-Apache-2.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"test": "vitest --run --passWithNoTests"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@concavejs/core": "0.0.1-alpha.
|
|
24
|
+
"@concavejs/core": "0.0.1-alpha.6"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^24.9.1"
|