@arikajs/storage 0.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.
- package/LICENSE +21 -0
- package/README.md +247 -0
- package/dist/Contracts/Filesystem.d.ts +48 -0
- package/dist/Contracts/Filesystem.d.ts.map +1 -0
- package/dist/Contracts/Filesystem.js +3 -0
- package/dist/Contracts/Filesystem.js.map +1 -0
- package/dist/Disk.d.ts +60 -0
- package/dist/Disk.d.ts.map +1 -0
- package/dist/Disk.js +119 -0
- package/dist/Disk.js.map +1 -0
- package/dist/Drivers/LocalDriver.d.ts +65 -0
- package/dist/Drivers/LocalDriver.d.ts.map +1 -0
- package/dist/Drivers/LocalDriver.js +156 -0
- package/dist/Drivers/LocalDriver.js.map +1 -0
- package/dist/Drivers/S3Driver.d.ts +67 -0
- package/dist/Drivers/S3Driver.d.ts.map +1 -0
- package/dist/Drivers/S3Driver.js +218 -0
- package/dist/Drivers/S3Driver.js.map +1 -0
- package/dist/Exceptions/FileNotFoundException.d.ts +4 -0
- package/dist/Exceptions/FileNotFoundException.d.ts.map +1 -0
- package/dist/Exceptions/FileNotFoundException.js +11 -0
- package/dist/Exceptions/FileNotFoundException.js.map +1 -0
- package/dist/StorageManager.d.ts +33 -0
- package/dist/StorageManager.d.ts.map +1 -0
- package/dist/StorageManager.js +87 -0
- package/dist/StorageManager.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/src/Contracts/Filesystem.d.ts +48 -0
- package/dist/src/Contracts/Filesystem.d.ts.map +1 -0
- package/dist/src/Contracts/Filesystem.js +3 -0
- package/dist/src/Contracts/Filesystem.js.map +1 -0
- package/dist/src/Disk.d.ts +60 -0
- package/dist/src/Disk.d.ts.map +1 -0
- package/dist/src/Disk.js +119 -0
- package/dist/src/Disk.js.map +1 -0
- package/dist/src/Drivers/LocalDriver.d.ts +65 -0
- package/dist/src/Drivers/LocalDriver.d.ts.map +1 -0
- package/dist/src/Drivers/LocalDriver.js +156 -0
- package/dist/src/Drivers/LocalDriver.js.map +1 -0
- package/dist/src/Drivers/S3Driver.d.ts +67 -0
- package/dist/src/Drivers/S3Driver.d.ts.map +1 -0
- package/dist/src/Drivers/S3Driver.js +218 -0
- package/dist/src/Drivers/S3Driver.js.map +1 -0
- package/dist/src/Exceptions/FileNotFoundException.d.ts +4 -0
- package/dist/src/Exceptions/FileNotFoundException.d.ts.map +1 -0
- package/dist/src/Exceptions/FileNotFoundException.js +11 -0
- package/dist/src/Exceptions/FileNotFoundException.js.map +1 -0
- package/dist/src/StorageManager.d.ts +33 -0
- package/dist/src/StorageManager.d.ts.map +1 -0
- package/dist/src/StorageManager.js +87 -0
- package/dist/src/StorageManager.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +37 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tests/AdvancedStorage.test.d.ts +2 -0
- package/dist/tests/AdvancedStorage.test.d.ts.map +1 -0
- package/dist/tests/AdvancedStorage.test.js +121 -0
- package/dist/tests/AdvancedStorage.test.js.map +1 -0
- package/dist/tests/Storage.test.d.ts +2 -0
- package/dist/tests/Storage.test.d.ts.map +1 -0
- package/dist/tests/Storage.test.js +121 -0
- package/dist/tests/Storage.test.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.LocalDriver = void 0;
|
|
37
|
+
const fs = __importStar(require("fs/promises"));
|
|
38
|
+
const fs_1 = require("fs");
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const promises_1 = require("stream/promises");
|
|
41
|
+
const mime = __importStar(require("mime-types"));
|
|
42
|
+
const FileNotFoundException_1 = require("../Exceptions/FileNotFoundException");
|
|
43
|
+
class LocalDriver {
|
|
44
|
+
constructor(config) {
|
|
45
|
+
this.root = path.resolve(config.root);
|
|
46
|
+
this.urlPrefix = config.url || '';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get the full path for a file.
|
|
50
|
+
*/
|
|
51
|
+
getFullPath(filePath) {
|
|
52
|
+
return path.join(this.root, filePath);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Ensure directory exists.
|
|
56
|
+
*/
|
|
57
|
+
async ensureDirectory(filePath) {
|
|
58
|
+
const dir = path.dirname(filePath);
|
|
59
|
+
await fs.mkdir(dir, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Write contents to a file.
|
|
63
|
+
*/
|
|
64
|
+
async put(filePath, contents) {
|
|
65
|
+
const fullPath = this.getFullPath(filePath);
|
|
66
|
+
await this.ensureDirectory(fullPath);
|
|
67
|
+
await fs.writeFile(fullPath, contents);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Write a stream to a file.
|
|
71
|
+
*/
|
|
72
|
+
async putStream(filePath, stream) {
|
|
73
|
+
const fullPath = this.getFullPath(filePath);
|
|
74
|
+
await this.ensureDirectory(fullPath);
|
|
75
|
+
const writeStream = (0, fs_1.createWriteStream)(fullPath);
|
|
76
|
+
await (0, promises_1.pipeline)(stream, writeStream);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Read file contents.
|
|
80
|
+
*/
|
|
81
|
+
async get(filePath) {
|
|
82
|
+
const fullPath = this.getFullPath(filePath);
|
|
83
|
+
if (!(await this.exists(filePath))) {
|
|
84
|
+
throw new FileNotFoundException_1.FileNotFoundException(filePath);
|
|
85
|
+
}
|
|
86
|
+
return await fs.readFile(fullPath);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Read file as a stream.
|
|
90
|
+
*/
|
|
91
|
+
readStream(filePath) {
|
|
92
|
+
const fullPath = this.getFullPath(filePath);
|
|
93
|
+
return (0, fs_1.createReadStream)(fullPath);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Check if a file exists.
|
|
97
|
+
*/
|
|
98
|
+
async exists(filePath) {
|
|
99
|
+
const fullPath = this.getFullPath(filePath);
|
|
100
|
+
try {
|
|
101
|
+
await fs.access(fullPath);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Delete a file.
|
|
110
|
+
*/
|
|
111
|
+
async delete(filePath) {
|
|
112
|
+
const fullPath = this.getFullPath(filePath);
|
|
113
|
+
if (await this.exists(filePath)) {
|
|
114
|
+
await fs.unlink(fullPath);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get the URL for a file.
|
|
119
|
+
*/
|
|
120
|
+
url(filePath) {
|
|
121
|
+
if (!this.urlPrefix) {
|
|
122
|
+
return filePath;
|
|
123
|
+
}
|
|
124
|
+
return `${this.urlPrefix}/${filePath}`.replace(/\/+/g, '/').replace(':/', '://');
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get a temporary URL for a file.
|
|
128
|
+
* Note: For local driver, this just returns the normal URL as local files don't support signing by default
|
|
129
|
+
* without a custom server implementation.
|
|
130
|
+
*/
|
|
131
|
+
async temporaryUrl(filePath, expiresAt) {
|
|
132
|
+
return this.url(filePath);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get the file size in bytes.
|
|
136
|
+
*/
|
|
137
|
+
async size(filePath) {
|
|
138
|
+
const stats = await fs.stat(this.getFullPath(filePath));
|
|
139
|
+
return stats.size;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get the last modified time of the file.
|
|
143
|
+
*/
|
|
144
|
+
async lastModified(filePath) {
|
|
145
|
+
const stats = await fs.stat(this.getFullPath(filePath));
|
|
146
|
+
return stats.mtimeMs;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get the mime type of the file.
|
|
150
|
+
*/
|
|
151
|
+
async mimeType(filePath) {
|
|
152
|
+
return mime.lookup(filePath) || 'application/octet-stream';
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.LocalDriver = LocalDriver;
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AAC,CAAC;QAC9B,CAAC;IACL,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,QAAgB;QACvB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAClB,OAAO,QAAQ,CAAC;QACpB,CAAC;QAED,OAAO,GAAG,IAAI,CAAC,SAAS,IAAI,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrF,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,QAAgB,EAAE,SAAe;QACvD,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAAC,QAAgB;QAC9B,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;QACxD,OAAO,KAAK,CAAC,IAAI,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,YAAY,CAAC,QAAgB;QACtC,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;QACxD,OAAO,KAAK,CAAC,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ,CAAC,QAAgB;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,0BAA0B,CAAC;IAC/D,CAAC;CACJ;AAnID,kCAmIC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Filesystem } from '../Contracts/Filesystem';
|
|
2
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
export declare class S3Driver implements Filesystem {
|
|
5
|
+
protected client: S3Client;
|
|
6
|
+
protected bucket: string;
|
|
7
|
+
protected region: string;
|
|
8
|
+
protected urlEndpoint?: string;
|
|
9
|
+
constructor(config: {
|
|
10
|
+
key: string;
|
|
11
|
+
secret: string;
|
|
12
|
+
region: string;
|
|
13
|
+
bucket: string;
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
url?: string;
|
|
16
|
+
forcePathStyle?: boolean;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Write contents to a file.
|
|
20
|
+
*/
|
|
21
|
+
put(path: string, contents: string | Buffer): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Write a stream to a file.
|
|
24
|
+
*/
|
|
25
|
+
putStream(path: string, stream: Readable): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Read file contents.
|
|
28
|
+
*/
|
|
29
|
+
get(path: string): Promise<Buffer>;
|
|
30
|
+
/**
|
|
31
|
+
* Read file as a stream.
|
|
32
|
+
*/
|
|
33
|
+
readStream(path: string): Readable;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a file exists.
|
|
36
|
+
*/
|
|
37
|
+
exists(path: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Delete a file.
|
|
40
|
+
*/
|
|
41
|
+
delete(path: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the URL for a file.
|
|
44
|
+
*/
|
|
45
|
+
url(path: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Get a temporary URL for a file.
|
|
48
|
+
*/
|
|
49
|
+
temporaryUrl(path: string, expiresAt: Date): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Get the file size in bytes.
|
|
52
|
+
*/
|
|
53
|
+
size(path: string): Promise<number>;
|
|
54
|
+
/**
|
|
55
|
+
* Get the last modified time of the file.
|
|
56
|
+
*/
|
|
57
|
+
lastModified(path: string): Promise<number>;
|
|
58
|
+
/**
|
|
59
|
+
* Get the mime type of the file.
|
|
60
|
+
*/
|
|
61
|
+
mimeType(path: string): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Helper to convert stream to buffer.
|
|
64
|
+
*/
|
|
65
|
+
private streamToBuffer;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=S3Driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"S3Driver.d.ts","sourceRoot":"","sources":["../../src/Drivers/S3Driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EACH,QAAQ,EAMX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,qBAAa,QAAS,YAAW,UAAU;IACvC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;gBAEnB,MAAM,EAAE;QAChB,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,cAAc,CAAC,EAAE,OAAO,CAAC;KAC5B;IAiBD;;OAEG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWjE;;OAEG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAa9D;;OAEG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBxC;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;IA2BlC;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiB5C;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASzC;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAOzB;;OAEG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAWlE;;OAEG;IACG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUzC;;OAEG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUjD;;OAEG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAU7C;;OAEG;YACW,cAAc;CAQ/B"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.S3Driver = void 0;
|
|
37
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
38
|
+
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
39
|
+
const mime = __importStar(require("mime-types"));
|
|
40
|
+
class S3Driver {
|
|
41
|
+
constructor(config) {
|
|
42
|
+
const s3Config = {
|
|
43
|
+
region: config.region,
|
|
44
|
+
credentials: {
|
|
45
|
+
accessKeyId: config.key,
|
|
46
|
+
secretAccessKey: config.secret,
|
|
47
|
+
},
|
|
48
|
+
endpoint: config.endpoint,
|
|
49
|
+
forcePathStyle: config.forcePathStyle,
|
|
50
|
+
};
|
|
51
|
+
this.client = new client_s3_1.S3Client(s3Config);
|
|
52
|
+
this.bucket = config.bucket;
|
|
53
|
+
this.region = config.region;
|
|
54
|
+
this.urlEndpoint = config.url;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Write contents to a file.
|
|
58
|
+
*/
|
|
59
|
+
async put(path, contents) {
|
|
60
|
+
const command = new client_s3_1.PutObjectCommand({
|
|
61
|
+
Bucket: this.bucket,
|
|
62
|
+
Key: path,
|
|
63
|
+
Body: contents,
|
|
64
|
+
ContentType: mime.lookup(path) || 'application/octet-stream'
|
|
65
|
+
});
|
|
66
|
+
await this.client.send(command);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Write a stream to a file.
|
|
70
|
+
*/
|
|
71
|
+
async putStream(path, stream) {
|
|
72
|
+
// Note: For large streams, you might want to use Upload from @aws-sdk/lib-storage
|
|
73
|
+
// but for basic implementation, this works.
|
|
74
|
+
const command = new client_s3_1.PutObjectCommand({
|
|
75
|
+
Bucket: this.bucket,
|
|
76
|
+
Key: path,
|
|
77
|
+
Body: stream,
|
|
78
|
+
ContentType: mime.lookup(path) || 'application/octet-stream'
|
|
79
|
+
});
|
|
80
|
+
await this.client.send(command);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Read file contents.
|
|
84
|
+
*/
|
|
85
|
+
async get(path) {
|
|
86
|
+
const command = new client_s3_1.GetObjectCommand({
|
|
87
|
+
Bucket: this.bucket,
|
|
88
|
+
Key: path,
|
|
89
|
+
});
|
|
90
|
+
const response = await this.client.send(command);
|
|
91
|
+
if (!response.Body) {
|
|
92
|
+
throw new Error(`File not found: ${path}`);
|
|
93
|
+
}
|
|
94
|
+
// Convert stream to buffer
|
|
95
|
+
return this.streamToBuffer(response.Body);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Read file as a stream.
|
|
99
|
+
*/
|
|
100
|
+
readStream(path) {
|
|
101
|
+
// We use a custom stream that fetches from S3 on demand
|
|
102
|
+
// Alternatively, we can use a pass-through stream but it's more complex.
|
|
103
|
+
// For simplicity, we return the S3 body which is a Readable.
|
|
104
|
+
// However, this needs to be an async call in some contexts.
|
|
105
|
+
// A better way is to provide a method that returns a Promise of a Readable.
|
|
106
|
+
// But to match the interface sync signature:
|
|
107
|
+
const { Readable } = require('stream');
|
|
108
|
+
const passThrough = new Readable({
|
|
109
|
+
read() { }
|
|
110
|
+
});
|
|
111
|
+
this.client.send(new client_s3_1.GetObjectCommand({
|
|
112
|
+
Bucket: this.bucket,
|
|
113
|
+
Key: path
|
|
114
|
+
})).then(response => {
|
|
115
|
+
if (response.Body) {
|
|
116
|
+
response.Body.pipe(passThrough);
|
|
117
|
+
}
|
|
118
|
+
}).catch(err => {
|
|
119
|
+
passThrough.emit('error', err);
|
|
120
|
+
});
|
|
121
|
+
return passThrough;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check if a file exists.
|
|
125
|
+
*/
|
|
126
|
+
async exists(path) {
|
|
127
|
+
try {
|
|
128
|
+
const command = new client_s3_1.HeadObjectCommand({
|
|
129
|
+
Bucket: this.bucket,
|
|
130
|
+
Key: path,
|
|
131
|
+
});
|
|
132
|
+
await this.client.send(command);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (error.name === 'NotFound' || error.$metadata?.httpStatusCode === 404) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Delete a file.
|
|
144
|
+
*/
|
|
145
|
+
async delete(path) {
|
|
146
|
+
const command = new client_s3_1.DeleteObjectCommand({
|
|
147
|
+
Bucket: this.bucket,
|
|
148
|
+
Key: path,
|
|
149
|
+
});
|
|
150
|
+
await this.client.send(command);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get the URL for a file.
|
|
154
|
+
*/
|
|
155
|
+
url(path) {
|
|
156
|
+
if (this.urlEndpoint) {
|
|
157
|
+
return `${this.urlEndpoint}/${path}`;
|
|
158
|
+
}
|
|
159
|
+
return `https://${this.bucket}.s3.${this.region}.amazonaws.com/${path}`;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get a temporary URL for a file.
|
|
163
|
+
*/
|
|
164
|
+
async temporaryUrl(path, expiresAt) {
|
|
165
|
+
const command = new client_s3_1.GetObjectCommand({
|
|
166
|
+
Bucket: this.bucket,
|
|
167
|
+
Key: path,
|
|
168
|
+
});
|
|
169
|
+
const expiresIn = Math.floor((expiresAt.getTime() - Date.now()) / 1000);
|
|
170
|
+
return await (0, s3_request_presigner_1.getSignedUrl)(this.client, command, { expiresIn });
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get the file size in bytes.
|
|
174
|
+
*/
|
|
175
|
+
async size(path) {
|
|
176
|
+
const command = new client_s3_1.HeadObjectCommand({
|
|
177
|
+
Bucket: this.bucket,
|
|
178
|
+
Key: path,
|
|
179
|
+
});
|
|
180
|
+
const response = await this.client.send(command);
|
|
181
|
+
return response.ContentLength || 0;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get the last modified time of the file.
|
|
185
|
+
*/
|
|
186
|
+
async lastModified(path) {
|
|
187
|
+
const command = new client_s3_1.HeadObjectCommand({
|
|
188
|
+
Bucket: this.bucket,
|
|
189
|
+
Key: path,
|
|
190
|
+
});
|
|
191
|
+
const response = await this.client.send(command);
|
|
192
|
+
return response.LastModified?.getTime() || 0;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get the mime type of the file.
|
|
196
|
+
*/
|
|
197
|
+
async mimeType(path) {
|
|
198
|
+
const command = new client_s3_1.HeadObjectCommand({
|
|
199
|
+
Bucket: this.bucket,
|
|
200
|
+
Key: path,
|
|
201
|
+
});
|
|
202
|
+
const response = await this.client.send(command);
|
|
203
|
+
return response.ContentType || mime.lookup(path) || 'application/octet-stream';
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Helper to convert stream to buffer.
|
|
207
|
+
*/
|
|
208
|
+
async streamToBuffer(stream) {
|
|
209
|
+
return new Promise((resolve, reject) => {
|
|
210
|
+
const chunks = [];
|
|
211
|
+
stream.on('data', (chunk) => chunks.push(chunk));
|
|
212
|
+
stream.on('error', reject);
|
|
213
|
+
stream.on('end', () => resolve(Buffer.concat(chunks)));
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.S3Driver = S3Dri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M,EAAE,IAAI,CAAC,MAAM;YACnB,GAAG,EAAE,IAAI;SACZ,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,0BAA0B,CAAC;IACnF,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,cAAc,CAAC,MAAgB;QACzC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,MAAM,MAAM,GAAU,EAAE,CAAC;YACzB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YACjD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC3B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAxND,4BAwNC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileNotFoundException.d.ts","sourceRoot":"","sources":["../../src/Exceptions/FileNotFoundException.ts"],"names":[],"mappings":"AAAA,qBAAa,qBAAsB,SAAQ,KAAK;gBAChC,IAAI,EAAE,MAAM;CAI3B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileNotFoundException = void 0;
|
|
4
|
+
class FileNotFoundException extends Error {
|
|
5
|
+
constructor(path) {
|
|
6
|
+
super(`File not found at path: ${path}`);
|
|
7
|
+
this.name = 'FileNotFoundException';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.FileNotFoundException = FileNotFoundException;
|
|
11
|
+
//# sourceMappingURL=FileNotFoundException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileNotFoundException.js","sourceRoot":"","sources":["../../src/Exceptions/FileNotFoundException.ts"],"names":[],"mappings":";;;AAAA,MAAa,qBAAsB,SAAQ,KAAK;IAC5C,YAAY,IAAY;QACpB,KAAK,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACxC,CAAC;CACJ;AALD,sDAKC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Disk } from './Disk';
|
|
2
|
+
export declare class StorageManager {
|
|
3
|
+
private disks;
|
|
4
|
+
private config;
|
|
5
|
+
constructor(config: any);
|
|
6
|
+
/**
|
|
7
|
+
* Get a disk instance.
|
|
8
|
+
*/
|
|
9
|
+
disk(name?: string): Disk;
|
|
10
|
+
/**
|
|
11
|
+
* Resolve a disk from configuration.
|
|
12
|
+
*/
|
|
13
|
+
private resolveDisk;
|
|
14
|
+
/**
|
|
15
|
+
* Create a driver instance based on configuration.
|
|
16
|
+
*/
|
|
17
|
+
private createDriver;
|
|
18
|
+
/**
|
|
19
|
+
* Proxy methods to the default disk.
|
|
20
|
+
*/
|
|
21
|
+
put(path: string, contents: string | Buffer): Promise<void>;
|
|
22
|
+
putStream(path: string, stream: any): Promise<void>;
|
|
23
|
+
get(path: string): Promise<Buffer>;
|
|
24
|
+
readStream(path: string): any;
|
|
25
|
+
exists(path: string): Promise<boolean>;
|
|
26
|
+
delete(path: string): Promise<void>;
|
|
27
|
+
url(path: string): string;
|
|
28
|
+
temporaryUrl(path: string, expiresAt: Date): Promise<string>;
|
|
29
|
+
size(path: string): Promise<number>;
|
|
30
|
+
lastModified(path: string): Promise<number>;
|
|
31
|
+
mimeType(path: string): Promise<string>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=StorageManager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,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StorageManager = void 0;
|
|
4
|
+
const Disk_1 = require("./Disk");
|
|
5
|
+
const LocalDriver_1 = require("./Drivers/LocalDriver");
|
|
6
|
+
const S3Driver_1 = require("./Drivers/S3Driver");
|
|
7
|
+
class StorageManager {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.disks = new Map();
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get a disk instance.
|
|
14
|
+
*/
|
|
15
|
+
disk(name) {
|
|
16
|
+
name = name || this.config.default;
|
|
17
|
+
if (!name) {
|
|
18
|
+
throw new Error('No default disk configured.');
|
|
19
|
+
}
|
|
20
|
+
if (!this.disks.has(name)) {
|
|
21
|
+
this.disks.set(name, this.resolveDisk(name));
|
|
22
|
+
}
|
|
23
|
+
return this.disks.get(name);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a disk from configuration.
|
|
27
|
+
*/
|
|
28
|
+
resolveDisk(name) {
|
|
29
|
+
const diskConfig = this.config.disks[name];
|
|
30
|
+
if (!diskConfig) {
|
|
31
|
+
throw new Error(`Disk [${name}] is not configured.`);
|
|
32
|
+
}
|
|
33
|
+
const driver = this.createDriver(diskConfig);
|
|
34
|
+
return new Disk_1.Disk(driver);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a driver instance based on configuration.
|
|
38
|
+
*/
|
|
39
|
+
createDriver(config) {
|
|
40
|
+
switch (config.driver) {
|
|
41
|
+
case 'local':
|
|
42
|
+
return new LocalDriver_1.LocalDriver(config);
|
|
43
|
+
case 's3':
|
|
44
|
+
return new S3Driver_1.S3Driver(config);
|
|
45
|
+
default:
|
|
46
|
+
throw new Error(`Driver [${config.driver}] is not supported.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Proxy methods to the default disk.
|
|
51
|
+
*/
|
|
52
|
+
async put(path, contents) {
|
|
53
|
+
return await this.disk().put(path, contents);
|
|
54
|
+
}
|
|
55
|
+
async putStream(path, stream) {
|
|
56
|
+
return await this.disk().putStream(path, stream);
|
|
57
|
+
}
|
|
58
|
+
async get(path) {
|
|
59
|
+
return await this.disk().get(path);
|
|
60
|
+
}
|
|
61
|
+
readStream(path) {
|
|
62
|
+
return this.disk().readStream(path);
|
|
63
|
+
}
|
|
64
|
+
async exists(path) {
|
|
65
|
+
return await this.disk().exists(path);
|
|
66
|
+
}
|
|
67
|
+
async delete(path) {
|
|
68
|
+
return await this.disk().delete(path);
|
|
69
|
+
}
|
|
70
|
+
url(path) {
|
|
71
|
+
return this.disk().url(path);
|
|
72
|
+
}
|
|
73
|
+
async temporaryUrl(path, expiresAt) {
|
|
74
|
+
return await this.disk().temporaryUrl(path, expiresAt);
|
|
75
|
+
}
|
|
76
|
+
async size(path) {
|
|
77
|
+
return await this.disk().size(path);
|
|
78
|
+
}
|
|
79
|
+
async lastModified(path) {
|
|
80
|
+
return await this.disk().lastModified(path);
|
|
81
|
+
}
|
|
82
|
+
async mimeType(path) {
|
|
83
|
+
return await this.disk().mimeType(path);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.StorageManager = StorageManager;
|
|
87
|
+
//# sourceMappingURL=StorageManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageManager.js","sourceRoot":"","sources":["../src/StorageManager.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAE9B,uDAAoD;AACpD,iDAA8C;AAE9C,MAAa,cAAc;IAIvB,YAAY,MAAW;QAHf,UAAK,GAAsB,IAAI,GAAG,EAAE,CAAC;QAIzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,IAAa;QACrB,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,C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,IAAI,CAAC,CAAC;IAC5C,CAAC;CACJ;AAnGD,wCAmGC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './StorageManager';
|
|
2
|
+
export * from './Disk';
|
|
3
|
+
export * from './Contracts/Filesystem';
|
|
4
|
+
export * from './Drivers/LocalDriver';
|
|
5
|
+
export * from './Drivers/S3Driver';
|
|
6
|
+
export * from './Exceptions/FileNotFoundException';
|
|
7
|
+
import { StorageManager } from './StorageManager';
|
|
8
|
+
export declare const Storage: StorageManager;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oCAAoC,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAalD,eAAO,MAAM,OAAO,gBAAoC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Storage = void 0;
|
|
18
|
+
__exportStar(require("./StorageManager"), exports);
|
|
19
|
+
__exportStar(require("./Disk"), exports);
|
|
20
|
+
__exportStar(require("./Contracts/Filesystem"), exports);
|
|
21
|
+
__exportStar(require("./Drivers/LocalDriver"), exports);
|
|
22
|
+
__exportStar(require("./Drivers/S3Driver"), exports);
|
|
23
|
+
__exportStar(require("./Exceptions/FileNotFoundException"), exports);
|
|
24
|
+
// Export a default Storage instance (will be configured by the application)
|
|
25
|
+
const StorageManager_1 = require("./StorageManager");
|
|
26
|
+
// Default configuration for standalone usage
|
|
27
|
+
const defaultConfig = {
|
|
28
|
+
default: 'local',
|
|
29
|
+
disks: {
|
|
30
|
+
local: {
|
|
31
|
+
driver: 'local',
|
|
32
|
+
root: './storage/app'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.Storage = new StorageManager_1.StorageManager(defaultConfig);
|
|
37
|
+
//# sourceMappingURL=index.js.map
|