@airnauts/comments-storage-vercel-blob 0.1.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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Airnauts
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @airnauts/comments-storage-vercel-blob
|
|
2
|
+
|
|
3
|
+
Vercel Blob attachment-storage adapter for the
|
|
4
|
+
[Airnauts commenting tool](https://github.com/Airnauts/commenting-tool) server.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pnpm add @airnauts/comments-storage-vercel-blob
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { VercelBlobStorage } from '@airnauts/comments-storage-vercel-blob'
|
|
16
|
+
|
|
17
|
+
const storage = new VercelBlobStorage() // reads BLOB_READ_WRITE_TOKEN
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Pass `storage` to `createCommentsServer` from `@airnauts/comments-server`.
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
MIT © Airnauts
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PutBlob, PutResult, StorageAdapter } from '@airnauts/comments-server';
|
|
2
|
+
export type VercelBlobStorageOptions = {
|
|
3
|
+
/** `BLOB_READ_WRITE_TOKEN`. If omitted, `@vercel/blob` reads it from `process.env`. */
|
|
4
|
+
token?: string;
|
|
5
|
+
/**
|
|
6
|
+
* Optional prefix (e.g. 'staging/') applied to every key. A trailing `/` is
|
|
7
|
+
* appended automatically if missing, so `'staging'` and `'staging/'` behave
|
|
8
|
+
* the same way.
|
|
9
|
+
*/
|
|
10
|
+
prefix?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare class VercelBlobStorage implements StorageAdapter {
|
|
13
|
+
private readonly opts;
|
|
14
|
+
private readonly prefix;
|
|
15
|
+
constructor(opts?: VercelBlobStorageOptions);
|
|
16
|
+
put(blob: PutBlob): Promise<PutResult>;
|
|
17
|
+
}
|
|
18
|
+
/** Construct a Vercel Blob `StorageAdapter` (uniform `xxxStorage(config)` shape). */
|
|
19
|
+
export declare function vercelBlobStorage(opts?: VercelBlobStorageOptions): StorageAdapter;
|
|
20
|
+
export declare const packageName = "@airnauts/comments-storage-vercel-blob";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAGnF,MAAM,MAAM,wBAAwB,GAAG;IACrC,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAiCD,qBAAa,iBAAkB,YAAW,cAAc;IAG1C,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAEF,IAAI,GAAE,wBAA6B;IAK1D,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;CAgB7C;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,wBAA6B,GAAG,cAAc,CAErF;AAED,eAAO,MAAM,WAAW,2CAA2C,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { put } from "@vercel/blob";
|
|
3
|
+
function sanitizeName(name) {
|
|
4
|
+
const cleaned = name.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 200);
|
|
5
|
+
return cleaned.length > 0 ? cleaned : "file";
|
|
6
|
+
}
|
|
7
|
+
async function readAllBytes(data) {
|
|
8
|
+
if (data instanceof Uint8Array) return data;
|
|
9
|
+
const reader = data.getReader();
|
|
10
|
+
const chunks = [];
|
|
11
|
+
let total = 0;
|
|
12
|
+
try {
|
|
13
|
+
for (; ; ) {
|
|
14
|
+
const { value, done } = await reader.read();
|
|
15
|
+
if (done) break;
|
|
16
|
+
if (value) {
|
|
17
|
+
chunks.push(value);
|
|
18
|
+
total += value.byteLength;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} finally {
|
|
22
|
+
reader.releaseLock();
|
|
23
|
+
}
|
|
24
|
+
const out = new Uint8Array(total);
|
|
25
|
+
let offset = 0;
|
|
26
|
+
for (const c of chunks) {
|
|
27
|
+
out.set(c, offset);
|
|
28
|
+
offset += c.byteLength;
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
var VercelBlobStorage = class {
|
|
33
|
+
constructor(opts = {}) {
|
|
34
|
+
this.opts = opts;
|
|
35
|
+
const raw = opts.prefix ?? "";
|
|
36
|
+
this.prefix = raw === "" || raw.endsWith("/") ? raw : `${raw}/`;
|
|
37
|
+
}
|
|
38
|
+
opts;
|
|
39
|
+
prefix;
|
|
40
|
+
async put(blob) {
|
|
41
|
+
const bytes = await readAllBytes(blob.data);
|
|
42
|
+
const body = new Blob([bytes], { type: blob.contentType });
|
|
43
|
+
const key = `${this.prefix}${sanitizeName(blob.name)}`;
|
|
44
|
+
const result = await put(key, body, {
|
|
45
|
+
access: "public",
|
|
46
|
+
contentType: blob.contentType,
|
|
47
|
+
addRandomSuffix: true,
|
|
48
|
+
token: this.opts.token
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
key: result.pathname,
|
|
52
|
+
url: result.url,
|
|
53
|
+
size: bytes.byteLength
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
function vercelBlobStorage(opts = {}) {
|
|
58
|
+
return new VercelBlobStorage(opts);
|
|
59
|
+
}
|
|
60
|
+
var packageName = "@airnauts/comments-storage-vercel-blob";
|
|
61
|
+
export {
|
|
62
|
+
VercelBlobStorage,
|
|
63
|
+
packageName,
|
|
64
|
+
vercelBlobStorage
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { PutBlob, PutResult, StorageAdapter } from '@airnauts/comments-server'\nimport { put } from '@vercel/blob'\n\nexport type VercelBlobStorageOptions = {\n /** `BLOB_READ_WRITE_TOKEN`. If omitted, `@vercel/blob` reads it from `process.env`. */\n token?: string\n /**\n * Optional prefix (e.g. 'staging/') applied to every key. A trailing `/` is\n * appended automatically if missing, so `'staging'` and `'staging/'` behave\n * the same way.\n */\n prefix?: string\n}\n\nfunction sanitizeName(name: string): string {\n const cleaned = name.replace(/[^A-Za-z0-9._-]/g, '_').slice(0, 200)\n return cleaned.length > 0 ? cleaned : 'file'\n}\n\nasync function readAllBytes(data: Uint8Array | ReadableStream<Uint8Array>): Promise<Uint8Array> {\n if (data instanceof Uint8Array) return data\n const reader = data.getReader()\n const chunks: Uint8Array[] = []\n let total = 0\n try {\n for (;;) {\n const { value, done } = await reader.read()\n if (done) break\n if (value) {\n chunks.push(value)\n total += value.byteLength\n }\n }\n } finally {\n reader.releaseLock()\n }\n const out = new Uint8Array(total)\n let offset = 0\n for (const c of chunks) {\n out.set(c, offset)\n offset += c.byteLength\n }\n return out\n}\n\nexport class VercelBlobStorage implements StorageAdapter {\n private readonly prefix: string\n\n constructor(private readonly opts: VercelBlobStorageOptions = {}) {\n const raw = opts.prefix ?? ''\n this.prefix = raw === '' || raw.endsWith('/') ? raw : `${raw}/`\n }\n\n async put(blob: PutBlob): Promise<PutResult> {\n const bytes = await readAllBytes(blob.data)\n const body = new Blob([bytes], { type: blob.contentType })\n const key = `${this.prefix}${sanitizeName(blob.name)}`\n const result = await put(key, body, {\n access: 'public',\n contentType: blob.contentType,\n addRandomSuffix: true,\n token: this.opts.token,\n })\n return {\n key: result.pathname,\n url: result.url,\n size: bytes.byteLength,\n }\n }\n}\n\n/** Construct a Vercel Blob `StorageAdapter` (uniform `xxxStorage(config)` shape). */\nexport function vercelBlobStorage(opts: VercelBlobStorageOptions = {}): StorageAdapter {\n return new VercelBlobStorage(opts)\n}\n\nexport const packageName = '@airnauts/comments-storage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;AAAA,MACjB,OAAO,KAAK,KAAK;AAAA,IACnB,CAAC;AACD,WAAO;AAAA,MACL,KAAK,OAAO;AAAA,MACZ,KAAK,OAAO;AAAA,MACZ,MAAM,MAAM;AAAA,IACd;AAAA,EACF;AACF;AAGO,SAAS,kBAAkB,OAAiC,CAAC,GAAmB;AACrF,SAAO,IAAI,kBAAkB,IAAI;AACnC;AAEO,IAAM,cAAc;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@airnauts/comments-storage-vercel-blob",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vercel Blob attachment-storage adapter for the Airnauts commenting tool server.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"comments",
|
|
7
|
+
"commenting",
|
|
8
|
+
"annotations",
|
|
9
|
+
"feedback",
|
|
10
|
+
"airnauts",
|
|
11
|
+
"storage",
|
|
12
|
+
"vercel",
|
|
13
|
+
"blob"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Airnauts",
|
|
17
|
+
"homepage": "https://github.com/Airnauts/commenting-tool#readme",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/Airnauts/commenting-tool.git",
|
|
21
|
+
"directory": "packages/storage-vercel-blob"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/Airnauts/commenting-tool/issues"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"!dist/.tsbuildinfo",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@vercel/blob": "^1.1.1",
|
|
44
|
+
"@airnauts/comments-core": "^0.1.0",
|
|
45
|
+
"@airnauts/comments-server": "^0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@airnauts/comments-test-support": "0.0.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup && tsc --build --force",
|
|
52
|
+
"typecheck": "tsc --build",
|
|
53
|
+
"test": "vitest run"
|
|
54
|
+
}
|
|
55
|
+
}
|