@cyberskill/shared 2.8.1 → 2.10.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/dist/node/upload/index.cjs +1 -1
- package/dist/node/upload/index.js +11 -10
- package/dist/node/upload/upload.constant.cjs +1 -1
- package/dist/node/upload/upload.constant.d.ts +22 -0
- package/dist/node/upload/upload.constant.js +30 -2
- package/dist/node/upload/upload.type.cjs +1 -1
- package/dist/node/upload/upload.type.d.ts +2 -0
- package/dist/node/upload/upload.type.js +2 -2
- package/dist/node/upload/upload.util.cjs +1 -1
- package/dist/node/upload/upload.util.js +53 -75
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./upload.constant.cjs"),a=require("./upload.type.cjs"),e=require("./upload.util.cjs");exports.BYTES_PER_MB=t.BYTES_PER_MB;Object.defineProperty(exports,"E_UploadType",{enumerable:!0,get:()=>a.E_UploadType});exports.createUploadConfig=e.createUploadConfig;exports.getAndValidateFile=e.getAndValidateFile;exports.getFileSizeFromStream=e.getFileSizeFromStream;exports.getFileWebStream=e.getFileWebStream;exports.upload=e.upload;exports.validateFileExtension=e.validateFileExtension;exports.validateUpload=e.validateUpload;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./upload.constant.cjs"),a=require("./upload.type.cjs"),e=require("./upload.util.cjs");exports.BYTES_PER_MB=t.BYTES_PER_MB;exports.DEFAULT_UPLOAD_CONFIG=t.DEFAULT_UPLOAD_CONFIG;Object.defineProperty(exports,"E_UploadType",{enumerable:!0,get:()=>a.E_UploadType});exports.createUploadConfig=e.createUploadConfig;exports.getAndValidateFile=e.getAndValidateFile;exports.getFileSizeFromStream=e.getFileSizeFromStream;exports.getFileWebStream=e.getFileWebStream;exports.upload=e.upload;exports.validateFileExtension=e.validateFileExtension;exports.validateUpload=e.validateUpload;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { BYTES_PER_MB as o } from "./upload.constant.js";
|
|
2
|
-
import { E_UploadType as
|
|
3
|
-
import { createUploadConfig as
|
|
1
|
+
import { BYTES_PER_MB as o, DEFAULT_UPLOAD_CONFIG as t } from "./upload.constant.js";
|
|
2
|
+
import { E_UploadType as i } from "./upload.type.js";
|
|
3
|
+
import { createUploadConfig as d, getAndValidateFile as p, getFileSizeFromStream as F, getFileWebStream as m, upload as E, validateFileExtension as U, validateUpload as _ } from "./upload.util.js";
|
|
4
4
|
export {
|
|
5
5
|
o as BYTES_PER_MB,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
d as
|
|
9
|
-
p as
|
|
6
|
+
t as DEFAULT_UPLOAD_CONFIG,
|
|
7
|
+
i as E_UploadType,
|
|
8
|
+
d as createUploadConfig,
|
|
9
|
+
p as getAndValidateFile,
|
|
10
|
+
F as getFileSizeFromStream,
|
|
10
11
|
m as getFileWebStream,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
E as upload,
|
|
13
|
+
U as validateFileExtension,
|
|
14
|
+
_ as validateUpload
|
|
14
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=1024*1024;exports.BYTES_PER_MB=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./upload.type.cjs"),i=1024*1024,o={[e.E_UploadType.IMAGE]:{allowedExtensions:["jpg","jpeg","png","gif","webp","svg"],sizeLimit:5*1024*1024},[e.E_UploadType.VIDEO]:{allowedExtensions:["mp4","avi","mov","wmv","flv","webm"],sizeLimit:500*1024*1024},[e.E_UploadType.AUDIO]:{allowedExtensions:["mp3","wav","ogg","m4a","aac"],sizeLimit:50*1024*1024},[e.E_UploadType.DOCUMENT]:{allowedExtensions:["pdf","doc","docx","txt","rtf"],sizeLimit:10*1024*1024},[e.E_UploadType.OTHER]:{allowedExtensions:["zip","rar","tar","gz"],sizeLimit:5*1024*1024}};exports.BYTES_PER_MB=i;exports.DEFAULT_UPLOAD_CONFIG=o;
|
|
@@ -1 +1,23 @@
|
|
|
1
1
|
export declare const BYTES_PER_MB: number;
|
|
2
|
+
export declare const DEFAULT_UPLOAD_CONFIG: {
|
|
3
|
+
IMAGE: {
|
|
4
|
+
allowedExtensions: string[];
|
|
5
|
+
sizeLimit: number;
|
|
6
|
+
};
|
|
7
|
+
VIDEO: {
|
|
8
|
+
allowedExtensions: string[];
|
|
9
|
+
sizeLimit: number;
|
|
10
|
+
};
|
|
11
|
+
AUDIO: {
|
|
12
|
+
allowedExtensions: string[];
|
|
13
|
+
sizeLimit: number;
|
|
14
|
+
};
|
|
15
|
+
DOCUMENT: {
|
|
16
|
+
allowedExtensions: string[];
|
|
17
|
+
sizeLimit: number;
|
|
18
|
+
};
|
|
19
|
+
OTHER: {
|
|
20
|
+
allowedExtensions: string[];
|
|
21
|
+
sizeLimit: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -1,4 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
import { E_UploadType as i } from "./upload.type.js";
|
|
2
|
+
const o = 1024 * 1024, s = {
|
|
3
|
+
[i.IMAGE]: {
|
|
4
|
+
allowedExtensions: ["jpg", "jpeg", "png", "gif", "webp", "svg"],
|
|
5
|
+
sizeLimit: 5 * 1024 * 1024
|
|
6
|
+
// 5MB
|
|
7
|
+
},
|
|
8
|
+
[i.VIDEO]: {
|
|
9
|
+
allowedExtensions: ["mp4", "avi", "mov", "wmv", "flv", "webm"],
|
|
10
|
+
sizeLimit: 500 * 1024 * 1024
|
|
11
|
+
// 500MB
|
|
12
|
+
},
|
|
13
|
+
[i.AUDIO]: {
|
|
14
|
+
allowedExtensions: ["mp3", "wav", "ogg", "m4a", "aac"],
|
|
15
|
+
sizeLimit: 50 * 1024 * 1024
|
|
16
|
+
// 50MB
|
|
17
|
+
},
|
|
18
|
+
[i.DOCUMENT]: {
|
|
19
|
+
allowedExtensions: ["pdf", "doc", "docx", "txt", "rtf"],
|
|
20
|
+
sizeLimit: 10 * 1024 * 1024
|
|
21
|
+
// 10MB
|
|
22
|
+
},
|
|
23
|
+
[i.OTHER]: {
|
|
24
|
+
allowedExtensions: ["zip", "rar", "tar", "gz"],
|
|
25
|
+
sizeLimit: 5 * 1024 * 1024
|
|
26
|
+
// 5MB
|
|
27
|
+
}
|
|
28
|
+
};
|
|
2
29
|
export {
|
|
3
|
-
o as BYTES_PER_MB
|
|
30
|
+
o as BYTES_PER_MB,
|
|
31
|
+
s as DEFAULT_UPLOAD_CONFIG
|
|
4
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.E_UploadType=(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.E_UploadType=(O=>(O.IMAGE="IMAGE",O.VIDEO="VIDEO",O.AUDIO="AUDIO",O.DOCUMENT="DOCUMENT",O.OTHER="OTHER",O))(exports.E_UploadType||{});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare enum E_UploadType {
|
|
2
2
|
IMAGE = "IMAGE",
|
|
3
3
|
VIDEO = "VIDEO",
|
|
4
|
+
AUDIO = "AUDIO",
|
|
4
5
|
DOCUMENT = "DOCUMENT",
|
|
5
6
|
OTHER = "OTHER"
|
|
6
7
|
}
|
|
@@ -15,6 +16,7 @@ export interface I_UploadTypeConfig {
|
|
|
15
16
|
export interface I_UploadConfig {
|
|
16
17
|
[E_UploadType.IMAGE]: I_UploadTypeConfig;
|
|
17
18
|
[E_UploadType.VIDEO]: I_UploadTypeConfig;
|
|
19
|
+
[E_UploadType.AUDIO]: I_UploadTypeConfig;
|
|
18
20
|
[E_UploadType.DOCUMENT]: I_UploadTypeConfig;
|
|
19
21
|
[E_UploadType.OTHER]: I_UploadTypeConfig;
|
|
20
22
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var D = /* @__PURE__ */ ((O) => (O.IMAGE = "IMAGE", O.VIDEO = "VIDEO", O.AUDIO = "AUDIO", O.DOCUMENT = "DOCUMENT", O.OTHER = "OTHER", O))(D || {});
|
|
2
2
|
export {
|
|
3
|
-
|
|
3
|
+
D as E_UploadType
|
|
4
4
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("node:buffer"),P=require("node:stream"),D=require("node:stream/web"),R=require("./upload.constant.cjs"),m=require("./upload.type.cjs"),F=require("../path/path.util.cjs"),p=require("../fs/fs.util.cjs"),d=require("../../constant/response-status.cjs");var h=Object.defineProperty,v=Object.getOwnPropertySymbols,z=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,O=(t,r,e)=>r in t?h(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,T=(t,r)=>{for(var e in r||(r={}))z.call(r,e)&&O(t,e,r[e]);if(v)for(var e of v(r))x.call(r,e)&&O(t,e,r[e]);return t},E=(t,r,e)=>new Promise((i,a)=>{var s=l=>{try{o(e.next(l))}catch(c){a(c)}},n=l=>{try{o(e.throw(l))}catch(c){a(c)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,n);o((e=e.apply(t,r)).next())});function w(t){return E(this,null,function*(){return new Promise((r,e)=>{let i=0;t.on("data",a=>{i+=a.length}),t.on("end",()=>r(i)),t.on("error",e)})})}function _(t,r,e){return E(this,null,function*(){const i=yield(yield r).file,a=i.createReadStream(),s=yield w(a),n=e!=null?e:y(),o=A({filename:i.filename,fileSize:s},n,t);return o.isValid?{success:!0,result:i,message:"File validated successfully"}:{success:!1,message:o.error||"File validation failed",code:d.RESPONSE_STATUS.BAD_REQUEST.CODE}})}function L(t,r,e){return E(this,null,function*(){const a=(e!=null?e:y())[t],s=yield _(t,r,e);if(!s.success)return s;const{createReadStream:n}=s.result;let o=a.sizeLimit;const l=new P.Transform({transform(u,f,g){o-=u.length,o<0?g(new Error(`File size exceeds limit of ${a.sizeLimit/R.BYTES_PER_MB}MB`)):g(null,u)}}),S=n().pipe(l);return{success:!0,result:new D.ReadableStream({start(u){S.on("data",f=>{u.enqueue(typeof f=="string"?C.Buffer.from(f):f)}),S.on("end",()=>u.close()),S.on("error",f=>u.error(f))}})}})}function U(t,r){const e=t.lastIndexOf(".");if(e===-1)return!1;const i=t.substring(e+1).toLowerCase();return r.includes(i)}function A(t,r,e){const{filename:i,fileSize:a}=t,s=r[e],{allowedExtensions:n,sizeLimit:o}=s;if(!U(i,n))return{isValid:!1,error:`File extension not allowed for ${e.toLowerCase()} files. Allowed extensions: ${n.join(", ")}`};if(a!==void 0&&a>o){const l=Math.round(o/1048576);return{isValid:!1,error:`File size exceeds limit for ${e.toLowerCase()} files. Maximum size: ${l}MB`}}return{isValid:!0}}function y(t){return T(T({},R.DEFAULT_UPLOAD_CONFIG),t)}function B(t){return E(this,null,function*(){const{path:r,file:e,config:i,type:a}=t;if(!r||typeof r!="string")return{success:!1,message:"Invalid path provided",code:d.RESPONSE_STATUS.BAD_REQUEST.CODE};if(!e||typeof e!="object")return{success:!1,message:"Invalid file provided",code:d.RESPONSE_STATUS.BAD_REQUEST.CODE};if(i){const s=[m.E_UploadType.IMAGE,m.E_UploadType.VIDEO,m.E_UploadType.DOCUMENT,m.E_UploadType.OTHER];for(const n of s){if(!i[n]||!Array.isArray(i[n].allowedExtensions)||i[n].allowedExtensions.length===0)return{success:!1,message:`Invalid config for ${n.toLowerCase()} files`,code:d.RESPONSE_STATUS.BAD_REQUEST.CODE};if(typeof i[n].sizeLimit!="number"||i[n].sizeLimit<=0)return{success:!1,message:`Invalid size limit for ${n.toLowerCase()} files`,code:d.RESPONSE_STATUS.BAD_REQUEST.CODE}}}try{const s=yield _(a,yield e,i);if(!s.success)return s;const{createReadStream:n}=s.result,o=F.dirname(r);p.pathExistsSync(o)||p.mkdirSync(o,{recursive:!0});const l=n(),c=p.createWriteStream(r);return l.pipe(c),yield new Promise((S,u)=>{c.on("finish",()=>S()),c.on("error",u),l.on("error",u)}),{success:!0,result:r,message:"File uploaded successfully",code:d.RESPONSE_STATUS.OK.CODE}}catch(s){return{success:!1,message:s instanceof Error?s.message:"File upload failed",code:d.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}})}exports.createUploadConfig=y;exports.getAndValidateFile=_;exports.getFileSizeFromStream=w;exports.getFileWebStream=L;exports.upload=B;exports.validateFileExtension=U;exports.validateUpload=A;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Buffer as
|
|
2
|
-
import { Transform as
|
|
3
|
-
import { ReadableStream as
|
|
4
|
-
import { BYTES_PER_MB as
|
|
5
|
-
import { E_UploadType as
|
|
6
|
-
import { dirname as
|
|
7
|
-
import { pathExistsSync as
|
|
8
|
-
import { RESPONSE_STATUS as
|
|
9
|
-
var
|
|
1
|
+
import { Buffer as w } from "node:buffer";
|
|
2
|
+
import { Transform as C } from "node:stream";
|
|
3
|
+
import { ReadableStream as D } from "node:stream/web";
|
|
4
|
+
import { BYTES_PER_MB as R, DEFAULT_UPLOAD_CONFIG as h } from "./upload.constant.js";
|
|
5
|
+
import { E_UploadType as p } from "./upload.type.js";
|
|
6
|
+
import { dirname as x } from "../path/path.util.js";
|
|
7
|
+
import { pathExistsSync as z, mkdirSync as A, createWriteStream as F } from "../fs/fs.util.js";
|
|
8
|
+
import { RESPONSE_STATUS as u } from "../../constant/response-status.js";
|
|
9
|
+
var P = Object.defineProperty, S = Object.getOwnPropertySymbols, T = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable, v = (t, r, e) => r in t ? P(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e, _ = (t, r) => {
|
|
10
10
|
for (var e in r || (r = {}))
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
for (var e of
|
|
14
|
-
|
|
11
|
+
T.call(r, e) && v(t, e, r[e]);
|
|
12
|
+
if (S)
|
|
13
|
+
for (var e of S(r))
|
|
14
|
+
L.call(r, e) && v(t, e, r[e]);
|
|
15
15
|
return t;
|
|
16
16
|
}, E = (t, r, e) => new Promise((i, a) => {
|
|
17
17
|
var s = (l) => {
|
|
@@ -29,7 +29,7 @@ var T = Object.defineProperty, v = Object.getOwnPropertySymbols, A = Object.prot
|
|
|
29
29
|
}, n = (l) => l.done ? i(l.value) : Promise.resolve(l.value).then(s, o);
|
|
30
30
|
n((e = e.apply(t, r)).next());
|
|
31
31
|
});
|
|
32
|
-
function
|
|
32
|
+
function B(t) {
|
|
33
33
|
return E(this, null, function* () {
|
|
34
34
|
return new Promise((r, e) => {
|
|
35
35
|
let i = 0;
|
|
@@ -39,9 +39,9 @@ function P(t) {
|
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function g(t, r, e) {
|
|
43
43
|
return E(this, null, function* () {
|
|
44
|
-
const i = yield (yield r).file, a = i.createReadStream(), s = yield
|
|
44
|
+
const i = yield (yield r).file, a = i.createReadStream(), s = yield B(a), o = e != null ? e : O(), n = U(
|
|
45
45
|
{ filename: i.filename, fileSize: s },
|
|
46
46
|
o,
|
|
47
47
|
t
|
|
@@ -53,44 +53,44 @@ function w(t, r, e) {
|
|
|
53
53
|
} : {
|
|
54
54
|
success: !1,
|
|
55
55
|
message: n.error || "File validation failed",
|
|
56
|
-
code:
|
|
56
|
+
code: u.BAD_REQUEST.CODE
|
|
57
57
|
};
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function G(t, r, e) {
|
|
61
61
|
return E(this, null, function* () {
|
|
62
|
-
const a = (e != null ? e :
|
|
62
|
+
const a = (e != null ? e : O())[t], s = yield g(t, r, e);
|
|
63
63
|
if (!s.success)
|
|
64
64
|
return s;
|
|
65
65
|
const { createReadStream: o } = s.result;
|
|
66
66
|
let n = a.sizeLimit;
|
|
67
|
-
const l = new
|
|
68
|
-
transform(f,
|
|
69
|
-
n -= f.length, n < 0 ?
|
|
67
|
+
const l = new C({
|
|
68
|
+
transform(f, d, y) {
|
|
69
|
+
n -= f.length, n < 0 ? y(new Error(`File size exceeds limit of ${a.sizeLimit / R}MB`)) : y(null, f);
|
|
70
70
|
}
|
|
71
|
-
}),
|
|
71
|
+
}), m = o().pipe(l);
|
|
72
72
|
return {
|
|
73
73
|
success: !0,
|
|
74
|
-
result: new
|
|
74
|
+
result: new D({
|
|
75
75
|
start(f) {
|
|
76
|
-
|
|
77
|
-
f.enqueue(typeof
|
|
78
|
-
}),
|
|
76
|
+
m.on("data", (d) => {
|
|
77
|
+
f.enqueue(typeof d == "string" ? w.from(d) : d);
|
|
78
|
+
}), m.on("end", () => f.close()), m.on("error", (d) => f.error(d));
|
|
79
79
|
}
|
|
80
80
|
})
|
|
81
81
|
};
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function I(t, r) {
|
|
85
85
|
const e = t.lastIndexOf(".");
|
|
86
86
|
if (e === -1)
|
|
87
87
|
return !1;
|
|
88
88
|
const i = t.substring(e + 1).toLowerCase();
|
|
89
89
|
return r.includes(i);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
91
|
+
function U(t, r, e) {
|
|
92
92
|
const { filename: i, fileSize: a } = t, s = r[e], { allowedExtensions: o, sizeLimit: n } = s;
|
|
93
|
-
if (!
|
|
93
|
+
if (!I(i, o))
|
|
94
94
|
return {
|
|
95
95
|
isValid: !1,
|
|
96
96
|
error: `File extension not allowed for ${e.toLowerCase()} files. Allowed extensions: ${o.join(", ")}`
|
|
@@ -104,93 +104,71 @@ function F(t, r, e) {
|
|
|
104
104
|
}
|
|
105
105
|
return { isValid: !0 };
|
|
106
106
|
}
|
|
107
|
-
function
|
|
108
|
-
|
|
109
|
-
[u.IMAGE]: {
|
|
110
|
-
allowedExtensions: ["jpg", "jpeg", "png", "gif", "webp", "svg"],
|
|
111
|
-
sizeLimit: 5242880
|
|
112
|
-
// 5MB
|
|
113
|
-
},
|
|
114
|
-
[u.VIDEO]: {
|
|
115
|
-
allowedExtensions: ["mp4", "avi", "mov", "wmv", "flv", "webm"],
|
|
116
|
-
sizeLimit: 524288e3
|
|
117
|
-
// 500MB
|
|
118
|
-
},
|
|
119
|
-
[u.DOCUMENT]: {
|
|
120
|
-
allowedExtensions: ["pdf", "doc", "docx", "txt", "rtf"],
|
|
121
|
-
sizeLimit: 10485760
|
|
122
|
-
// 10MB
|
|
123
|
-
},
|
|
124
|
-
[u.OTHER]: {
|
|
125
|
-
allowedExtensions: ["zip", "rar", "tar", "gz"],
|
|
126
|
-
sizeLimit: 5242880
|
|
127
|
-
// 5MB
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
return S(S({}, r), t);
|
|
107
|
+
function O(t) {
|
|
108
|
+
return _(_({}, h), t);
|
|
131
109
|
}
|
|
132
|
-
function
|
|
110
|
+
function W(t) {
|
|
133
111
|
return E(this, null, function* () {
|
|
134
112
|
const { path: r, file: e, config: i, type: a } = t;
|
|
135
113
|
if (!r || typeof r != "string")
|
|
136
114
|
return {
|
|
137
115
|
success: !1,
|
|
138
116
|
message: "Invalid path provided",
|
|
139
|
-
code:
|
|
117
|
+
code: u.BAD_REQUEST.CODE
|
|
140
118
|
};
|
|
141
119
|
if (!e || typeof e != "object")
|
|
142
120
|
return {
|
|
143
121
|
success: !1,
|
|
144
122
|
message: "Invalid file provided",
|
|
145
|
-
code:
|
|
123
|
+
code: u.BAD_REQUEST.CODE
|
|
146
124
|
};
|
|
147
125
|
if (i) {
|
|
148
|
-
const s = [
|
|
126
|
+
const s = [p.IMAGE, p.VIDEO, p.DOCUMENT, p.OTHER];
|
|
149
127
|
for (const o of s) {
|
|
150
128
|
if (!i[o] || !Array.isArray(i[o].allowedExtensions) || i[o].allowedExtensions.length === 0)
|
|
151
129
|
return {
|
|
152
130
|
success: !1,
|
|
153
131
|
message: `Invalid config for ${o.toLowerCase()} files`,
|
|
154
|
-
code:
|
|
132
|
+
code: u.BAD_REQUEST.CODE
|
|
155
133
|
};
|
|
156
134
|
if (typeof i[o].sizeLimit != "number" || i[o].sizeLimit <= 0)
|
|
157
135
|
return {
|
|
158
136
|
success: !1,
|
|
159
137
|
message: `Invalid size limit for ${o.toLowerCase()} files`,
|
|
160
|
-
code:
|
|
138
|
+
code: u.BAD_REQUEST.CODE
|
|
161
139
|
};
|
|
162
140
|
}
|
|
163
141
|
}
|
|
164
142
|
try {
|
|
165
|
-
const s = yield
|
|
143
|
+
const s = yield g(a, yield e, i);
|
|
166
144
|
if (!s.success)
|
|
167
145
|
return s;
|
|
168
|
-
const { createReadStream: o } = s.result, n =
|
|
169
|
-
|
|
170
|
-
const l = o(), c =
|
|
171
|
-
return l.pipe(c), yield new Promise((
|
|
172
|
-
c.on("finish", () =>
|
|
146
|
+
const { createReadStream: o } = s.result, n = x(r);
|
|
147
|
+
z(n) || A(n, { recursive: !0 });
|
|
148
|
+
const l = o(), c = F(r);
|
|
149
|
+
return l.pipe(c), yield new Promise((m, f) => {
|
|
150
|
+
c.on("finish", () => m()), c.on("error", f), l.on("error", f);
|
|
173
151
|
}), {
|
|
174
152
|
success: !0,
|
|
175
153
|
result: r,
|
|
176
154
|
message: "File uploaded successfully",
|
|
177
|
-
code:
|
|
155
|
+
code: u.OK.CODE
|
|
178
156
|
};
|
|
179
157
|
} catch (s) {
|
|
180
158
|
return {
|
|
181
159
|
success: !1,
|
|
182
160
|
message: s instanceof Error ? s.message : "File upload failed",
|
|
183
|
-
code:
|
|
161
|
+
code: u.INTERNAL_SERVER_ERROR.CODE
|
|
184
162
|
};
|
|
185
163
|
}
|
|
186
164
|
});
|
|
187
165
|
}
|
|
188
166
|
export {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
167
|
+
O as createUploadConfig,
|
|
168
|
+
g as getAndValidateFile,
|
|
169
|
+
B as getFileSizeFromStream,
|
|
170
|
+
G as getFileWebStream,
|
|
171
|
+
W as upload,
|
|
172
|
+
I as validateFileExtension,
|
|
173
|
+
U as validateUpload
|
|
196
174
|
};
|