lesca-node-bunnycdn 0.0.21 → 0.0.22
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/lib/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function C(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var O={exports:{}},r=O.exports={},u,f;function b(){throw new Error("setTimeout has not been defined")}function E(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?u=setTimeout:u=b}catch{u=b}try{typeof clearTimeout=="function"?f=clearTimeout:f=E}catch{f=E}})();function S(e){if(u===setTimeout)return setTimeout(e,0);if((u===b||!u)&&setTimeout)return u=setTimeout,setTimeout(e,0);try{return u(e,0)}catch{try{return u.call(null,e,0)}catch{return u.call(this,e,0)}}}function H(e){if(f===clearTimeout)return clearTimeout(e);if((f===E||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(e);try{return f(e)}catch{try{return f.call(null,e)}catch{return f.call(this,e)}}}var m=[],T=!1,g,w=-1;function R(){!T||!g||(T=!1,g.length?m=g.concat(m):w=-1,m.length&&U())}function U(){if(!T){var e=S(R);T=!0;for(var t=m.length;t;){for(g=m,m=[];++w<t;)g&&g[w].run();w=-1,t=m.length}g=null,T=!1,H(e)}}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];m.push(new A(e,t)),m.length===1&&!T&&S(U)};function A(e,t){this.fun=e,this.array=t}A.prototype.run=function(){this.fun.apply(null,this.array)};r.title="browser";r.browser=!0;r.env={};r.argv=[];r.version="";r.versions={};function h(){}r.on=h;r.addListener=h;r.once=h;r.off=h;r.removeListener=h;r.removeAllListeners=h;r.emit=h;r.prependListener=h;r.prependOnceListener=h;r.listeners=function(e){return[]};r.binding=function(e){throw new Error("process.binding is not supported")};r.cwd=function(){return"/"};r.chdir=function(e){throw new Error("process.chdir is not supported")};r.umask=function(){return 0};var D=O.exports;const p=C(D),_=(e={})=>({region:e.region||p.env.BUNNY_REGION||"SG",baseHostName:"storage.bunnycdn.com",folderName:e.folderName||p.env.BUNNY_FOLDER_NAME||"",storageZone:e.storageZone||p.env.BUNNY_STORAGE_ZONE||"unset",password:e.password||p.env.BUNNY_PASSWORD||"unset"}),F=({storageZone:e,password:t,region:n,folderName:l})=>{e&&(p.env.BUNNY_STORAGE_ZONE=e),t&&(p.env.BUNNY_PASSWORD=t),n&&(p.env.BUNNY_REGION=n),l&&(p.env.BUNNY_FOLDER_NAME=l)},P=async({file:e,buffer:t,folder:n,...l})=>new Promise(async(o,d)=>{try{!t&&!e&&d({res:!1,message:"No file uploaded"});const s=_(l),c=t?t.length:e.buffer.length,N=s.folderName?`${s.folderName}/`:"",$=n?`${n}/`:"",a=`${new Date().getTime()}.webp`,y={method:"PUT",hostname:s.region?`${s.region}.${s.baseHostName}`:s.baseHostName,port:443,path:`/${s.storageZone}/${N}${$}${a}`,headers:{AccessKey:s.password,"Content-Type":"application/octet-stream","Content-Length":c.toString()}},i=await fetch(`https://${y.hostname}${y.path}`,{method:"PUT",headers:y.headers,body:t||e.buffer});if(i.status===201){const v=`https://${s.storageZone}.b-cdn.net/${N}${$}${a}`;o({res:!0,message:"upload success",url:v})}else d({res:!1,message:"Upload failed",error:await i.text()})}catch{d({res:!1,message:"Server error"})}}),L=async({folder:e="",configOverrides:t={}}={})=>new Promise((n,l)=>{try{const o=_(t),d=o.region?`${o.region}.${o.baseHostName}`:o.baseHostName,s=o.folderName?`${o.folderName}/`:"",c=e?`${e}/`:"",N=`https://${d}/${o.storageZone}/${s}${c}`,$={AccessKey:o.password};fetch(N,{headers:$}).then(a=>a.json()).then(a=>{const y=a.map(i=>{const v=`https://${o.storageZone}.b-cdn.net/${s}${c}${i.ObjectName}`;return{...i,Url:v}});n({res:!0,message:"List retrieved successfully",files:y})}).catch(a=>{l({res:!1,message:"Network error",error:a})})}catch{l({res:!1,message:"Server error"})}}),B=({ObjectName:e,href:t,...n})=>new Promise((l,o)=>{if(!e&&!t){o({res:!1,message:"No file specified for deletion"});return}try{let d="",s="";if(t){const a=t.split("/").filter(i=>i!==""&&!i.includes("http"));if([...a].pop()?.includes(".")||!1){const i=[...a];d=decodeURIComponent(i.pop()||""),s=i.splice(1,1).join("/")}else s=[...a].splice(1,1).join("/")}const c=_(n),N=c.region?`${c.region}.${c.baseHostName}`:c.baseHostName,$=s?`/${s}`:"";fetch(`https://${N}/${c.storageZone}${$}/${d}`,{method:"DELETE",headers:{AccessKey:c.password}}).then(a=>{a.status===200?l({res:!0,message:"File deleted successfully"}):l({res:!1,message:"Failed to delete file"})}).catch(a=>{o({res:!1,message:"Network error",error:a})})}catch{o({res:!1,message:"Server error"})}}),Y={install:F,upload:P,list:L,deleteFile:B};exports.default=Y;exports.deleteFile=B;exports.install=F;exports.list=L;exports.upload=P;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function
|
|
1
|
+
function S(e) {
|
|
2
2
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
3
3
|
}
|
|
4
|
-
var
|
|
4
|
+
var A = { exports: {} }, r = A.exports = {}, u, f;
|
|
5
5
|
function b() {
|
|
6
6
|
throw new Error("setTimeout has not been defined");
|
|
7
7
|
}
|
|
@@ -10,60 +10,60 @@ function E() {
|
|
|
10
10
|
}
|
|
11
11
|
(function() {
|
|
12
12
|
try {
|
|
13
|
-
typeof setTimeout == "function" ?
|
|
13
|
+
typeof setTimeout == "function" ? u = setTimeout : u = b;
|
|
14
14
|
} catch {
|
|
15
|
-
|
|
15
|
+
u = b;
|
|
16
16
|
}
|
|
17
17
|
try {
|
|
18
|
-
typeof clearTimeout == "function" ?
|
|
18
|
+
typeof clearTimeout == "function" ? f = clearTimeout : f = E;
|
|
19
19
|
} catch {
|
|
20
|
-
|
|
20
|
+
f = E;
|
|
21
21
|
}
|
|
22
22
|
})();
|
|
23
|
-
function
|
|
24
|
-
if (
|
|
23
|
+
function O(e) {
|
|
24
|
+
if (u === setTimeout)
|
|
25
25
|
return setTimeout(e, 0);
|
|
26
|
-
if ((
|
|
27
|
-
return
|
|
26
|
+
if ((u === b || !u) && setTimeout)
|
|
27
|
+
return u = setTimeout, setTimeout(e, 0);
|
|
28
28
|
try {
|
|
29
|
-
return
|
|
29
|
+
return u(e, 0);
|
|
30
30
|
} catch {
|
|
31
31
|
try {
|
|
32
|
-
return
|
|
32
|
+
return u.call(null, e, 0);
|
|
33
33
|
} catch {
|
|
34
|
-
return
|
|
34
|
+
return u.call(this, e, 0);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
if (
|
|
38
|
+
function L(e) {
|
|
39
|
+
if (f === clearTimeout)
|
|
40
40
|
return clearTimeout(e);
|
|
41
|
-
if ((
|
|
42
|
-
return
|
|
41
|
+
if ((f === E || !f) && clearTimeout)
|
|
42
|
+
return f = clearTimeout, clearTimeout(e);
|
|
43
43
|
try {
|
|
44
|
-
return
|
|
44
|
+
return f(e);
|
|
45
45
|
} catch {
|
|
46
46
|
try {
|
|
47
|
-
return
|
|
47
|
+
return f.call(null, e);
|
|
48
48
|
} catch {
|
|
49
|
-
return
|
|
49
|
+
return f.call(this, e);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
var
|
|
54
|
-
function
|
|
55
|
-
!
|
|
53
|
+
var d = [], w = !1, g, T = -1;
|
|
54
|
+
function P() {
|
|
55
|
+
!w || !g || (w = !1, g.length ? d = g.concat(d) : T = -1, d.length && _());
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
if (!
|
|
59
|
-
var e =
|
|
60
|
-
|
|
61
|
-
for (var t =
|
|
62
|
-
for (
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
function _() {
|
|
58
|
+
if (!w) {
|
|
59
|
+
var e = O(P);
|
|
60
|
+
w = !0;
|
|
61
|
+
for (var t = d.length; t; ) {
|
|
62
|
+
for (g = d, d = []; ++T < t; )
|
|
63
|
+
g && g[T].run();
|
|
64
|
+
T = -1, t = d.length;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
g = null, w = !1, L(e);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
r.nextTick = function(e) {
|
|
@@ -71,12 +71,12 @@ r.nextTick = function(e) {
|
|
|
71
71
|
if (arguments.length > 1)
|
|
72
72
|
for (var n = 1; n < arguments.length; n++)
|
|
73
73
|
t[n - 1] = arguments[n];
|
|
74
|
-
|
|
74
|
+
d.push(new F(e, t)), d.length === 1 && !w && O(_);
|
|
75
75
|
};
|
|
76
|
-
function
|
|
76
|
+
function F(e, t) {
|
|
77
77
|
this.fun = e, this.array = t;
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
F.prototype.run = function() {
|
|
80
80
|
this.fun.apply(null, this.array);
|
|
81
81
|
};
|
|
82
82
|
r.title = "browser";
|
|
@@ -85,17 +85,17 @@ r.env = {};
|
|
|
85
85
|
r.argv = [];
|
|
86
86
|
r.version = "";
|
|
87
87
|
r.versions = {};
|
|
88
|
-
function
|
|
88
|
+
function h() {
|
|
89
89
|
}
|
|
90
|
-
r.on =
|
|
91
|
-
r.addListener =
|
|
92
|
-
r.once =
|
|
93
|
-
r.off =
|
|
94
|
-
r.removeListener =
|
|
95
|
-
r.removeAllListeners =
|
|
96
|
-
r.emit =
|
|
97
|
-
r.prependListener =
|
|
98
|
-
r.prependOnceListener =
|
|
90
|
+
r.on = h;
|
|
91
|
+
r.addListener = h;
|
|
92
|
+
r.once = h;
|
|
93
|
+
r.off = h;
|
|
94
|
+
r.removeListener = h;
|
|
95
|
+
r.removeAllListeners = h;
|
|
96
|
+
r.emit = h;
|
|
97
|
+
r.prependListener = h;
|
|
98
|
+
r.prependOnceListener = h;
|
|
99
99
|
r.listeners = function(e) {
|
|
100
100
|
return [];
|
|
101
101
|
};
|
|
@@ -111,90 +111,99 @@ r.chdir = function(e) {
|
|
|
111
111
|
r.umask = function() {
|
|
112
112
|
return 0;
|
|
113
113
|
};
|
|
114
|
-
var
|
|
115
|
-
const
|
|
116
|
-
region: e.region ||
|
|
114
|
+
var B = A.exports;
|
|
115
|
+
const p = /* @__PURE__ */ S(B), U = (e = {}) => ({
|
|
116
|
+
region: e.region || p.env.BUNNY_REGION || "SG",
|
|
117
117
|
baseHostName: "storage.bunnycdn.com",
|
|
118
|
-
folderName: e.folderName ||
|
|
119
|
-
storageZone: e.storageZone ||
|
|
120
|
-
password: e.password ||
|
|
121
|
-
}),
|
|
122
|
-
e && (
|
|
123
|
-
},
|
|
118
|
+
folderName: e.folderName || p.env.BUNNY_FOLDER_NAME || "",
|
|
119
|
+
storageZone: e.storageZone || p.env.BUNNY_STORAGE_ZONE || "unset",
|
|
120
|
+
password: e.password || p.env.BUNNY_PASSWORD || "unset"
|
|
121
|
+
}), C = ({ storageZone: e, password: t, region: n, folderName: l }) => {
|
|
122
|
+
e && (p.env.BUNNY_STORAGE_ZONE = e), t && (p.env.BUNNY_PASSWORD = t), n && (p.env.BUNNY_REGION = n), l && (p.env.BUNNY_FOLDER_NAME = l);
|
|
123
|
+
}, H = async ({
|
|
124
124
|
file: e,
|
|
125
125
|
buffer: t,
|
|
126
126
|
folder: n,
|
|
127
|
-
...
|
|
127
|
+
...l
|
|
128
128
|
}) => new Promise(
|
|
129
|
-
async (
|
|
129
|
+
async (o, m) => {
|
|
130
130
|
try {
|
|
131
|
-
!t && !e &&
|
|
132
|
-
const
|
|
131
|
+
!t && !e && m({ res: !1, message: "No file uploaded" });
|
|
132
|
+
const s = U(l), c = t ? t.length : e.buffer.length, N = s.folderName ? `${s.folderName}/` : "", $ = n ? `${n}/` : "", a = `${(/* @__PURE__ */ new Date()).getTime()}.webp`, y = {
|
|
133
133
|
method: "PUT",
|
|
134
|
-
hostname:
|
|
134
|
+
hostname: s.region ? `${s.region}.${s.baseHostName}` : s.baseHostName,
|
|
135
135
|
port: 443,
|
|
136
|
-
path: `/${
|
|
136
|
+
path: `/${s.storageZone}/${N}${$}${a}`,
|
|
137
137
|
headers: {
|
|
138
|
-
AccessKey:
|
|
138
|
+
AccessKey: s.password,
|
|
139
139
|
"Content-Type": "application/octet-stream",
|
|
140
|
-
"Content-Length":
|
|
140
|
+
"Content-Length": c.toString()
|
|
141
141
|
}
|
|
142
|
-
},
|
|
142
|
+
}, i = await fetch(`https://${y.hostname}${y.path}`, {
|
|
143
143
|
method: "PUT",
|
|
144
|
-
headers:
|
|
144
|
+
headers: y.headers,
|
|
145
145
|
body: t || e.buffer
|
|
146
146
|
});
|
|
147
|
-
if (
|
|
148
|
-
const v = `https://${
|
|
149
|
-
|
|
147
|
+
if (i.status === 201) {
|
|
148
|
+
const v = `https://${s.storageZone}.b-cdn.net/${N}${$}${a}`;
|
|
149
|
+
o({ res: !0, message: "upload success", url: v });
|
|
150
150
|
} else
|
|
151
|
-
|
|
151
|
+
m({ res: !1, message: "Upload failed", error: await i.text() });
|
|
152
152
|
} catch {
|
|
153
|
-
|
|
153
|
+
m({ res: !1, message: "Server error" });
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
),
|
|
156
|
+
), R = async ({ folder: e = "", configOverrides: t = {} } = {}) => new Promise((n, l) => {
|
|
157
157
|
try {
|
|
158
|
-
const
|
|
159
|
-
fetch(
|
|
160
|
-
const
|
|
161
|
-
const v = `https://${
|
|
162
|
-
return { ...
|
|
158
|
+
const o = U(t), m = o.region ? `${o.region}.${o.baseHostName}` : o.baseHostName, s = o.folderName ? `${o.folderName}/` : "", c = e ? `${e}/` : "", N = `https://${m}/${o.storageZone}/${s}${c}`, $ = { AccessKey: o.password };
|
|
159
|
+
fetch(N, { headers: $ }).then((a) => a.json()).then((a) => {
|
|
160
|
+
const y = a.map((i) => {
|
|
161
|
+
const v = `https://${o.storageZone}.b-cdn.net/${s}${c}${i.ObjectName}`;
|
|
162
|
+
return { ...i, Url: v };
|
|
163
163
|
});
|
|
164
|
-
n({ res: !0, message: "List retrieved successfully", files:
|
|
165
|
-
}).catch((
|
|
166
|
-
|
|
164
|
+
n({ res: !0, message: "List retrieved successfully", files: y });
|
|
165
|
+
}).catch((a) => {
|
|
166
|
+
l({ res: !1, message: "Network error", error: a });
|
|
167
167
|
});
|
|
168
168
|
} catch {
|
|
169
|
-
|
|
169
|
+
l({ res: !1, message: "Server error" });
|
|
170
170
|
}
|
|
171
|
-
}),
|
|
171
|
+
}), D = ({
|
|
172
172
|
ObjectName: e,
|
|
173
173
|
href: t,
|
|
174
174
|
...n
|
|
175
|
-
}) => new Promise((
|
|
175
|
+
}) => new Promise((l, o) => {
|
|
176
176
|
if (!e && !t) {
|
|
177
|
-
|
|
177
|
+
o({ res: !1, message: "No file specified for deletion" });
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
180
|
try {
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
let m = "", s = "";
|
|
182
|
+
if (t) {
|
|
183
|
+
const a = t.split("/").filter((i) => i !== "" && !i.includes("http"));
|
|
184
|
+
if ([...a].pop()?.includes(".") || !1) {
|
|
185
|
+
const i = [...a];
|
|
186
|
+
m = decodeURIComponent(i.pop() || ""), s = i.splice(1, 1).join("/");
|
|
187
|
+
} else
|
|
188
|
+
s = [...a].splice(1, 1).join("/");
|
|
189
|
+
}
|
|
190
|
+
const c = U(n), N = c.region ? `${c.region}.${c.baseHostName}` : c.baseHostName, $ = s ? `/${s}` : "";
|
|
191
|
+
fetch(`https://${N}/${c.storageZone}${$}/${m}`, {
|
|
183
192
|
method: "DELETE",
|
|
184
|
-
headers: { AccessKey:
|
|
185
|
-
}).then((
|
|
186
|
-
|
|
187
|
-
}).catch((
|
|
188
|
-
|
|
193
|
+
headers: { AccessKey: c.password }
|
|
194
|
+
}).then((a) => {
|
|
195
|
+
a.status === 200 ? l({ res: !0, message: "File deleted successfully" }) : l({ res: !1, message: "Failed to delete file" });
|
|
196
|
+
}).catch((a) => {
|
|
197
|
+
o({ res: !1, message: "Network error", error: a });
|
|
189
198
|
});
|
|
190
199
|
} catch {
|
|
191
|
-
|
|
200
|
+
o({ res: !1, message: "Server error" });
|
|
192
201
|
}
|
|
193
|
-
}),
|
|
202
|
+
}), Y = { install: C, upload: H, list: R, deleteFile: D };
|
|
194
203
|
export {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
204
|
+
Y as default,
|
|
205
|
+
D as deleteFile,
|
|
206
|
+
C as install,
|
|
207
|
+
R as list,
|
|
208
|
+
H as upload
|
|
200
209
|
};
|