@arkstack/filesystem 0.2.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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @arkstack/filesystem
2
+
3
+ Shared Filesystem utilities for ArkStack.
@@ -0,0 +1,237 @@
1
+ import { DriveDirectory, DriveFile } from "flydrive";
2
+ import { createReadStream, createWriteStream } from "node:fs";
3
+ import Client from "ssh2-sftp-client";
4
+ import { Readable } from "node:stream";
5
+ import path from "node:path";
6
+
7
+ //#region src/FtpDriver.ts
8
+ var FtpDriver = class FtpDriver {
9
+ config;
10
+ constructor(config) {
11
+ if (typeof config === "string") {
12
+ const url = new URL(config);
13
+ this.config = {
14
+ host: url.hostname,
15
+ username: url.username,
16
+ password: url.password,
17
+ port: url.port ? parseInt(url.port, 10) : 22,
18
+ verbose: url.searchParams.get("verbose") === "true"
19
+ };
20
+ } else this.config = config;
21
+ }
22
+ getConfig() {
23
+ return this.config;
24
+ }
25
+ async init() {
26
+ const client = new Client();
27
+ await client.connect({
28
+ host: this.config.host,
29
+ username: this.config.username,
30
+ password: this.config.password,
31
+ port: this.config.port || 22
32
+ });
33
+ return client;
34
+ }
35
+ async load(handle) {
36
+ const client = await this.init();
37
+ try {
38
+ return await handle(client);
39
+ } catch (e) {
40
+ if (this.config.verbose) throw e;
41
+ } finally {
42
+ await client.end();
43
+ }
44
+ return null;
45
+ }
46
+ /**
47
+ * Return a boolean value indicating if the file exists
48
+ * or not.
49
+ */
50
+ async exists(key) {
51
+ return !!await this.load((client) => {
52
+ return client.stat(key);
53
+ }).catch(() => {
54
+ return null;
55
+ });
56
+ }
57
+ /**
58
+ * Return the file contents as a UTF-8 string. Throw an exception
59
+ * if the file is missing.
60
+ */
61
+ async get(key) {
62
+ const stream = await this.getStream(key);
63
+ const chunks = [];
64
+ for await (const chunk of stream) chunks.push(chunk);
65
+ return Buffer.concat(chunks).toString("utf-8");
66
+ }
67
+ /**
68
+ * Return the file contents as a Readable stream. Throw an exception
69
+ * if the file is missing.
70
+ */
71
+ async getStream(key) {
72
+ const dst = createWriteStream("/tmp/" + path.basename(key));
73
+ await this.load((client) => {
74
+ return client.get(key, dst);
75
+ }).catch(() => {
76
+ return null;
77
+ });
78
+ return createReadStream("/tmp/" + path.basename(key));
79
+ }
80
+ /**
81
+ * Return the file contents as a Uint8Array. Throw an exception
82
+ * if the file is missing.
83
+ */
84
+ async getBytes(key) {
85
+ const content = await this.get(key);
86
+ return new Uint8Array(Buffer.from(content, "utf-8"));
87
+ }
88
+ /**
89
+ * Return metadata of the file. Throw an exception
90
+ * if the file is missing.
91
+ */
92
+ async getMetaData(key) {
93
+ const stat = await this.load((client) => {
94
+ return client.stat(key);
95
+ }).catch(() => {
96
+ return null;
97
+ });
98
+ if (!stat) throw new Error("E_CANNOT_READ_FILE");
99
+ return {
100
+ contentType: void 0,
101
+ contentLength: stat.size,
102
+ etag: key,
103
+ lastModified: new Date(stat.modifyTime)
104
+ };
105
+ }
106
+ /**
107
+ * Return visibility of the file. Infer visibility from the initial
108
+ * config, when the driver does not support the concept of visibility.
109
+ */
110
+ async getVisibility(key) {
111
+ return "private";
112
+ }
113
+ /**
114
+ * Return the public URL of the file. Throw an exception when the driver
115
+ * does not support generating URLs.
116
+ */
117
+ async getUrl(key) {
118
+ throw new Error("E_URL_GENERATION_UNSUPPORTED");
119
+ }
120
+ /**
121
+ * Return the signed URL to serve a private file. Throw exception
122
+ * when the driver does not support generating URLs.
123
+ */
124
+ async getSignedUrl(key, options) {
125
+ throw new Error("E_URL_GENERATION_UNSUPPORTED");
126
+ }
127
+ /**
128
+ * Return the signed/temporary URL that can be used to directly upload
129
+ * the file contents to the storage.
130
+ */
131
+ async getSignedUploadUrl(key, options) {
132
+ throw new Error("E_URL_GENERATION_UNSUPPORTED");
133
+ }
134
+ /**
135
+ * Update the visibility of the file. Result in a NOOP
136
+ * when the driver does not support the concept of
137
+ * visibility.
138
+ */
139
+ async setVisibility(key, visibility) {}
140
+ /**
141
+ * Create a new file or update an existing file. The contents
142
+ * will be a UTF-8 string or "Uint8Array".
143
+ */
144
+ async put(key, contents, options) {
145
+ if (contents instanceof Uint8Array) contents = Buffer.from(contents);
146
+ const stream = Readable.from(contents);
147
+ await this.putStream(key, stream, options);
148
+ }
149
+ /**
150
+ * Create a new file or update an existing file. The contents
151
+ * will be a Readable stream.
152
+ */
153
+ async putStream(key, contents, options) {
154
+ const dst = createWriteStream("/tmp/" + path.basename(key), { encoding: options?.contentEncoding || "utf-8" });
155
+ await new Promise((resolve, reject) => {
156
+ contents.pipe(dst);
157
+ contents.on("error", reject);
158
+ dst.on("finish", resolve);
159
+ dst.on("error", reject);
160
+ });
161
+ await this.load((client) => {
162
+ return client.put("/tmp/" + path.basename(key), key);
163
+ });
164
+ }
165
+ /**
166
+ * Copy the existing file to the destination. Make sure the new file
167
+ * has the same visibility as the existing file. It might require
168
+ * manually fetching the visibility of the "source" file.
169
+ */
170
+ async copy(source, destination, options) {
171
+ await this.load((client) => {
172
+ return client.rcopy(source, destination);
173
+ });
174
+ }
175
+ /**
176
+ * Move the existing file to the destination. Make sure the new file
177
+ * has the same visibility as the existing file. It might require
178
+ * manually fetching the visibility of the "source" file.
179
+ */
180
+ async move(source, destination, options) {
181
+ await this.load((client) => {
182
+ return client.rename(source, destination);
183
+ });
184
+ }
185
+ /**
186
+ * Delete an existing file. Do not throw an error if the
187
+ * file is already missing
188
+ */
189
+ async delete(key) {
190
+ await this.load((client) => {
191
+ return client.delete(key);
192
+ }).catch(() => {
193
+ return null;
194
+ });
195
+ }
196
+ /**
197
+ * Delete all files inside a folder. Do not throw an error
198
+ * if the folder does not exist or is empty.
199
+ */
200
+ async deleteAll(prefix) {
201
+ await this.load((client) => {
202
+ return client.rmdir(prefix, true);
203
+ }).catch(() => {
204
+ return null;
205
+ });
206
+ }
207
+ /**
208
+ * Switch bucket at runtime if supported.
209
+ */
210
+ bucket(config) {
211
+ return new FtpDriver(config);
212
+ }
213
+ /**
214
+ * List all files from a given folder or the root of the storage.
215
+ * Do not throw an error if the request folder does not exist.
216
+ */
217
+ async listAll(prefix, options) {
218
+ const data = await this.load((client) => {
219
+ return client.list(prefix);
220
+ }).catch(() => {
221
+ return null;
222
+ });
223
+ return data ? { objects: data.map((file) => {
224
+ if (file.type === "d") return new DriveDirectory(file.name);
225
+ else return new DriveFile(file.name, this, {
226
+ contentType: void 0,
227
+ contentLength: file.size,
228
+ etag: file.name,
229
+ lastModified: new Date(file.modifyTime)
230
+ });
231
+ }) } : { objects: [] };
232
+ }
233
+ };
234
+
235
+ //#endregion
236
+ export { FtpDriver as t };
237
+ //# sourceMappingURL=FtpDriver-CfUSZ1xr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FtpDriver-CfUSZ1xr.js","names":[],"sources":["../src/FtpDriver.ts"],"sourcesContent":["import { DriveDirectory, DriveFile } from 'flydrive'\nimport type {\n DriverContract,\n ObjectMetaData,\n ObjectVisibility,\n SignedURLOptions,\n WriteOptions,\n} from 'flydrive/types'\nimport { createReadStream, createWriteStream } from 'node:fs'\n\nimport Client from 'ssh2-sftp-client'\nimport { Readable } from 'node:stream'\nimport path from 'node:path'\n\nexport class FtpDriver implements DriverContract {\n private config: {\n host: string\n username: string\n password: string\n port?: number\n verbose?: boolean\n privateKey?: string\n }\n\n constructor(config: string | {\n host: string\n username: string\n password: string\n port?: number\n verbose?: boolean\n privateKey?: string\n }) {\n if (typeof config === 'string') {\n const url = new URL(config)\n\n this.config = {\n host: url.hostname,\n username: url.username,\n password: url.password,\n port: url.port ? parseInt(url.port, 10) : 22,\n verbose: url.searchParams.get('verbose') === 'true',\n }\n } else {\n this.config = config\n }\n }\n\n getConfig () {\n return this.config\n }\n\n private async init () {\n const client = new Client()\n\n await client.connect({\n host: this.config.host,\n username: this.config.username,\n password: this.config.password,\n port: this.config.port || 22,\n })\n\n return client\n }\n\n private async load<T> (handle: (client: Client) => Promise<T>): Promise<T> {\n const client = await this.init()\n\n try {\n return await handle(client)\n } catch (e) {\n if (this.config.verbose) {\n throw e\n }\n } finally {\n await client.end()\n }\n\n return null as any\n }\n\n /**\n * Return a boolean value indicating if the file exists\n * or not.\n */\n async exists (key: string): Promise<boolean> {\n const client = await this.load((client) => {\n return client.stat(key)\n }).catch(() => {\n return null\n })\n\n return !!client\n }\n\n /**\n * Return the file contents as a UTF-8 string. Throw an exception\n * if the file is missing.\n */\n async get (key: string): Promise<string> {\n const stream = await this.getStream(key)\n\n const chunks: Uint8Array[] = []\n for await (const chunk of stream) {\n chunks.push(chunk)\n }\n\n return Buffer.concat(chunks).toString('utf-8')\n }\n\n /**\n * Return the file contents as a Readable stream. Throw an exception\n * if the file is missing.\n */\n async getStream (key: string): Promise<Readable> {\n const dst = createWriteStream('/tmp/' + path.basename(key))\n await this.load((client) => {\n return client.get(key, dst)\n }).catch(() => {\n return null\n })\n\n return createReadStream('/tmp/' + path.basename(key))\n }\n\n /**\n * Return the file contents as a Uint8Array. Throw an exception\n * if the file is missing.\n */\n async getBytes (key: string): Promise<Uint8Array> {\n const content = await this.get(key)\n\n return new Uint8Array(Buffer.from(content, 'utf-8'))\n }\n\n /**\n * Return metadata of the file. Throw an exception\n * if the file is missing.\n */\n async getMetaData (key: string): Promise<ObjectMetaData> {\n const stat = await this.load((client) => {\n return client.stat(key)\n }).catch(() => {\n return null\n })\n\n if (!stat) {\n throw new Error('E_CANNOT_READ_FILE')\n }\n\n return {\n contentType: undefined,\n contentLength: stat.size,\n etag: key,\n lastModified: new Date(stat.modifyTime),\n }\n }\n\n /**\n * Return visibility of the file. Infer visibility from the initial\n * config, when the driver does not support the concept of visibility.\n */\n async getVisibility (key: string): Promise<ObjectVisibility> {\n void key\n\n return 'private'\n }\n\n /**\n * Return the public URL of the file. Throw an exception when the driver\n * does not support generating URLs.\n */\n async getUrl (key: string): Promise<string> {\n void key\n throw new Error('E_URL_GENERATION_UNSUPPORTED')\n }\n\n /**\n * Return the signed URL to serve a private file. Throw exception\n * when the driver does not support generating URLs.\n */\n async getSignedUrl (key: string, options?: SignedURLOptions): Promise<string> {\n void key\n void options\n throw new Error('E_URL_GENERATION_UNSUPPORTED')\n }\n /**\n * Return the signed/temporary URL that can be used to directly upload\n * the file contents to the storage.\n */\n async getSignedUploadUrl (key: string, options?: SignedURLOptions): Promise<string> {\n void key\n void options\n throw new Error('E_URL_GENERATION_UNSUPPORTED')\n }\n\n /**\n * Update the visibility of the file. Result in a NOOP\n * when the driver does not support the concept of\n * visibility.\n */\n async setVisibility (key: string, visibility: ObjectVisibility): Promise<void> {\n void key\n void visibility\n }\n\n /**\n * Create a new file or update an existing file. The contents\n * will be a UTF-8 string or \"Uint8Array\".\n */\n async put (key: string, contents: string | Uint8Array, options?: WriteOptions): Promise<void> {\n if (contents instanceof Uint8Array) {\n contents = Buffer.from(contents)\n }\n\n const stream = Readable.from(contents)\n\n await this.putStream(key, stream, options)\n }\n\n /**\n * Create a new file or update an existing file. The contents\n * will be a Readable stream.\n */\n async putStream (key: string, contents: Readable, options?: WriteOptions): Promise<void> {\n const dst = createWriteStream('/tmp/' + path.basename(key), {\n encoding: options?.contentEncoding as never || 'utf-8',\n })\n\n await new Promise((resolve, reject) => {\n contents.pipe(dst)\n contents.on('error', reject)\n dst.on('finish', resolve)\n dst.on('error', reject)\n })\n\n await this.load((client) => {\n return client.put('/tmp/' + path.basename(key), key)\n })\n }\n\n /**\n * Copy the existing file to the destination. Make sure the new file\n * has the same visibility as the existing file. It might require\n * manually fetching the visibility of the \"source\" file.\n */\n async copy (source: string, destination: string, options?: WriteOptions): Promise<void> {\n void options\n await this.load((client) => {\n return client.rcopy(source, destination)\n })\n }\n\n /**\n * Move the existing file to the destination. Make sure the new file\n * has the same visibility as the existing file. It might require\n * manually fetching the visibility of the \"source\" file.\n */\n async move (source: string, destination: string, options?: WriteOptions): Promise<void> {\n void options\n await this.load((client) => {\n return client.rename(source, destination)\n })\n }\n\n /**\n * Delete an existing file. Do not throw an error if the\n * file is already missing\n */\n async delete (key: string): Promise<void> {\n await this.load((client) => {\n return client.delete(key)\n }).catch(() => {\n return null\n })\n }\n\n /**\n * Delete all files inside a folder. Do not throw an error\n * if the folder does not exist or is empty.\n */\n async deleteAll (prefix: string): Promise<void> {\n await this.load((client) => {\n return client.rmdir(prefix, true)\n }).catch(() => {\n return null\n })\n }\n\n\n /**\n * Switch bucket at runtime if supported.\n */\n bucket (config: string | {\n host: string\n username: string\n password: string\n port?: number\n verbose?: boolean\n privateKey?: string\n }): DriverContract {\n return new FtpDriver(config)\n }\n\n /**\n * List all files from a given folder or the root of the storage.\n * Do not throw an error if the request folder does not exist.\n */\n async listAll (\n prefix: string,\n options?: {\n recursive?: boolean\n paginationToken?: string\n }\n ): Promise<{\n paginationToken?: string\n objects: Iterable<DriveFile | DriveDirectory>\n }> {\n void options\n\n const data = await this.load((client) => {\n return client.list(prefix)\n }).catch(() => {\n return null\n })\n\n return data ? {\n objects: data.map((file) => {\n if (file.type === 'd') {\n return new DriveDirectory(file.name)\n } else {\n return new DriveFile(file.name, this, {\n contentType: undefined,\n contentLength: file.size,\n etag: file.name,\n lastModified: new Date(file.modifyTime),\n })\n }\n })\n } : { objects: [] }\n }\n\n}\n"],"mappings":";;;;;;;AAcA,IAAa,YAAb,MAAa,UAAoC;CAC7C,AAAQ;CASR,YAAY,QAOT;AACC,MAAI,OAAO,WAAW,UAAU;GAC5B,MAAM,MAAM,IAAI,IAAI,OAAO;AAE3B,QAAK,SAAS;IACV,MAAM,IAAI;IACV,UAAU,IAAI;IACd,UAAU,IAAI;IACd,MAAM,IAAI,OAAO,SAAS,IAAI,MAAM,GAAG,GAAG;IAC1C,SAAS,IAAI,aAAa,IAAI,UAAU,KAAK;IAChD;QAED,MAAK,SAAS;;CAItB,YAAa;AACT,SAAO,KAAK;;CAGhB,MAAc,OAAQ;EAClB,MAAM,SAAS,IAAI,QAAQ;AAE3B,QAAM,OAAO,QAAQ;GACjB,MAAM,KAAK,OAAO;GAClB,UAAU,KAAK,OAAO;GACtB,UA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OAAO,IAAI;IAC3B,CAAC,YAAY;AACX,UAAO;IACT;;;;;;CAON,MAAM,UAAW,QAA+B;AAC5C,QAAM,KAAK,MAAM,WAAW;AACxB,UAAO,OAAO,MAAM,QAAQ,KAAK;IACnC,CAAC,YAAY;AACX,UAAO;IACT;;;;;CAON,OAAQ,QAOW;AACf,SAAO,IAAI,UAAU,OAAO;;;;;;CAOhC,MAAM,QACF,QACA,SAOD;EAGC,MAAM,OAAO,MAAM,KAAK,MAAM,WAAW;AACrC,UAAO,OAAO,KAAK,OAAO;IAC5B,CAAC,YAAY;AACX,UAAO;IACT;AAEF,SAAO,OAAO,EACV,SAAS,KAAK,KAAK,SAAS;AACxB,OAAI,KAAK,SAAS,IACd,QAAO,IAAI,eAAe,KAAK,KAAK;OAEpC,QAAO,IAAI,UAAU,KAAK,MAAM,MAAM;IAClC,aAAa;IACb,eAAe,KAAK;IACpB,MAAM,KAAK;IACX,cAAc,IAAI,KAAK,KAAK,WAAW;IAC1C,CAAC;IAER,EACL,GAAG,EAAE,SAAS,EAAE,EAAE"}
@@ -0,0 +1,11 @@
1
+ import { Command } from "@h3ravel/musket";
2
+
3
+ //#region src/commands/StorageLinkCommand.d.ts
4
+ declare class StorageLinkCommand extends Command {
5
+ protected signature: string;
6
+ protected description: string;
7
+ handle(): Promise<void>;
8
+ }
9
+ //#endregion
10
+ export { StorageLinkCommand };
11
+ //# sourceMappingURL=StorageLinkCommand.d.ts.map
@@ -0,0 +1,18 @@
1
+ import "../FtpDriver-CfUSZ1xr.js";
2
+ import { Storage } from "../index.js";
3
+ import { Command } from "@h3ravel/musket";
4
+
5
+ //#region src/commands/StorageLinkCommand.ts
6
+ var StorageLinkCommand = class extends Command {
7
+ signature = `storage:link
8
+ {--force : Remove existing links before creating new ones.}
9
+ `;
10
+ description = "Create symbolic links for filesystem.links configuration.";
11
+ async handle() {
12
+ Storage.link(this.options());
13
+ }
14
+ };
15
+
16
+ //#endregion
17
+ export { StorageLinkCommand };
18
+ //# sourceMappingURL=StorageLinkCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageLinkCommand.js","names":[],"sources":["../../src/commands/StorageLinkCommand.ts"],"sourcesContent":["import { Command } from '@h3ravel/musket'\nimport { Storage } from '../'\n\nexport class StorageLinkCommand extends Command {\n protected signature = `storage:link\n {--force : Remove existing links before creating new ones.}\n `\n protected description = 'Create symbolic links for filesystem.links configuration.'\n\n async handle () {\n Storage.link(this.options())\n }\n}"],"mappings":";;;;;AAGA,IAAa,qBAAb,cAAwC,QAAQ;CAC5C,AAAU,YAAY;;;CAGtB,AAAU,cAAc;CAExB,MAAM,SAAU;AACZ,UAAQ,KAAK,KAAK,SAAS,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { DriveDirectory, DriveFile, DriveManager } from "flydrive";
2
+ import { Readable } from "node:stream";
3
+ import { DriverContract, ObjectMetaData, ObjectVisibility, SignedURLOptions, WriteOptions } from "flydrive/types";
4
+
5
+ //#region src/index.d.ts
6
+ interface FileLike {
7
+ originalname: string;
8
+ buffer: Buffer;
9
+ mimetype: string;
10
+ }
11
+ declare class Storage implements DriverContract {
12
+ driver: DriveManager<any>;
13
+ services: Record<string, () => DriverContract>;
14
+ constructor();
15
+ static disk<K extends string>(diskName?: K): Storage;
16
+ static generateName: (file: {
17
+ name?: string;
18
+ originalname?: string;
19
+ }) => string;
20
+ static saveFile: (file: FileLike, filePath?: string, fileName?: string) => Promise<[string, string]>;
21
+ saveFile: (file: FileLike, filePath?: string, fileName?: string) => Promise<[string, string]>;
22
+ exists(key: string): Promise<boolean>;
23
+ get(key: string): Promise<string>;
24
+ getStream(key: string): Promise<Readable>;
25
+ getBytes(key: string): Promise<Uint8Array>;
26
+ getMetaData(key: string): Promise<ObjectMetaData>;
27
+ getVisibility(key: string): Promise<ObjectVisibility>;
28
+ getUrl(key: string): Promise<string>;
29
+ getSignedUrl(key: string, options?: SignedURLOptions): Promise<string>;
30
+ getSignedUploadUrl(key: string, options?: SignedURLOptions): Promise<string>;
31
+ setVisibility(key: string, visibility: ObjectVisibility): Promise<void>;
32
+ put(key: string, contents: string | Uint8Array | FileLike, options?: WriteOptions): Promise<void>;
33
+ putStream(key: string, contents: Readable, options?: WriteOptions): Promise<void>;
34
+ copy(source: string, destination: string, options?: WriteOptions): Promise<void>;
35
+ move(source: string, destination: string, options?: WriteOptions): Promise<void>;
36
+ delete(key: string): Promise<void>;
37
+ deleteAll(prefix: string): Promise<void>;
38
+ listAll(prefix: string, options?: {
39
+ recursive?: boolean;
40
+ paginationToken?: string;
41
+ }): Promise<{
42
+ paginationToken?: string;
43
+ objects: Iterable<DriveFile | DriveDirectory>;
44
+ }>;
45
+ bucket(bucket: string): DriverContract;
46
+ static link({
47
+ force
48
+ }?: {
49
+ force?: boolean;
50
+ }): void;
51
+ private driversMap;
52
+ }
53
+ //#endregion
54
+ export { Storage };
55
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,273 @@
1
+ import { t as FtpDriver } from "./FtpDriver-CfUSZ1xr.js";
2
+ import { DriveManager } from "flydrive";
3
+ import { appUrl, config } from "@arkstack/common";
4
+ import { existsSync, rmSync, symlinkSync } from "node:fs";
5
+ import { FSDriver } from "flydrive/drivers/fs";
6
+ import path from "node:path";
7
+ import { Logger } from "@h3ravel/shared";
8
+ import { S3Driver } from "flydrive/drivers/s3";
9
+
10
+ //#region src/index.ts
11
+ var Storage = class Storage {
12
+ driver;
13
+ services = {};
14
+ constructor() {
15
+ for (const diskName in config("filesystem.disks")) {
16
+ const diskConfig = config("filesystem.disks")[diskName];
17
+ const driverFactory = this.driversMap[diskConfig.driver];
18
+ if (!driverFactory) throw new Error(`Unsupported driver: ${diskConfig.driver}`);
19
+ this.services[diskName] = () => driverFactory(diskConfig);
20
+ }
21
+ this.driver = new DriveManager({
22
+ default: config("filesystem.default"),
23
+ services: this.services
24
+ });
25
+ }
26
+ /**
27
+ * Static method to get a disk instance directly from the Storage class without needing to instantiate it first.
28
+ *
29
+ * @param diskName The name of the disk to use. If not provided, the default disk will be used.
30
+ * @returns A Storage instance
31
+ */
32
+ static disk(diskName) {
33
+ const storage = new Storage();
34
+ if (diskName) storage.driver = new DriveManager({
35
+ default: diskName,
36
+ services: storage.services
37
+ });
38
+ return storage;
39
+ }
40
+ /**
41
+ * Generate a unique name for the file based on random numbers and original extension
42
+ *
43
+ * @param file The file object containing the original name
44
+ * @returns A unique file name
45
+ */
46
+ static generateName = (file) => {
47
+ const name = file.originalname || file.name || "file";
48
+ if (typeof config("filesystem.fileNameGenerator") === "function") return config("filesystem.fileNameGenerator")(name);
49
+ return Math.floor(Math.random() * 999999999999).toString() + "_" + Math.floor(Math.random() * 999999999999) + "." + name.split(".").pop();
50
+ };
51
+ /**
52
+ * Save the file to the storage and return the public URL and the file path
53
+ *
54
+ * @param file The file object containing the file data
55
+ * @param filePath The path where the file should be saved
56
+ * @param fileName The name to save the file as (optional)
57
+ * @returns A tuple containing the public URL and the file path
58
+ */
59
+ static saveFile = async (file, filePath = "", fileName) => {
60
+ return new Storage().saveFile(file, filePath, fileName);
61
+ };
62
+ /**
63
+ * Save the file to the storage and return the public URL and the file path
64
+ *
65
+ * @param file The file object containing the file data
66
+ * @param filePath The path where the file should be saved
67
+ * @param fileName The name to save the file as (optional)
68
+ * @returns A tuple containing the public URL and the file path
69
+ */
70
+ saveFile = async (file, filePath = "", fileName) => {
71
+ const name = fileName || Storage.generateName(file);
72
+ const drive = this.driver.use();
73
+ if (file instanceof File && !file.buffer) file.buffer = Buffer.from(await file.arrayBuffer());
74
+ await drive.put(path.join(filePath, name), file.buffer);
75
+ return [await drive.getUrl(path.join(filePath, name)), path.join(filePath, name)];
76
+ };
77
+ /**
78
+ * Return a boolean indicating if the file exists
79
+ */
80
+ exists(key) {
81
+ return this.driver.use().exists(key);
82
+ }
83
+ /**
84
+ * Return contents of a object for the given key as a UTF-8 string.
85
+ * Should throw "E_CANNOT_READ_FILE" error when the file
86
+ * does not exists.
87
+ */
88
+ get(key) {
89
+ return this.driver.use().get(key);
90
+ }
91
+ /**
92
+ * Return contents of a object for the given key as a Readable stream.
93
+ * Should throw "E_CANNOT_READ_FILE" error when the file
94
+ * does not exists.
95
+ */
96
+ getStream(key) {
97
+ return this.driver.use().getStream(key);
98
+ }
99
+ /**
100
+ * Return contents of an object for the given key as an Uint8Array.
101
+ * Should throw "E_CANNOT_READ_FILE" error when the file
102
+ * does not exists.
103
+ */
104
+ getBytes(key) {
105
+ return this.driver.use().getBytes(key);
106
+ }
107
+ /**
108
+ * Return metadata of an object for the given key.
109
+ */
110
+ getMetaData(key) {
111
+ return this.driver.use().getMetaData(key);
112
+ }
113
+ /**
114
+ * Return the visibility of the file
115
+ */
116
+ getVisibility(key) {
117
+ return this.driver.use().getVisibility(key);
118
+ }
119
+ /**
120
+ * Return the public URL to access the file
121
+ */
122
+ getUrl(key) {
123
+ return this.driver.use().getUrl(key);
124
+ }
125
+ /**
126
+ * Return the signed/temporary URL to access the file
127
+ */
128
+ getSignedUrl(key, options) {
129
+ return this.driver.use().getSignedUrl(key, options);
130
+ }
131
+ /**
132
+ * Return the signed/temporary URL that can be used to directly upload
133
+ * the file contents to the storage.
134
+ */
135
+ getSignedUploadUrl(key, options) {
136
+ return this.driver.use().getSignedUploadUrl(key, options);
137
+ }
138
+ /**
139
+ * Update the visibility of the file
140
+ */
141
+ setVisibility(key, visibility) {
142
+ return this.driver.use().setVisibility(key, visibility);
143
+ }
144
+ /**
145
+ * Write object to the destination with the provided
146
+ * contents.
147
+ */
148
+ put(key, contents, options) {
149
+ if (!(contents instanceof Uint8Array) && typeof contents !== "string") contents = contents.buffer;
150
+ return this.driver.use().put(key, contents, options);
151
+ }
152
+ /**
153
+ * Write object to the destination with the provided
154
+ * contents as a readable stream
155
+ */
156
+ putStream(key, contents, options) {
157
+ return this.driver.use().putStream(key, contents, options);
158
+ }
159
+ /**
160
+ * Copy the file from within the disk root location. Both
161
+ * the "source" and "destination" will be the key names
162
+ * and not absolute paths.
163
+ */
164
+ copy(source, destination, options) {
165
+ return this.driver.use().copy(source, destination, options);
166
+ }
167
+ /**
168
+ * Move the file from within the disk root location. Both
169
+ * the "source" and "destination" will be the key names
170
+ * and not absolute paths.
171
+ */
172
+ move(source, destination, options) {
173
+ return this.driver.use().move(source, destination, options);
174
+ }
175
+ /**
176
+ * Delete the file for the given key. Should not throw
177
+ * error when file does not exist in first place
178
+ */
179
+ delete(key) {
180
+ return this.driver.use().delete(key);
181
+ }
182
+ /**
183
+ * Delete the files and directories matching the provided prefix.
184
+ */
185
+ deleteAll(prefix) {
186
+ return this.driver.use().deleteAll(prefix);
187
+ }
188
+ /**
189
+ * The list all method must return an array of objects with
190
+ * the ability to paginate results (if supported).
191
+ */
192
+ listAll(prefix, options) {
193
+ return this.driver.use().listAll(prefix, options);
194
+ }
195
+ /**
196
+ * Switch bucket at runtime if supported.
197
+ */
198
+ bucket(bucket) {
199
+ return this.driver.use().bucket(bucket);
200
+ }
201
+ /**
202
+ * Create symbolic links for all configured links in the application configuration.
203
+ */
204
+ static link({ force = false } = {}) {
205
+ for (const link in config("filesystem.links")) {
206
+ const target = config("filesystem.links")[link];
207
+ const unlink = link.replace(process.cwd(), "");
208
+ const untarget = target.replace(process.cwd(), "");
209
+ try {
210
+ if (force && existsSync(link)) rmSync(link, { recursive: true });
211
+ symlinkSync(target, link);
212
+ Logger.log([
213
+ [" SUCCESS ", "bgGreen"],
214
+ [`[${unlink}]`, "green"],
215
+ ["is now linked to", "white"],
216
+ [`[${untarget}].`, "green"]
217
+ ], " ");
218
+ } catch (error) {
219
+ if (error.code === "EEXIST") Logger.log([
220
+ [" INFO ", "bgBlue"],
221
+ [`[${unlink}]`, "green"],
222
+ ["is already linked to", "white"],
223
+ [`[${untarget}].`, "green"]
224
+ ], " ");
225
+ else Logger.log([
226
+ [" ERROR ", "bgRed"],
227
+ ["Failed to create symbolic link from", "white"],
228
+ [`[${unlink}]`, "green"],
229
+ ["to", "white"],
230
+ [`[${untarget}]`, "green"],
231
+ [error.message, "red"]
232
+ ], " ");
233
+ }
234
+ }
235
+ }
236
+ driversMap = {
237
+ local: (conf) => new FSDriver({
238
+ location: new URL(conf.root, import.meta.url),
239
+ visibility: "public",
240
+ urlBuilder: {
241
+ async generateURL(key, _path) {
242
+ return appUrl(key);
243
+ },
244
+ async generateSignedURL(key, _path, _opts) {
245
+ return appUrl(key);
246
+ }
247
+ }
248
+ }),
249
+ s3: (conf) => new S3Driver({
250
+ credentials: {
251
+ accessKeyId: conf.key,
252
+ secretAccessKey: conf.secret
253
+ },
254
+ endpoint: conf.endpoint,
255
+ region: conf.region,
256
+ bucket: conf.bucket,
257
+ visibility: "private",
258
+ cdnUrl: conf.url
259
+ }),
260
+ ftp: (conf) => new FtpDriver({
261
+ host: conf.host,
262
+ username: conf.username,
263
+ password: conf.password,
264
+ port: conf.port,
265
+ verbose: conf.verbose,
266
+ privateKey: conf.privateKey
267
+ })
268
+ };
269
+ };
270
+
271
+ //#endregion
272
+ export { Storage };
273
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { DriveDirectory, DriveFile, DriveManager } from 'flydrive'\nimport { DriverContract, ObjectMetaData, ObjectVisibility, SignedURLOptions, WriteOptions } from 'flydrive/types'\nimport { appUrl, config } from '@arkstack/common'\nimport { existsSync, rmSync, symlinkSync } from 'node:fs'\n\nimport { FSDriver } from 'flydrive/drivers/fs'\nimport { FtpDriver } from './FtpDriver'\nimport { Logger } from '@h3ravel/shared'\nimport { Readable } from 'node:stream'\nimport { S3Driver } from 'flydrive/drivers/s3'\nimport path from 'node:path'\n\ninterface FileLike {\n originalname: string\n buffer: Buffer\n mimetype: string\n}\n\nexport class Storage implements DriverContract {\n driver: DriveManager<any>\n services: Record<string, () => DriverContract> = {}\n\n constructor() {\n for (const diskName in config('filesystem.disks')) {\n const diskConfig = config('filesystem.disks')[diskName]\n const driverFactory = this.driversMap[diskConfig.driver]\n\n if (!driverFactory) {\n throw new Error(`Unsupported driver: ${diskConfig.driver}`)\n }\n\n this.services[diskName] = () => driverFactory(diskConfig)\n }\n\n this.driver = new DriveManager({\n default: config('filesystem.default'),\n services: this.services\n })\n }\n\n /**\n * Static method to get a disk instance directly from the Storage class without needing to instantiate it first.\n * \n * @param diskName The name of the disk to use. If not provided, the default disk will be used.\n * @returns A Storage instance\n */\n static disk<K extends string> (diskName?: K): Storage {\n const storage = new Storage()\n\n if (diskName) {\n storage.driver = new DriveManager({\n default: diskName,\n services: storage.services\n })\n }\n\n return storage\n }\n\n /**\n * Generate a unique name for the file based on random numbers and original extension\n * \n * @param file The file object containing the original name\n * @returns A unique file name\n */\n static generateName = (file: { name?: string; originalname?: string }): string => {\n const name = file.originalname || file.name || 'file'\n\n if (typeof config('filesystem.fileNameGenerator') === 'function') {\n return config('filesystem.fileNameGenerator')(name)\n }\n\n return Math.floor(Math.random() * 999999999999).toString() +\n '_' + Math.floor(Math.random() * 999999999999) +\n '.' + (name).split('.').pop()\n }\n\n /**\n * Save the file to the storage and return the public URL and the file path\n * \n * @param file The file object containing the file data\n * @param filePath The path where the file should be saved\n * @param fileName The name to save the file as (optional)\n * @returns A tuple containing the public URL and the file path\n */\n static saveFile = async (\n file: FileLike,\n filePath: string = '',\n fileName?: string\n ): Promise<[string, string]> => {\n return new Storage().saveFile(file, filePath, fileName)\n }\n\n /**\n * Save the file to the storage and return the public URL and the file path\n * \n * @param file The file object containing the file data\n * @param filePath The path where the file should be saved\n * @param fileName The name to save the file as (optional)\n * @returns A tuple containing the public URL and the file path\n */\n saveFile = async (\n file: FileLike,\n filePath: string = '',\n fileName?: string\n ): Promise<[string, string]> => {\n const name = fileName || Storage.generateName(file)\n const drive = this.driver.use()\n\n if (file instanceof File && !file.buffer) {\n file.buffer = Buffer.from(await file.arrayBuffer())\n }\n\n await drive.put(path.join(filePath, name), file.buffer)\n\n return [await drive.getUrl(path.join(filePath, name)), path.join(filePath, name)]\n }\n\n /**\n * Return a boolean indicating if the file exists\n */\n exists (key: string): Promise<boolean> {\n return this.driver.use().exists(key)\n }\n /**\n * Return contents of a object for the given key as a UTF-8 string.\n * Should throw \"E_CANNOT_READ_FILE\" error when the file\n * does not exists.\n */\n get (key: string): Promise<string> {\n return this.driver.use().get(key)\n }\n /**\n * Return contents of a object for the given key as a Readable stream.\n * Should throw \"E_CANNOT_READ_FILE\" error when the file\n * does not exists.\n */\n getStream (key: string): Promise<Readable> {\n return this.driver.use().getStream(key)\n }\n /**\n * Return contents of an object for the given key as an Uint8Array.\n * Should throw \"E_CANNOT_READ_FILE\" error when the file\n * does not exists.\n */\n getBytes (key: string): Promise<Uint8Array> {\n return this.driver.use().getBytes(key)\n }\n /**\n * Return metadata of an object for the given key.\n */\n getMetaData (key: string): Promise<ObjectMetaData> {\n return this.driver.use().getMetaData(key)\n }\n /**\n * Return the visibility of the file\n */\n getVisibility (key: string): Promise<ObjectVisibility> {\n return this.driver.use().getVisibility(key)\n }\n /**\n * Return the public URL to access the file\n */\n getUrl (key: string): Promise<string> {\n return this.driver.use().getUrl(key)\n }\n /**\n * Return the signed/temporary URL to access the file\n */\n getSignedUrl (key: string, options?: SignedURLOptions): Promise<string> {\n return this.driver.use().getSignedUrl(key, options)\n }\n /**\n * Return the signed/temporary URL that can be used to directly upload\n * the file contents to the storage.\n */\n getSignedUploadUrl (key: string, options?: SignedURLOptions): Promise<string> {\n return this.driver.use().getSignedUploadUrl(key, options)\n }\n /**\n * Update the visibility of the file\n */\n setVisibility (key: string, visibility: ObjectVisibility): Promise<void> {\n return this.driver.use().setVisibility(key, visibility)\n }\n /**\n * Write object to the destination with the provided\n * contents.\n */\n put (key: string, contents: string | Uint8Array | FileLike, options?: WriteOptions): Promise<void> {\n if (!(contents instanceof Uint8Array) && typeof contents !== 'string') {\n contents = contents.buffer\n }\n\n return this.driver.use().put(key, contents, options)\n }\n /**\n * Write object to the destination with the provided\n * contents as a readable stream\n */\n putStream (key: string, contents: Readable, options?: WriteOptions): Promise<void> {\n return this.driver.use().putStream(key, contents, options)\n }\n /**\n * Copy the file from within the disk root location. Both\n * the \"source\" and \"destination\" will be the key names\n * and not absolute paths.\n */\n copy (source: string, destination: string, options?: WriteOptions): Promise<void> {\n return this.driver.use().copy(source, destination, options)\n }\n /**\n * Move the file from within the disk root location. Both\n * the \"source\" and \"destination\" will be the key names\n * and not absolute paths.\n */\n move (source: string, destination: string, options?: WriteOptions): Promise<void> {\n return this.driver.use().move(source, destination, options)\n }\n /**\n * Delete the file for the given key. Should not throw\n * error when file does not exist in first place\n */\n delete (key: string): Promise<void> {\n return this.driver.use().delete(key)\n }\n /**\n * Delete the files and directories matching the provided prefix.\n */\n deleteAll (prefix: string): Promise<void> {\n return this.driver.use().deleteAll(prefix)\n }\n /**\n * The list all method must return an array of objects with\n * the ability to paginate results (if supported).\n */\n listAll (prefix: string, options?: {\n recursive?: boolean;\n paginationToken?: string;\n }): Promise<{\n paginationToken?: string;\n objects: Iterable<DriveFile | DriveDirectory>;\n }> {\n return this.driver.use().listAll(prefix, options)\n }\n /**\n * Switch bucket at runtime if supported.\n */\n bucket (bucket: string): DriverContract {\n return (this.driver.use() as any).bucket(bucket)\n }\n\n /**\n * Create symbolic links for all configured links in the application configuration.\n */\n static link ({ force = false }: { force?: boolean } = {}): void {\n for (const link in config('filesystem.links')) {\n const target = config('filesystem.links')[link]\n\n const unlink = link.replace(process.cwd(), '')\n const untarget = target.replace(process.cwd(), '')\n\n try {\n if (force && existsSync(link)) rmSync(link, { recursive: true })\n symlinkSync(target, link)\n\n Logger.log([\n [' SUCCESS ', 'bgGreen'],\n [`[${unlink}]`, 'green'],\n ['is now linked to', 'white'],\n [`[${untarget}].`, 'green']\n ], ' ')\n } catch (error: any) {\n if (error.code === 'EEXIST') {\n Logger.log([\n [' INFO ', 'bgBlue'],\n [`[${unlink}]`, 'green'],\n ['is already linked to', 'white'],\n [`[${untarget}].`, 'green']\n ], ' ')\n } else {\n Logger.log([\n [' ERROR ', 'bgRed'],\n ['Failed to create symbolic link from', 'white'],\n [`[${unlink}]`, 'green'],\n ['to', 'white'],\n [`[${untarget}]`, 'green'],\n [error.message, 'red']\n ], ' ')\n }\n }\n }\n }\n\n private driversMap: Record<string, (conf: Record<string, any>) => DriverContract> = {\n local: (conf: Record<string, any>) => new FSDriver({\n location: new URL(conf.root, import.meta.url),\n visibility: 'public',\n urlBuilder: {\n async generateURL (key: string, _path: string) {\n return appUrl(key)\n },\n\n async generateSignedURL (key: string, _path: string, _opts: SignedURLOptions) {\n return appUrl(key)\n },\n },\n }),\n s3: (conf: Record<string, any>) => new S3Driver({\n credentials: {\n accessKeyId: conf.key,\n secretAccessKey: conf.secret,\n },\n endpoint: conf.endpoint,\n region: conf.region,\n bucket: conf.bucket,\n visibility: 'private',\n cdnUrl: conf.url,\n }),\n ftp: (conf: Record<string, any>) => new FtpDriver({\n host: conf.host,\n username: conf.username,\n password: conf.password,\n port: conf.port,\n verbose: conf.verbose,\n privateKey: conf.privateKey,\n }),\n }\n}"],"mappings":";;;;;;;;;;AAkBA,IAAa,UAAb,MAAa,QAAkC;CAC3C;CACA,WAAiD,EAAE;CAEnD,cAAc;AACV,OAAK,MAAM,YAAY,OAAO,mBAAmB,EAAE;GAC/C,MAAM,aAAa,OAAO,mBAAmB,CAAC;GAC9C,MAAM,gBAAgB,KAAK,WAAW,WAAW;AAEjD,OAAI,CAAC,cACD,OAAM,IAAI,MAAM,uBAAuB,WAAW,SAAS;AAG/D,QAAK,SAAS,kBAAkB,cAAc,WAAW;;AAG7D,OAAK,SAAS,IAAI,aAAa;GAC3B,SAAS,OAAO,qBAAqB;GACrC,UAAU,KAAK;GAClB,CAAC;;;;;;;;CASN,OAAO,KAAwB,UAAuB;EAClD,MAAM,UAAU,IAAI,SAAS;AAE7B,MAAI,SACA,SAAQ,SAAS,IAAI,aAAa;GAC9B,SAAS;GACT,UAAU,QAAQ;GACrB,CAAC;AAGN,SAAO;;;;;;;;CASX,OAAO,gBAAgB,SAA2D;EAC9E,MAAM,OAA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AAK;GACf,QAAQ,KAAK;GACb,QAAQ,KAAK;GACb,YAAY;GACZ,QAAQ,KAAK;GAChB,CAAC;EACF,MAAM,SAA8B,IAAI,UAAU;GAC9C,MAAM,KAAK;GACX,UAAU,KAAK;GACf,UAAU,KAAK;GACf,MAAM,KAAK;GACX,SAAS,KAAK;GACd,YAAY,KAAK;GACpB,CAAC;EACL"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@arkstack/filesystem",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "Shared Filesystem utilities for ArkStack.",
6
+ "homepage": "https://arkstack.toneflix.net",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/arkstack-hq/arkstack.git",
10
+ "directory": "packages/filesystem"
11
+ },
12
+ "keywords": [
13
+ "filesystem",
14
+ "storage",
15
+ "utilities",
16
+ "interface",
17
+ "runtime",
18
+ "application",
19
+ "framework",
20
+ "flydrive"
21
+ ],
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "exports": {
29
+ ".": "./dist/index.js",
30
+ "./commands/StorageLinkCommand": "./dist/commands/StorageLinkCommand.js",
31
+ "./package.json": "./package.json"
32
+ },
33
+ "peerDependencies": {
34
+ "@h3ravel/musket": "^0.10.1"
35
+ },
36
+ "dependencies": {
37
+ "@h3ravel/shared": "^0.27.13",
38
+ "@aws-sdk/client-s3": "^3.1011.0",
39
+ "@aws-sdk/s3-request-presigner": "^3.1011.0",
40
+ "flydrive": "^2.0.0",
41
+ "ssh2-sftp-client": "^12.1.0",
42
+ "@arkstack/common": "^0.2.0",
43
+ "@arkstack/contract": "^0.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/ssh2-sftp-client": "^9.0.6"
47
+ },
48
+ "scripts": {
49
+ "build": "tsdown",
50
+ "test": "vitest",
51
+ "version:patch": "pnpm version patch"
52
+ }
53
+ }