@yongdall/fs-minio 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/hooks.yongdall.mjs +10 -0
- package/hooks.yongdall.mjs.map +1 -0
- package/index.d.mts +11 -0
- package/index.mjs +6 -0
- package/index.mjs.map +1 -0
- package/minio-DVpomKSG.mjs +53 -0
- package/minio-DVpomKSG.mjs.map +1 -0
- package/package.json +22 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import minio from "#index";
|
|
2
|
+
|
|
3
|
+
//#region providers/fs-minio/hooks.yongdall.mjs
|
|
4
|
+
/** @import { Hooks } from '@yongdall/connection' */
|
|
5
|
+
/** @type {Hooks.providers} */
|
|
6
|
+
const providers = { fs: { minio } };
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { providers };
|
|
10
|
+
//# sourceMappingURL=hooks.yongdall.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.yongdall.mjs","names":[],"sources":["../../providers/fs-minio/hooks.yongdall.mjs"],"sourcesContent":["import minio from '#index';\n/** @import { Hooks } from '@yongdall/connection' */\n/** @type {Hooks.providers} */\nexport const providers = {\n\tfs: { minio },\n};\n"],"mappings":";;;;;AAGA,MAAa,YAAY,EACxB,IAAI,EAAE,OAAO,EACb"}
|
package/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as stream0 from "stream";
|
|
2
|
+
|
|
3
|
+
//#region providers/fs-minio/index.d.mts
|
|
4
|
+
declare function _default(url: string): Promise<{
|
|
5
|
+
urlRead(path: string, expires?: number): Promise<string>;
|
|
6
|
+
urlWrite(path: string, expires?: number): Promise<string>;
|
|
7
|
+
read(path: string): Promise<ReadableStream>;
|
|
8
|
+
write(path: string, data: ReadableStream | Blob | ArrayBufferView | ArrayBuffer | string | Buffer | stream0.Readable, size?: number): Promise<void>;
|
|
9
|
+
}>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { _default as default };
|
package/index.mjs
ADDED
package/index.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../providers/fs-minio/index.mjs"],"sourcesContent":["export default (/** @type {string} */url) => import('./minio.mjs').then(v => v.default(url));\n"],"mappings":";AAAA,wBAAqC,QAAQ,OAAO,wBAAe,MAAK,MAAK,EAAE,QAAQ,IAAI,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Client } from "minio";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
|
|
4
|
+
//#region providers/fs-minio/minio.mjs
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {string[]} base
|
|
8
|
+
* @param {string} root
|
|
9
|
+
* @returns {[string, string]}
|
|
10
|
+
*/
|
|
11
|
+
function tPath(base, root) {
|
|
12
|
+
const [bucket, ...path] = [...base, ...root.split(/#|\?/, 1)[0].split("/").filter(Boolean)];
|
|
13
|
+
return [bucket, path.join("/")];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {string} uri
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
function useFile(uri) {
|
|
21
|
+
const url = new URL(uri);
|
|
22
|
+
const portText = url.port;
|
|
23
|
+
const client = new Client({
|
|
24
|
+
endPoint: url.hostname,
|
|
25
|
+
port: portText && parseInt(portText) || (url.protocol.includes("https") ? 443 : url.protocol.includes("https") ? 9e3 : 443),
|
|
26
|
+
useSSL: url.protocol.includes("https"),
|
|
27
|
+
accessKey: url.username,
|
|
28
|
+
secretKey: url.password
|
|
29
|
+
});
|
|
30
|
+
const root = url.pathname.split("/").filter(Boolean);
|
|
31
|
+
return {
|
|
32
|
+
async urlRead(path, expires = 3600 * 24) {
|
|
33
|
+
return await client.presignedGetObject(...tPath(root, path), expires);
|
|
34
|
+
},
|
|
35
|
+
async urlWrite(path, expires = 3600 * 24) {
|
|
36
|
+
return await client.presignedPutObject(...tPath(root, path), expires);
|
|
37
|
+
},
|
|
38
|
+
async read(path) {
|
|
39
|
+
return Readable.toWeb(await client.getObject(...tPath(root, path)));
|
|
40
|
+
},
|
|
41
|
+
async write(path, data, size) {
|
|
42
|
+
if (data instanceof ReadableStream) await client.putObject(...tPath(root, path), Readable.fromWeb(data), size);
|
|
43
|
+
else if (data instanceof Blob) await client.putObject(...tPath(root, path), Readable.fromWeb(data.stream()), data.size);
|
|
44
|
+
else if (ArrayBuffer.isView(data)) await client.putObject(...tPath(root, path), Buffer.from(data.buffer, data.byteOffset, data.byteLength));
|
|
45
|
+
else if (data instanceof ArrayBuffer) await client.putObject(...tPath(root, path), Buffer.from(data));
|
|
46
|
+
else await client.putObject(...tPath(root, path), data);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { useFile as default };
|
|
53
|
+
//# sourceMappingURL=minio-DVpomKSG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minio-DVpomKSG.mjs","names":[],"sources":["../../providers/fs-minio/minio.mjs"],"sourcesContent":["import { Client } from 'minio';\nimport { Readable } from 'node:stream';\n\n/**\n * \n * @param {string[]} base \n * @param {string} root \n * @returns {[string, string]}\n */\nfunction tPath(base, root) {\n\tconst [bucket, ...path] = [...base, ...root.split(/#|\\?/, 1)[0].split('/').filter(Boolean)];\n\treturn [bucket, path.join('/')];\n}\n/**\n * \n * @param {string} uri\n * @returns \n */\nexport default function useFile(uri) {\n\tconst url = new URL(uri);\n\tconst portText = url.port;\n\tconst client = new Client({\n\t\tendPoint: url.hostname,\n\t\tport: portText && parseInt(portText) || (url.protocol.includes('https') ? 443 : url.protocol.includes('https') ? 9000 : 443),\n\t\tuseSSL: url.protocol.includes('https'),\n\t\taccessKey: url.username,\n\t\tsecretKey: url.password,\n\t});\n\tconst root = url.pathname.split('/').filter(Boolean);\n\treturn {\n\t\t/**\n\t\t * \n\t\t * @param {string} path \n\t\t * @param {number} [expires] \n\t\t * @returns {Promise<string>}\n\t\t */\n\t\tasync urlRead(path, expires = 60 * 60 * 24) {\n\t\t\treturn await client.presignedGetObject(...tPath(root, path), expires);\n\t\t},\n\t\t/**\n\t\t * \n\t\t * @param {string} path \n\t\t * @param {number} [expires] \n\t\t * @returns {Promise<string>}\n\t\t */\n\t\tasync urlWrite(path, expires = 60 * 60 * 24) {\n\t\t\treturn await client.presignedPutObject(...tPath(root, path), expires);\n\t\t},\n\t\t/**\n\t\t * \n\t\t * @param {string} path \n\t\t * @returns {Promise<ReadableStream>}\n\t\t */\n\t\tasync read(path) {\n\t\t\t// @ts-ignore\n\t\t\treturn Readable.toWeb(await client.getObject(...tPath(root, path)));\n\t\t},\n\t\t/**\n\t\t * \n\t\t * @param {string} path \n\t\t * @param {ReadableStream | Blob | ArrayBufferView | ArrayBuffer | string | Buffer | Readable} data \n\t\t * @param {number} [size] \n\t\t * @returns \n\t\t */\n\t\tasync write(path, data, size) {\n\t\t\tif (data instanceof ReadableStream) {\n\t\t\t\t// @ts-ignore\n\t\t\t\tawait client.putObject(...tPath(root, path), Readable.fromWeb(data), size);\n\t\t\t} else if (data instanceof Blob) {\n\t\t\t\t// @ts-ignore\n\t\t\t\tawait client.putObject(...tPath(root, path), Readable.fromWeb(data.stream()), data.size);\n\t\t\t} else if (ArrayBuffer.isView(data)) {\n\t\t\t\tawait client.putObject(...tPath(root, path), Buffer.from(data.buffer, data.byteOffset, data.byteLength));\n\t\t\t} else if (data instanceof ArrayBuffer) {\n\t\t\t\tawait client.putObject(...tPath(root, path), Buffer.from(data));\n\t\t\t} else {\n\t\t\t\tawait client.putObject(...tPath(root, path), data);\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;AASA,SAAS,MAAM,MAAM,MAAM;CAC1B,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC,GAAG,MAAM,GAAG,KAAK,MA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AAK,YAAY,KAAK,WAAW,CAAC;YAC9F,gBAAgB,YAC1B,OAAM,OAAO,UAAU,GAAG,MAAM,MAAM,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC;OAE/D,OAAM,OAAO,UAAU,GAAG,MAAM,MAAM,KAAK,EAAE,KAAK;;EAGpD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yongdall/fs-minio",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "./index.mjs",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.mjs"
|
|
7
|
+
},
|
|
8
|
+
"imports": {
|
|
9
|
+
"#index": "./index.mjs"
|
|
10
|
+
},
|
|
11
|
+
"version": "0.1.0",
|
|
12
|
+
"description": "",
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"minio": "^8.0.5"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@yongdall/connection": "^0.1.0"
|
|
21
|
+
}
|
|
22
|
+
}
|