@cyberskill/shared 2.9.0 → 2.11.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/mongo/mongo.util.cjs +4 -4
- package/dist/node/mongo/mongo.util.d.ts +5 -1
- package/dist/node/mongo/mongo.util.js +207 -211
- 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.util.cjs +1 -1
- package/dist/node/upload/upload.util.js +71 -98
- 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"});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,50 +1,50 @@
|
|
|
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
|
|
10
|
-
for (var e in
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
for (var e of
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
}, E = (
|
|
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
|
+
for (var e in r || (r = {}))
|
|
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
|
+
return t;
|
|
16
|
+
}, E = (t, r, e) => new Promise((i, a) => {
|
|
17
17
|
var s = (l) => {
|
|
18
18
|
try {
|
|
19
19
|
n(e.next(l));
|
|
20
|
-
} catch (
|
|
21
|
-
a(
|
|
20
|
+
} catch (c) {
|
|
21
|
+
a(c);
|
|
22
22
|
}
|
|
23
23
|
}, o = (l) => {
|
|
24
24
|
try {
|
|
25
25
|
n(e.throw(l));
|
|
26
|
-
} catch (
|
|
27
|
-
a(
|
|
26
|
+
} catch (c) {
|
|
27
|
+
a(c);
|
|
28
28
|
}
|
|
29
29
|
}, n = (l) => l.done ? i(l.value) : Promise.resolve(l.value).then(s, o);
|
|
30
|
-
n((e = e.apply(
|
|
30
|
+
n((e = e.apply(t, r)).next());
|
|
31
31
|
});
|
|
32
|
-
function
|
|
32
|
+
function B(t) {
|
|
33
33
|
return E(this, null, function* () {
|
|
34
|
-
return new Promise((
|
|
34
|
+
return new Promise((r, e) => {
|
|
35
35
|
let i = 0;
|
|
36
|
-
|
|
36
|
+
t.on("data", (a) => {
|
|
37
37
|
i += a.length;
|
|
38
|
-
}),
|
|
38
|
+
}), t.on("end", () => r(i)), t.on("error", e);
|
|
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
|
|
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
|
|
48
48
|
);
|
|
49
49
|
return n.isValid ? {
|
|
50
50
|
success: !0,
|
|
@@ -53,44 +53,44 @@ function S(r, t, 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 : O())[
|
|
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
|
|
85
|
-
const e =
|
|
84
|
+
function I(t, r) {
|
|
85
|
+
const e = t.lastIndexOf(".");
|
|
86
86
|
if (e === -1)
|
|
87
87
|
return !1;
|
|
88
|
-
const i =
|
|
89
|
-
return
|
|
88
|
+
const i = t.substring(e + 1).toLowerCase();
|
|
89
|
+
return r.includes(i);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
const { filename: i, fileSize: a } =
|
|
93
|
-
if (!
|
|
91
|
+
function U(t, r, e) {
|
|
92
|
+
const { filename: i, fileSize: a } = t, s = r[e], { allowedExtensions: o, sizeLimit: n } = s;
|
|
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,98 +104,71 @@ function F(r, t, e) {
|
|
|
104
104
|
}
|
|
105
105
|
return { isValid: !0 };
|
|
106
106
|
}
|
|
107
|
-
function O(
|
|
108
|
-
|
|
109
|
-
[c.IMAGE]: {
|
|
110
|
-
allowedExtensions: ["jpg", "jpeg", "png", "gif", "webp", "svg"],
|
|
111
|
-
sizeLimit: 5242880
|
|
112
|
-
// 5MB
|
|
113
|
-
},
|
|
114
|
-
[c.VIDEO]: {
|
|
115
|
-
allowedExtensions: ["mp4", "avi", "mov", "wmv", "flv", "webm"],
|
|
116
|
-
sizeLimit: 524288e3
|
|
117
|
-
// 500MB
|
|
118
|
-
},
|
|
119
|
-
[c.AUDIO]: {
|
|
120
|
-
allowedExtensions: ["mp3", "wav", "ogg", "m4a", "aac"],
|
|
121
|
-
sizeLimit: 52428800
|
|
122
|
-
// 50MB
|
|
123
|
-
},
|
|
124
|
-
[c.DOCUMENT]: {
|
|
125
|
-
allowedExtensions: ["pdf", "doc", "docx", "txt", "rtf"],
|
|
126
|
-
sizeLimit: 10485760
|
|
127
|
-
// 10MB
|
|
128
|
-
},
|
|
129
|
-
[c.OTHER]: {
|
|
130
|
-
allowedExtensions: ["zip", "rar", "tar", "gz"],
|
|
131
|
-
sizeLimit: 5242880
|
|
132
|
-
// 5MB
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
return y(y({}, t), r);
|
|
107
|
+
function O(t) {
|
|
108
|
+
return _(_({}, h), t);
|
|
136
109
|
}
|
|
137
|
-
function
|
|
110
|
+
function W(t) {
|
|
138
111
|
return E(this, null, function* () {
|
|
139
|
-
const { path:
|
|
140
|
-
if (!
|
|
112
|
+
const { path: r, file: e, config: i, type: a } = t;
|
|
113
|
+
if (!r || typeof r != "string")
|
|
141
114
|
return {
|
|
142
115
|
success: !1,
|
|
143
116
|
message: "Invalid path provided",
|
|
144
|
-
code:
|
|
117
|
+
code: u.BAD_REQUEST.CODE
|
|
145
118
|
};
|
|
146
119
|
if (!e || typeof e != "object")
|
|
147
120
|
return {
|
|
148
121
|
success: !1,
|
|
149
122
|
message: "Invalid file provided",
|
|
150
|
-
code:
|
|
123
|
+
code: u.BAD_REQUEST.CODE
|
|
151
124
|
};
|
|
152
125
|
if (i) {
|
|
153
|
-
const s = [
|
|
126
|
+
const s = [p.IMAGE, p.VIDEO, p.DOCUMENT, p.OTHER];
|
|
154
127
|
for (const o of s) {
|
|
155
128
|
if (!i[o] || !Array.isArray(i[o].allowedExtensions) || i[o].allowedExtensions.length === 0)
|
|
156
129
|
return {
|
|
157
130
|
success: !1,
|
|
158
131
|
message: `Invalid config for ${o.toLowerCase()} files`,
|
|
159
|
-
code:
|
|
132
|
+
code: u.BAD_REQUEST.CODE
|
|
160
133
|
};
|
|
161
134
|
if (typeof i[o].sizeLimit != "number" || i[o].sizeLimit <= 0)
|
|
162
135
|
return {
|
|
163
136
|
success: !1,
|
|
164
137
|
message: `Invalid size limit for ${o.toLowerCase()} files`,
|
|
165
|
-
code:
|
|
138
|
+
code: u.BAD_REQUEST.CODE
|
|
166
139
|
};
|
|
167
140
|
}
|
|
168
141
|
}
|
|
169
142
|
try {
|
|
170
|
-
const s = yield
|
|
143
|
+
const s = yield g(a, yield e, i);
|
|
171
144
|
if (!s.success)
|
|
172
145
|
return s;
|
|
173
|
-
const { createReadStream: o } = s.result, n =
|
|
174
|
-
|
|
175
|
-
const l = o(),
|
|
176
|
-
return l.pipe(
|
|
177
|
-
|
|
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);
|
|
178
151
|
}), {
|
|
179
152
|
success: !0,
|
|
180
|
-
result:
|
|
153
|
+
result: r,
|
|
181
154
|
message: "File uploaded successfully",
|
|
182
|
-
code:
|
|
155
|
+
code: u.OK.CODE
|
|
183
156
|
};
|
|
184
157
|
} catch (s) {
|
|
185
158
|
return {
|
|
186
159
|
success: !1,
|
|
187
160
|
message: s instanceof Error ? s.message : "File upload failed",
|
|
188
|
-
code:
|
|
161
|
+
code: u.INTERNAL_SERVER_ERROR.CODE
|
|
189
162
|
};
|
|
190
163
|
}
|
|
191
164
|
});
|
|
192
165
|
}
|
|
193
166
|
export {
|
|
194
167
|
O as createUploadConfig,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
168
|
+
g as getAndValidateFile,
|
|
169
|
+
B as getFileSizeFromStream,
|
|
170
|
+
G as getFileWebStream,
|
|
171
|
+
W as upload,
|
|
172
|
+
I as validateFileExtension,
|
|
173
|
+
U as validateUpload
|
|
201
174
|
};
|