exodus-framework 2.0.9998 → 2.0.99991
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.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FileLibrary.d.ts","sourceRoot":"","sources":["../../../src/services/file/FileLibrary.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,OAAO,MAAM,2BAA2B,CAAC;AAChD,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AAIzC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,cAAM,kBAAmB,SAAQ,OAAO;IACtC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC;IAEZ,aAAa;IAQb,OAAO;YAMN,WAAW;YA2BX,iBAAiB;
|
1
|
+
{"version":3,"file":"FileLibrary.d.ts","sourceRoot":"","sources":["../../../src/services/file/FileLibrary.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,OAAO,MAAM,2BAA2B,CAAC;AAChD,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AAIzC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,cAAM,kBAAmB,SAAQ,OAAO;IACtC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC;IAEZ,aAAa;IAQb,OAAO;YAMN,WAAW;YA2BX,iBAAiB;IAyBxB,WAAW,CAAC,GAAG,EAAE,MAAM;IAOjB,UAAU,CAAC,GAAG,EAAE,MAAM;IAO5B,aAAa,CAAC,GAAG,EAAE,MAAM;IAOnB,UAAU,CAAC,GAAG,EAAE,MAAM;IAWtB,WAAW,CAAC,GAAG,EAAE,MAAM;IAWvB,mBAAmB,CAAC,QAAQ,EAAE,MAAM;IAmCpC,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IA2B7E,cAAc,CAAC,QAAQ,EAAE,MAAM;IAW/B,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAMxC,QAAQ,CAAC,GAAG,EAAE,MAAM;CAG5B;AAED,eAAe,kBAAkB,CAAC"}
|
@@ -56,14 +56,16 @@ class FileLibraryService extends _service.default {
|
|
56
56
|
const itemPath = _path.default.join(target, item);
|
57
57
|
const stat = await _fsExtra.default.stat(itemPath);
|
58
58
|
if (stat.isDirectory()) {
|
59
|
-
this.migratePublicPath(itemPath);
|
59
|
+
await this.migratePublicPath(itemPath);
|
60
60
|
continue;
|
61
61
|
}
|
62
62
|
const md5 = await this.getMD5FromFile(itemPath);
|
63
63
|
if (md5 && !this.cache.has(md5)) {
|
64
|
+
//! este move o arquivo, não é preciso excluir o original
|
64
65
|
await this.saveAndRegisterFile(itemPath);
|
66
|
+
} else {
|
67
|
+
await _fsExtra.default.unlink(itemPath);
|
65
68
|
}
|
66
|
-
await _fsExtra.default.unlink(itemPath);
|
67
69
|
}
|
68
70
|
}
|
69
71
|
getFilePath(md5) {
|
@@ -97,16 +99,13 @@ class FileLibraryService extends _service.default {
|
|
97
99
|
|
98
100
|
/**
|
99
101
|
* Save a file to the library and register it in the cache
|
100
|
-
*
|
101
|
-
* @param {string} filePath
|
102
|
-
* @return {string} MD5 hash of the saved file
|
103
|
-
* @memberof FileLibraryService
|
102
|
+
* @return MD5 hash of the saved file
|
104
103
|
*/
|
105
104
|
async saveAndRegisterFile(filePath) {
|
106
105
|
const md5 = await this.getMD5FromFile(filePath);
|
107
106
|
if (!md5) throw new Error('Falha ao gerar o md5 do arquivo');
|
108
107
|
if (this.isCached(md5)) return;
|
109
|
-
const ext = this.mime.
|
108
|
+
const ext = this.mime.getFileExtension(filePath);
|
110
109
|
const newFilePath = _path.default.join(this.path, `${md5}.${ext}`);
|
111
110
|
const metaFilePath = _path.default.join(this.path, `${md5}.meta`);
|
112
111
|
await _fsExtra.default.move(filePath, newFilePath, {
|
@@ -130,12 +129,7 @@ class FileLibraryService extends _service.default {
|
|
130
129
|
|
131
130
|
/**
|
132
131
|
* Save a file buffer to the library and register it in the cache
|
133
|
-
*
|
134
|
-
* @param {Buffer} buffer
|
135
|
-
* @param {string} originalName
|
136
|
-
* @param {string} ext
|
137
|
-
* @return {string} MD5 hash of the saved file
|
138
|
-
* @memberof FileLibraryService
|
132
|
+
* @return MD5 hash of the saved file
|
139
133
|
*/
|
140
134
|
async saveAndRegisterBuffer(buffer, originalName, ext) {
|
141
135
|
const md5 = this.getMD5FromBuffer(buffer);
|
@@ -8,6 +8,7 @@ declare class MimeType {
|
|
8
8
|
constructor(...args: TypeMap[]);
|
9
9
|
define(typeMap: TypeMap, force?: boolean): this;
|
10
10
|
getType(path: string): string;
|
11
|
+
getFileExtension(path: string): string;
|
11
12
|
getExtension(type: string): string;
|
12
13
|
getAllExtensions(type: string): Set<string>;
|
13
14
|
_freeze(): this;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Mimetyp.d.ts","sourceRoot":"","sources":["../../../../src/services/file/classes/Mimetyp.ts"],"names":[],"mappings":"AAAA,KAAK,OAAO,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3C,cAAM,QAAQ;IACZ,eAAe,sBAA6B;IAC5C,eAAe,sBAA6B;IAC5C,gBAAgB,2BAAkC;gBAEtC,GAAG,IAAI,EAAE,OAAO,EAAE;IAMvB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,UAAQ;IA8CtC,OAAO,CAAC,IAAI,EAAE,MAAM;IAqBpB,YAAY,CAAC,IAAI,EAAE,MAAM;IAYzB,gBAAgB,CAAC,IAAI,EAAE,MAAM;IAUpC,OAAO;IAgBP,aAAa;;;;CAMd;AAED,eAAe,QAAQ,CAAC"}
|
1
|
+
{"version":3,"file":"Mimetyp.d.ts","sourceRoot":"","sources":["../../../../src/services/file/classes/Mimetyp.ts"],"names":[],"mappings":"AAAA,KAAK,OAAO,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3C,cAAM,QAAQ;IACZ,eAAe,sBAA6B;IAC5C,eAAe,sBAA6B;IAC5C,gBAAgB,2BAAkC;gBAEtC,GAAG,IAAI,EAAE,OAAO,EAAE;IAMvB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,UAAQ;IA8CtC,OAAO,CAAC,IAAI,EAAE,MAAM;IAqBpB,gBAAgB,CAAC,IAAI,EAAE,MAAM;IAe7B,YAAY,CAAC,IAAI,EAAE,MAAM;IAYzB,gBAAgB,CAAC,IAAI,EAAE,MAAM;IAUpC,OAAO;IAgBP,aAAa;;;;CAMd;AAED,eAAe,QAAQ,CAAC"}
|
@@ -68,6 +68,20 @@ class MimeType {
|
|
68
68
|
return this.extensionToType.get(ext) ?? null;
|
69
69
|
}
|
70
70
|
|
71
|
+
/**
|
72
|
+
* Get extension associated with a filepath
|
73
|
+
*/
|
74
|
+
getFileExtension(path) {
|
75
|
+
if (typeof path !== 'string') return null;
|
76
|
+
|
77
|
+
// Remove chars preceeding `/` or `\`
|
78
|
+
const last = path.replace(/^.*[/\\]/, '').toLowerCase();
|
79
|
+
|
80
|
+
// Remove chars preceeding '.'
|
81
|
+
const ext = last.replace(/^.*\./, '').toLowerCase();
|
82
|
+
return ext;
|
83
|
+
}
|
84
|
+
|
71
85
|
/**
|
72
86
|
* Get default file extension associated with a mime type
|
73
87
|
*/
|