@e-mc/file-manager 0.9.0 → 0.9.2
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 +10 -10
- package/README.md +11 -27
- package/index.d.ts +5 -5
- package/index.js +20 -19
- package/package.json +10 -10
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
11
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @e-mc/file-manager
|
|
2
2
|
|
|
3
|
-
* NodeJS
|
|
3
|
+
* NodeJS 16
|
|
4
4
|
* ES2020
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.2/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { DataSource, IncrementalMatch, TaskAction } from "./squared";
|
|
@@ -284,33 +284,17 @@ await instance.start();
|
|
|
284
284
|
|
|
285
285
|
NOTE: **FileManager** is a sub-class of [Host](https://www.npmjs.com/package/@e-mc/core) and [Module](https://www.npmjs.com/package/@e-mc/module). Their ``loadSettings`` will be called as well which uses a combined [Settings](https://e-mc.readthedocs.io/en/latest/references.html#references-e-mc-types-lib-node) object.
|
|
286
286
|
|
|
287
|
-
## NodeJS 14 LTS
|
|
288
|
-
|
|
289
|
-
Any optional fail safe dependencies were removed as of `E-mc 0.9`. The code itself will still be *ES2020* and will continue to work equivalently when self-installing these dependencies:
|
|
290
|
-
|
|
291
|
-
### Under 15.4 + 16.0
|
|
292
|
-
|
|
293
|
-
```sh
|
|
294
|
-
npm i abort-controller event-target-shim
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### Under 14.17 + 15.6
|
|
298
|
-
|
|
299
|
-
```sh
|
|
300
|
-
npm i uuid
|
|
301
|
-
```
|
|
302
|
-
|
|
303
287
|
## References
|
|
304
288
|
|
|
305
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
306
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
307
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
308
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
309
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
310
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
311
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
312
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
313
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
289
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/squared.d.ts
|
|
290
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/asset.d.ts
|
|
291
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/core.d.ts
|
|
292
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/filemanager.d.ts
|
|
293
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/logger.d.ts
|
|
294
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/module.d.ts
|
|
295
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/node.d.ts
|
|
296
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/request.d.ts
|
|
297
|
+
- https://www.unpkg.com/@e-mc/types@0.9.2/lib/settings.d.ts
|
|
314
298
|
|
|
315
299
|
* https://www.npmjs.com/package/@types/node
|
|
316
300
|
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { FileManagerConstructor } from '../types/lib';
|
|
2
|
-
import type { ExternalAsset } from '../types/lib/asset';
|
|
3
|
-
|
|
4
|
-
declare const FileManager: FileManagerConstructor<ExternalAsset>;
|
|
5
|
-
|
|
1
|
+
import type { FileManagerConstructor } from '../types/lib';
|
|
2
|
+
import type { ExternalAsset } from '../types/lib/asset';
|
|
3
|
+
|
|
4
|
+
declare const FileManager: FileManagerConstructor<ExternalAsset>;
|
|
5
|
+
|
|
6
6
|
export = FileManager;
|
package/index.js
CHANGED
|
@@ -135,7 +135,8 @@ function resetAssets() {
|
|
|
135
135
|
}
|
|
136
136
|
function recurseDir(output, subDirs, options) {
|
|
137
137
|
const { ignore, sortBy, recursive } = options;
|
|
138
|
-
const
|
|
138
|
+
const baseDir = path.join(...subDirs);
|
|
139
|
+
const items = fs.readdirSync(baseDir, { withFileTypes: true })
|
|
139
140
|
.filter(item => item.name)
|
|
140
141
|
.sort((a, b) => {
|
|
141
142
|
if (sortBy > 0) {
|
|
@@ -150,7 +151,7 @@ function recurseDir(output, subDirs, options) {
|
|
|
150
151
|
});
|
|
151
152
|
for (const item of items) {
|
|
152
153
|
if (!item.isDirectory()) {
|
|
153
|
-
const pathname = path.join(
|
|
154
|
+
const pathname = path.join(baseDir, item.name);
|
|
154
155
|
if (!ignore.includes(pathname)) {
|
|
155
156
|
output.push(pathname);
|
|
156
157
|
}
|
|
@@ -2904,8 +2905,8 @@ class FileManager extends core_1.Host {
|
|
|
2904
2905
|
data[attr] = undefined;
|
|
2905
2906
|
}
|
|
2906
2907
|
};
|
|
2907
|
-
const errorRequest = (file, err, preceding) => {
|
|
2908
|
-
const
|
|
2908
|
+
const errorRequest = (file, localUri, err, preceding) => {
|
|
2909
|
+
const uri = file.uri;
|
|
2909
2910
|
clearQueue(processing, localUri);
|
|
2910
2911
|
clearQueue(downloading, uri);
|
|
2911
2912
|
clearQueue(appending, localUri);
|
|
@@ -3190,7 +3191,7 @@ class FileManager extends core_1.Host {
|
|
|
3190
3191
|
downloading[uri] = [];
|
|
3191
3192
|
}
|
|
3192
3193
|
const url = item.url;
|
|
3193
|
-
let
|
|
3194
|
+
let mainEtag = false, encoding = item.encoding, client = null, cacheDir, cacheBuffer;
|
|
3194
3195
|
if (type === 1) {
|
|
3195
3196
|
cacheDir = cacheToDisk.has(url) && isCacheable(item);
|
|
3196
3197
|
cacheBuffer = cacheToMemory.has(url);
|
|
@@ -3238,7 +3239,7 @@ class FileManager extends core_1.Host {
|
|
|
3238
3239
|
});
|
|
3239
3240
|
}
|
|
3240
3241
|
}, (err) => {
|
|
3241
|
-
errorRequest(item, err);
|
|
3242
|
+
errorRequest(item, localUri, err);
|
|
3242
3243
|
}, 1);
|
|
3243
3244
|
};
|
|
3244
3245
|
this.performAsyncTask();
|
|
@@ -3253,7 +3254,7 @@ class FileManager extends core_1.Host {
|
|
|
3253
3254
|
const statusCode = res.statusCode;
|
|
3254
3255
|
if (statusCode < 300) {
|
|
3255
3256
|
const etag = applyHeaders(item, res.headers, false, mainEtag);
|
|
3256
|
-
let
|
|
3257
|
+
let etagDir = '', tempDir;
|
|
3257
3258
|
if (etag) {
|
|
3258
3259
|
if (cacheDir || mainEtag) {
|
|
3259
3260
|
tempDir = this.getCacheDir(href);
|
|
@@ -3370,44 +3371,44 @@ class FileManager extends core_1.Host {
|
|
|
3370
3371
|
catch {
|
|
3371
3372
|
}
|
|
3372
3373
|
}
|
|
3373
|
-
errorRequest(item, (0, types_1.errorMessage)(statusCode, 'Exceeded redirect limit', url.toString()));
|
|
3374
|
+
errorRequest(item, localUri, (0, types_1.errorMessage)(statusCode, 'Exceeded redirect limit', url.toString()));
|
|
3374
3375
|
}
|
|
3375
3376
|
else {
|
|
3376
|
-
downloadUri(target);
|
|
3377
|
+
downloadUri(target, null);
|
|
3377
3378
|
}
|
|
3378
3379
|
})
|
|
3379
3380
|
.on('error', err => {
|
|
3380
3381
|
if (!client.destroyed) {
|
|
3381
3382
|
if ((0, util_1.checkRetryable)(err)) {
|
|
3382
|
-
downloadUri(target);
|
|
3383
|
+
downloadUri(target, null);
|
|
3383
3384
|
}
|
|
3384
3385
|
else {
|
|
3385
|
-
errorRequest(item, err);
|
|
3386
|
+
errorRequest(item, localUri, err);
|
|
3386
3387
|
}
|
|
3387
3388
|
}
|
|
3388
3389
|
})
|
|
3389
3390
|
.on('timeout', () => {
|
|
3390
3391
|
if (!client.destroyed) {
|
|
3391
|
-
downloadUri(target);
|
|
3392
|
+
downloadUri(target, null);
|
|
3392
3393
|
}
|
|
3393
3394
|
});
|
|
3394
3395
|
}
|
|
3395
3396
|
catch {
|
|
3396
|
-
downloadUri(request.opts(href));
|
|
3397
|
+
downloadUri(request.opts(href), null);
|
|
3397
3398
|
}
|
|
3398
3399
|
}).bind(this)(url);
|
|
3399
3400
|
}
|
|
3400
3401
|
else {
|
|
3401
|
-
downloadUri(this.Request.opts(url));
|
|
3402
|
+
downloadUri(this.Request.opts(url), null);
|
|
3402
3403
|
}
|
|
3403
3404
|
}
|
|
3404
3405
|
}
|
|
3405
3406
|
}
|
|
3406
3407
|
else if (type) {
|
|
3407
3408
|
if (bundleMain && !item.mimeType) {
|
|
3408
|
-
errorRequest(item, (0, types_1.errorValue)("MIME not found", uri), true);
|
|
3409
|
+
errorRequest(item, localUri, (0, types_1.errorValue)("MIME not found", uri), true);
|
|
3409
3410
|
}
|
|
3410
|
-
else if (!checkQueue(item, localUri, pathname
|
|
3411
|
+
else if (!checkQueue(item, localUri, pathname)) {
|
|
3411
3412
|
if (downloading[uri]) {
|
|
3412
3413
|
downloading[uri].push(item);
|
|
3413
3414
|
continue;
|
|
@@ -3416,7 +3417,7 @@ class FileManager extends core_1.Host {
|
|
|
3416
3417
|
this.performAsyncTask();
|
|
3417
3418
|
this.scheduleTask(item.url || uri, { pathname, binOpts: item.binOpts }, (result) => {
|
|
3418
3419
|
if (result.length === 0) {
|
|
3419
|
-
errorRequest(item, (0, types_1.errorValue)("No files were successfully downloaded", uri));
|
|
3420
|
+
errorRequest(item, localUri, (0, types_1.errorValue)("No files were successfully downloaded", uri));
|
|
3420
3421
|
}
|
|
3421
3422
|
else if (bundleMain) {
|
|
3422
3423
|
const encoding = item.encoding || (item.encoding = 'utf-8');
|
|
@@ -3426,7 +3427,7 @@ class FileManager extends core_1.Host {
|
|
|
3426
3427
|
processQueue(item, localUri);
|
|
3427
3428
|
}
|
|
3428
3429
|
else {
|
|
3429
|
-
errorRequest(item, err);
|
|
3430
|
+
errorRequest(item, localUri, err);
|
|
3430
3431
|
}
|
|
3431
3432
|
});
|
|
3432
3433
|
}
|
|
@@ -3463,7 +3464,7 @@ class FileManager extends core_1.Host {
|
|
|
3463
3464
|
}
|
|
3464
3465
|
}
|
|
3465
3466
|
}, (err) => {
|
|
3466
|
-
errorRequest(item, err);
|
|
3467
|
+
errorRequest(item, localUri, err);
|
|
3467
3468
|
}, 4);
|
|
3468
3469
|
}
|
|
3469
3470
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/file-manager",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "FileManager constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"license": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "0.9.
|
|
24
|
-
"@e-mc/compress": "0.9.
|
|
25
|
-
"@e-mc/core": "0.9.
|
|
26
|
-
"@e-mc/document": "0.9.
|
|
27
|
-
"@e-mc/image": "0.9.
|
|
28
|
-
"@e-mc/request": "0.9.
|
|
29
|
-
"@e-mc/task": "0.9.
|
|
30
|
-
"@e-mc/types": "0.9.
|
|
31
|
-
"@e-mc/watch": "0.9.
|
|
23
|
+
"@e-mc/cloud": "0.9.2",
|
|
24
|
+
"@e-mc/compress": "0.9.2",
|
|
25
|
+
"@e-mc/core": "0.9.2",
|
|
26
|
+
"@e-mc/document": "0.9.2",
|
|
27
|
+
"@e-mc/image": "0.9.2",
|
|
28
|
+
"@e-mc/request": "0.9.2",
|
|
29
|
+
"@e-mc/task": "0.9.2",
|
|
30
|
+
"@e-mc/types": "0.9.2",
|
|
31
|
+
"@e-mc/watch": "0.9.2",
|
|
32
32
|
"chalk": "4.1.2",
|
|
33
33
|
"picomatch": "^4.0.2"
|
|
34
34
|
}
|