@cyberskill/shared 2.9.0 → 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.
@@ -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 l } from "./upload.type.js";
3
- import { createUploadConfig as r, getAndValidateFile as d, getFileSizeFromStream as p, getFileWebStream as m, upload as F, validateFileExtension as f, validateUpload as g } from "./upload.util.js";
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
- l as E_UploadType,
7
- r as createUploadConfig,
8
- d as getAndValidateFile,
9
- p as getFileSizeFromStream,
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
- F as upload,
12
- f as validateFileExtension,
13
- g as validateUpload
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=e;
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
- const o = 1048576;
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 z=require("node:buffer"),x=require("node:stream"),C=require("node:stream/web"),A=require("./upload.constant.cjs"),d=require("./upload.type.cjs"),D=require("../path/path.util.cjs"),S=require("../fs/fs.util.cjs"),f=require("../../constant/response-status.cjs");var P=Object.defineProperty,v=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable,T=(i,t,e)=>t in i?P(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,w=(i,t)=>{for(var e in t||(t={}))h.call(t,e)&&T(i,e,t[e]);if(v)for(var e of v(t))F.call(t,e)&&T(i,e,t[e]);return i},m=(i,t,e)=>new Promise((r,a)=>{var s=l=>{try{n(e.next(l))}catch(c){a(c)}},o=l=>{try{n(e.throw(l))}catch(c){a(c)}},n=l=>l.done?r(l.value):Promise.resolve(l.value).then(s,o);n((e=e.apply(i,t)).next())});function O(i){return m(this,null,function*(){return new Promise((t,e)=>{let r=0;i.on("data",a=>{r+=a.length}),i.on("end",()=>t(r)),i.on("error",e)})})}function _(i,t,e){return m(this,null,function*(){const r=yield(yield t).file,a=r.createReadStream(),s=yield O(a),o=e!=null?e:y(),n=R({filename:r.filename,fileSize:s},o,i);return n.isValid?{success:!0,result:r,message:"File validated successfully"}:{success:!1,message:n.error||"File validation failed",code:f.RESPONSE_STATUS.BAD_REQUEST.CODE}})}function L(i,t,e){return m(this,null,function*(){const a=(e!=null?e:y())[i],s=yield _(i,t,e);if(!s.success)return s;const{createReadStream:o}=s.result;let n=a.sizeLimit;const l=new x.Transform({transform(u,p,g){n-=u.length,n<0?g(new Error(`File size exceeds limit of ${a.sizeLimit/A.BYTES_PER_MB}MB`)):g(null,u)}}),E=o().pipe(l);return{success:!0,result:new C.ReadableStream({start(u){E.on("data",p=>{u.enqueue(typeof p=="string"?z.Buffer.from(p):p)}),E.on("end",()=>u.close()),E.on("error",p=>u.error(p))}})}})}function U(i,t){const e=i.lastIndexOf(".");if(e===-1)return!1;const r=i.substring(e+1).toLowerCase();return t.includes(r)}function R(i,t,e){const{filename:r,fileSize:a}=i,s=t[e],{allowedExtensions:o,sizeLimit:n}=s;if(!U(r,o))return{isValid:!1,error:`File extension not allowed for ${e.toLowerCase()} files. Allowed extensions: ${o.join(", ")}`};if(a!==void 0&&a>n){const l=Math.round(n/1048576);return{isValid:!1,error:`File size exceeds limit for ${e.toLowerCase()} files. Maximum size: ${l}MB`}}return{isValid:!0}}function y(i){const t={[d.E_UploadType.IMAGE]:{allowedExtensions:["jpg","jpeg","png","gif","webp","svg"],sizeLimit:5242880},[d.E_UploadType.VIDEO]:{allowedExtensions:["mp4","avi","mov","wmv","flv","webm"],sizeLimit:524288e3},[d.E_UploadType.AUDIO]:{allowedExtensions:["mp3","wav","ogg","m4a","aac"],sizeLimit:52428800},[d.E_UploadType.DOCUMENT]:{allowedExtensions:["pdf","doc","docx","txt","rtf"],sizeLimit:10485760},[d.E_UploadType.OTHER]:{allowedExtensions:["zip","rar","tar","gz"],sizeLimit:5242880}};return w(w({},t),i)}function I(i){return m(this,null,function*(){const{path:t,file:e,config:r,type:a}=i;if(!t||typeof t!="string")return{success:!1,message:"Invalid path provided",code:f.RESPONSE_STATUS.BAD_REQUEST.CODE};if(!e||typeof e!="object")return{success:!1,message:"Invalid file provided",code:f.RESPONSE_STATUS.BAD_REQUEST.CODE};if(r){const s=[d.E_UploadType.IMAGE,d.E_UploadType.VIDEO,d.E_UploadType.DOCUMENT,d.E_UploadType.OTHER];for(const o of s){if(!r[o]||!Array.isArray(r[o].allowedExtensions)||r[o].allowedExtensions.length===0)return{success:!1,message:`Invalid config for ${o.toLowerCase()} files`,code:f.RESPONSE_STATUS.BAD_REQUEST.CODE};if(typeof r[o].sizeLimit!="number"||r[o].sizeLimit<=0)return{success:!1,message:`Invalid size limit for ${o.toLowerCase()} files`,code:f.RESPONSE_STATUS.BAD_REQUEST.CODE}}}try{const s=yield _(a,yield e,r);if(!s.success)return s;const{createReadStream:o}=s.result,n=D.dirname(t);S.pathExistsSync(n)||S.mkdirSync(n,{recursive:!0});const l=o(),c=S.createWriteStream(t);return l.pipe(c),yield new Promise((E,u)=>{c.on("finish",()=>E()),c.on("error",u),l.on("error",u)}),{success:!0,result:t,message:"File uploaded successfully",code:f.RESPONSE_STATUS.OK.CODE}}catch(s){return{success:!1,message:s instanceof Error?s.message:"File upload failed",code:f.RESPONSE_STATUS.INTERNAL_SERVER_ERROR.CODE}}})}exports.createUploadConfig=y;exports.getAndValidateFile=_;exports.getFileSizeFromStream=O;exports.getFileWebStream=L;exports.upload=I;exports.validateFileExtension=U;exports.validateUpload=R;
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 _ } from "node:buffer";
2
- import { Transform as x } from "node:stream";
3
- import { ReadableStream as z } from "node:stream/web";
4
- import { BYTES_PER_MB as C } from "./upload.constant.js";
5
- import { E_UploadType as c } from "./upload.type.js";
6
- import { dirname as D } from "../path/path.util.js";
7
- import { pathExistsSync as R, mkdirSync as h, createWriteStream as L } from "../fs/fs.util.js";
8
- import { RESPONSE_STATUS as d } from "../../constant/response-status.js";
9
- var T = Object.defineProperty, v = Object.getOwnPropertySymbols, A = Object.prototype.hasOwnProperty, I = Object.prototype.propertyIsEnumerable, w = (r, t, e) => t in r ? T(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, y = (r, t) => {
10
- for (var e in t || (t = {}))
11
- A.call(t, e) && w(r, e, t[e]);
12
- if (v)
13
- for (var e of v(t))
14
- I.call(t, e) && w(r, e, t[e]);
15
- return r;
16
- }, E = (r, t, e) => new Promise((i, a) => {
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 (u) {
21
- a(u);
20
+ } catch (c) {
21
+ a(c);
22
22
  }
23
23
  }, o = (l) => {
24
24
  try {
25
25
  n(e.throw(l));
26
- } catch (u) {
27
- a(u);
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(r, t)).next());
30
+ n((e = e.apply(t, r)).next());
31
31
  });
32
- function P(r) {
32
+ function B(t) {
33
33
  return E(this, null, function* () {
34
- return new Promise((t, e) => {
34
+ return new Promise((r, e) => {
35
35
  let i = 0;
36
- r.on("data", (a) => {
36
+ t.on("data", (a) => {
37
37
  i += a.length;
38
- }), r.on("end", () => t(i)), r.on("error", e);
38
+ }), t.on("end", () => r(i)), t.on("error", e);
39
39
  });
40
40
  });
41
41
  }
42
- function S(r, t, e) {
42
+ function g(t, r, e) {
43
43
  return E(this, null, function* () {
44
- const i = yield (yield t).file, a = i.createReadStream(), s = yield P(a), o = e != null ? e : O(), n = F(
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
- r
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: d.BAD_REQUEST.CODE
56
+ code: u.BAD_REQUEST.CODE
57
57
  };
58
58
  });
59
59
  }
60
- function q(r, t, e) {
60
+ function G(t, r, e) {
61
61
  return E(this, null, function* () {
62
- const a = (e != null ? e : O())[r], s = yield S(r, t, 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 x({
68
- transform(f, m, g) {
69
- n -= f.length, n < 0 ? g(new Error(`File size exceeds limit of ${a.sizeLimit / C}MB`)) : g(null, f);
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
- }), p = o().pipe(l);
71
+ }), m = o().pipe(l);
72
72
  return {
73
73
  success: !0,
74
- result: new z({
74
+ result: new D({
75
75
  start(f) {
76
- p.on("data", (m) => {
77
- f.enqueue(typeof m == "string" ? _.from(m) : m);
78
- }), p.on("end", () => f.close()), p.on("error", (m) => f.error(m));
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 B(r, t) {
85
- const e = r.lastIndexOf(".");
84
+ function I(t, r) {
85
+ const e = t.lastIndexOf(".");
86
86
  if (e === -1)
87
87
  return !1;
88
- const i = r.substring(e + 1).toLowerCase();
89
- return t.includes(i);
88
+ const i = t.substring(e + 1).toLowerCase();
89
+ return r.includes(i);
90
90
  }
91
- function F(r, t, e) {
92
- const { filename: i, fileSize: a } = r, s = t[e], { allowedExtensions: o, sizeLimit: n } = s;
93
- if (!B(i, o))
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(r) {
108
- const t = {
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 G(r) {
110
+ function W(t) {
138
111
  return E(this, null, function* () {
139
- const { path: t, file: e, config: i, type: a } = r;
140
- if (!t || typeof t != "string")
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: d.BAD_REQUEST.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: d.BAD_REQUEST.CODE
123
+ code: u.BAD_REQUEST.CODE
151
124
  };
152
125
  if (i) {
153
- const s = [c.IMAGE, c.VIDEO, c.DOCUMENT, c.OTHER];
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: d.BAD_REQUEST.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: d.BAD_REQUEST.CODE
138
+ code: u.BAD_REQUEST.CODE
166
139
  };
167
140
  }
168
141
  }
169
142
  try {
170
- const s = yield S(a, yield e, i);
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 = D(t);
174
- R(n) || h(n, { recursive: !0 });
175
- const l = o(), u = L(t);
176
- return l.pipe(u), yield new Promise((p, f) => {
177
- u.on("finish", () => p()), u.on("error", f), l.on("error", f);
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: t,
153
+ result: r,
181
154
  message: "File uploaded successfully",
182
- code: d.OK.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: d.INTERNAL_SERVER_ERROR.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
- S as getAndValidateFile,
196
- P as getFileSizeFromStream,
197
- q as getFileWebStream,
198
- G as upload,
199
- B as validateFileExtension,
200
- F as validateUpload
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
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cyberskill/shared",
3
3
  "type": "module",
4
- "version": "2.9.0",
4
+ "version": "2.10.0",
5
5
  "description": "CyberSkill Shared",
6
6
  "author": "Stephen Cheng",
7
7
  "license": "MIT",