lesca-node-bunnycdn 0.0.21 → 0.0.23
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 +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +96 -86
- package/lib/type.d.ts +1 -0
- package/lib/vector-folder-directory-icon-png-701751694965455bukl0emvi3.png +0 -0
- package/package.json +1 -2
- package/readme.md +1 -14
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 R(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 D(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 d=[],$=!1,g,v=-1;function Y(){!$||!g||($=!1,g.length?d=g.concat(d):v=-1,d.length&&U())}function U(){if(!$){var e=S(Y);$=!0;for(var t=d.length;t;){for(g=d,d=[];++v<t;)g&&g[v].run();v=-1,t=d.length}g=null,$=!1,D(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];d.push(new A(e,t)),d.length===1&&!$&&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 m(){}r.on=m;r.addListener=m;r.once=m;r.off=m;r.removeListener=m;r.removeAllListeners=m;r.emit=m;r.prependListener=m;r.prependOnceListener=m;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 Z=O.exports;const h=R(Z),_=(e={})=>({region:e.region||h.env.BUNNY_REGION||"SG",baseHostName:"storage.bunnycdn.com",folderName:e.folderName||h.env.BUNNY_FOLDER_NAME||"",storageZone:e.storageZone||h.env.BUNNY_STORAGE_ZONE||"unset",password:e.password||h.env.BUNNY_PASSWORD||"unset"}),P=({storageZone:e,password:t,region:n,folderName:c})=>{e&&(h.env.BUNNY_STORAGE_ZONE=e),t&&(h.env.BUNNY_PASSWORD=t),n&&(h.env.BUNNY_REGION=n),c&&(h.env.BUNNY_FOLDER_NAME=c)},L=async({file:e,buffer:t,folder:n,format:c,...o})=>new Promise(async(p,l)=>{try{!t&&!e&&l({res:!1,message:"No file uploaded"});const s=_(o),y=t?t.length:e.buffer.length,N=s.folderName?`${s.folderName}/`:"",a=n?`${n}/`:"",w=c||"jpg",i=`${new Date().getTime()}.${w}`,T={method:"PUT",hostname:s.region?`${s.region}.${s.baseHostName}`:s.baseHostName,port:443,path:`/${s.storageZone}/${N}${a}${i}`,headers:{AccessKey:s.password,"Content-Type":"application/octet-stream","Content-Length":y.toString()}},F=await fetch(`https://${T.hostname}${T.path}`,{method:"PUT",headers:T.headers,body:t||e.buffer});if(F.status===201){const H=`https://${s.storageZone}.b-cdn.net/${N}${a}${i}`;p({res:!0,message:"upload success",url:H})}else l({res:!1,message:"Upload failed",error:await F.text()})}catch{l({res:!1,message:"Server error"})}}),B=async({folder:e="",configOverrides:t={}}={})=>new Promise((n,c)=>{try{const o=_(t),p=o.region?`${o.region}.${o.baseHostName}`:o.baseHostName,l=o.folderName?`${o.folderName}/`:"",s=e?`${e}/`:"",y=`https://${p}/${o.storageZone}/${l}${s}`,N={AccessKey:o.password};fetch(y,{headers:N}).then(a=>a.json()).then(a=>{const w=a.map(i=>{const T=`https://${o.storageZone}.b-cdn.net/${l}${s}${i.ObjectName}`;return{...i,Url:T}});n({res:!0,message:"List retrieved successfully",files:w})}).catch(a=>{c({res:!1,message:"Network error",error:a})})}catch{c({res:!1,message:"Server error"})}}),C=({ObjectName:e,href:t,...n})=>new Promise((c,o)=>{if(!e&&!t){o({res:!1,message:"No file specified for deletion"});return}try{let p="",l="";if(t){const a=t.split("/").filter(i=>i!==""&&!i.includes("http"));if([...a].pop()?.includes(".")||!1){const i=[...a];p=decodeURIComponent(i.pop()||""),l=i.splice(1,1).join("/")}else l=[...a].splice(1,1).join("/")}const s=_(n),y=s.region?`${s.region}.${s.baseHostName}`:s.baseHostName,N=l?`/${l}`:"";fetch(`https://${y}/${s.storageZone}${N}/${p}`,{method:"DELETE",headers:{AccessKey:s.password}}).then(a=>{a.status===200?c({res:!0,message:"File deleted successfully"}):c({res:!1,message:"Failed to delete file"})}).catch(a=>{o({res:!1,message:"Network error",error:a})})}catch{o({res:!1,message:"Server error"})}}),x={install:P,upload:L,list:B,deleteFile:C};exports.default=x;exports.deleteFile=C;exports.install=P;exports.list=B;exports.upload=L;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { File, InstallParams, ListParams, UploadParams } from './type';
|
|
2
2
|
export declare const install: ({ storageZone, password, region, folderName }: InstallParams) => void;
|
|
3
|
-
export declare const upload: ({ file, buffer, folder, ...configOverrides }: UploadParams & Partial<InstallParams>) => Promise<{
|
|
3
|
+
export declare const upload: ({ file, buffer, folder, format, ...configOverrides }: UploadParams & Partial<InstallParams>) => Promise<{
|
|
4
4
|
res: boolean;
|
|
5
5
|
message: string;
|
|
6
6
|
url?: string;
|
|
@@ -20,7 +20,7 @@ export declare const deleteFile: ({ ObjectName, href, ...configOverrides }: {
|
|
|
20
20
|
}>;
|
|
21
21
|
declare const BunnyCDN: {
|
|
22
22
|
install: ({ storageZone, password, region, folderName }: InstallParams) => void;
|
|
23
|
-
upload: ({ file, buffer, folder, ...configOverrides }: UploadParams & Partial<InstallParams>) => Promise<{
|
|
23
|
+
upload: ({ file, buffer, folder, format, ...configOverrides }: UploadParams & Partial<InstallParams>) => Promise<{
|
|
24
24
|
res: boolean;
|
|
25
25
|
message: string;
|
|
26
26
|
url?: string;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function
|
|
1
|
+
function P(e) {
|
|
2
2
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
3
3
|
}
|
|
4
|
-
var
|
|
4
|
+
var F = { exports: {} }, r = F.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 B(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 m = [], $ = !1, g, v = -1;
|
|
54
|
+
function C() {
|
|
55
|
+
!$ || !g || ($ = !1, g.length ? m = g.concat(m) : v = -1, m.length && _());
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
if (
|
|
59
|
-
var e =
|
|
60
|
-
|
|
61
|
-
for (var t =
|
|
62
|
-
for (
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
function _() {
|
|
58
|
+
if (!$) {
|
|
59
|
+
var e = O(C);
|
|
60
|
+
$ = !0;
|
|
61
|
+
for (var t = m.length; t; ) {
|
|
62
|
+
for (g = m, m = []; ++v < t; )
|
|
63
|
+
g && g[v].run();
|
|
64
|
+
v = -1, t = m.length;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
g = null, $ = !1, B(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
|
+
m.push(new S(e, t)), m.length === 1 && !$ && O(_);
|
|
75
75
|
};
|
|
76
|
-
function
|
|
76
|
+
function S(e, t) {
|
|
77
77
|
this.fun = e, this.array = t;
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
S.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 d() {
|
|
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 = d;
|
|
91
|
+
r.addListener = d;
|
|
92
|
+
r.once = d;
|
|
93
|
+
r.off = d;
|
|
94
|
+
r.removeListener = d;
|
|
95
|
+
r.removeAllListeners = d;
|
|
96
|
+
r.emit = d;
|
|
97
|
+
r.prependListener = d;
|
|
98
|
+
r.prependOnceListener = d;
|
|
99
99
|
r.listeners = function(e) {
|
|
100
100
|
return [];
|
|
101
101
|
};
|
|
@@ -111,8 +111,8 @@ r.chdir = function(e) {
|
|
|
111
111
|
r.umask = function() {
|
|
112
112
|
return 0;
|
|
113
113
|
};
|
|
114
|
-
var
|
|
115
|
-
const h = /* @__PURE__ */
|
|
114
|
+
var H = F.exports;
|
|
115
|
+
const h = /* @__PURE__ */ P(H), U = (e = {}) => ({
|
|
116
116
|
region: e.region || h.env.BUNNY_REGION || "SG",
|
|
117
117
|
baseHostName: "storage.bunnycdn.com",
|
|
118
118
|
folderName: e.folderName || h.env.BUNNY_FOLDER_NAME || "",
|
|
@@ -124,77 +124,87 @@ const h = /* @__PURE__ */ L(C), U = (e = {}) => ({
|
|
|
124
124
|
file: e,
|
|
125
125
|
buffer: t,
|
|
126
126
|
folder: n,
|
|
127
|
-
|
|
127
|
+
format: c,
|
|
128
|
+
...o
|
|
128
129
|
}) => new Promise(
|
|
129
|
-
async (
|
|
130
|
+
async (p, l) => {
|
|
130
131
|
try {
|
|
131
|
-
!t && !e &&
|
|
132
|
-
const
|
|
132
|
+
!t && !e && l({ res: !1, message: "No file uploaded" });
|
|
133
|
+
const s = U(o), y = t ? t.length : e.buffer.length, N = s.folderName ? `${s.folderName}/` : "", a = n ? `${n}/` : "", w = c || "jpg", i = `${(/* @__PURE__ */ new Date()).getTime()}.${w}`, T = {
|
|
133
134
|
method: "PUT",
|
|
134
|
-
hostname:
|
|
135
|
+
hostname: s.region ? `${s.region}.${s.baseHostName}` : s.baseHostName,
|
|
135
136
|
port: 443,
|
|
136
|
-
path: `/${
|
|
137
|
+
path: `/${s.storageZone}/${N}${a}${i}`,
|
|
137
138
|
headers: {
|
|
138
|
-
AccessKey:
|
|
139
|
+
AccessKey: s.password,
|
|
139
140
|
"Content-Type": "application/octet-stream",
|
|
140
|
-
"Content-Length":
|
|
141
|
+
"Content-Length": y.toString()
|
|
141
142
|
}
|
|
142
|
-
},
|
|
143
|
+
}, A = await fetch(`https://${T.hostname}${T.path}`, {
|
|
143
144
|
method: "PUT",
|
|
144
|
-
headers:
|
|
145
|
+
headers: T.headers,
|
|
145
146
|
body: t || e.buffer
|
|
146
147
|
});
|
|
147
|
-
if (
|
|
148
|
-
const
|
|
149
|
-
|
|
148
|
+
if (A.status === 201) {
|
|
149
|
+
const L = `https://${s.storageZone}.b-cdn.net/${N}${a}${i}`;
|
|
150
|
+
p({ res: !0, message: "upload success", url: L });
|
|
150
151
|
} else
|
|
151
|
-
|
|
152
|
+
l({ res: !1, message: "Upload failed", error: await A.text() });
|
|
152
153
|
} catch {
|
|
153
|
-
|
|
154
|
+
l({ res: !1, message: "Server error" });
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
|
-
),
|
|
157
|
+
), Y = async ({ folder: e = "", configOverrides: t = {} } = {}) => new Promise((n, c) => {
|
|
157
158
|
try {
|
|
158
|
-
const
|
|
159
|
-
fetch(
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
return { ...
|
|
159
|
+
const o = U(t), p = o.region ? `${o.region}.${o.baseHostName}` : o.baseHostName, l = o.folderName ? `${o.folderName}/` : "", s = e ? `${e}/` : "", y = `https://${p}/${o.storageZone}/${l}${s}`, N = { AccessKey: o.password };
|
|
160
|
+
fetch(y, { headers: N }).then((a) => a.json()).then((a) => {
|
|
161
|
+
const w = a.map((i) => {
|
|
162
|
+
const T = `https://${o.storageZone}.b-cdn.net/${l}${s}${i.ObjectName}`;
|
|
163
|
+
return { ...i, Url: T };
|
|
163
164
|
});
|
|
164
|
-
n({ res: !0, message: "List retrieved successfully", files:
|
|
165
|
-
}).catch((
|
|
166
|
-
c({ res: !1, message: "Network error", error:
|
|
165
|
+
n({ res: !0, message: "List retrieved successfully", files: w });
|
|
166
|
+
}).catch((a) => {
|
|
167
|
+
c({ res: !1, message: "Network error", error: a });
|
|
167
168
|
});
|
|
168
169
|
} catch {
|
|
169
170
|
c({ res: !1, message: "Server error" });
|
|
170
171
|
}
|
|
171
|
-
}),
|
|
172
|
+
}), Z = ({
|
|
172
173
|
ObjectName: e,
|
|
173
174
|
href: t,
|
|
174
175
|
...n
|
|
175
|
-
}) => new Promise((c,
|
|
176
|
+
}) => new Promise((c, o) => {
|
|
176
177
|
if (!e && !t) {
|
|
177
|
-
|
|
178
|
+
o({ res: !1, message: "No file specified for deletion" });
|
|
178
179
|
return;
|
|
179
180
|
}
|
|
180
181
|
try {
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
let p = "", l = "";
|
|
183
|
+
if (t) {
|
|
184
|
+
const a = t.split("/").filter((i) => i !== "" && !i.includes("http"));
|
|
185
|
+
if ([...a].pop()?.includes(".") || !1) {
|
|
186
|
+
const i = [...a];
|
|
187
|
+
p = decodeURIComponent(i.pop() || ""), l = i.splice(1, 1).join("/");
|
|
188
|
+
} else
|
|
189
|
+
l = [...a].splice(1, 1).join("/");
|
|
190
|
+
}
|
|
191
|
+
const s = U(n), y = s.region ? `${s.region}.${s.baseHostName}` : s.baseHostName, N = l ? `/${l}` : "";
|
|
192
|
+
fetch(`https://${y}/${s.storageZone}${N}/${p}`, {
|
|
183
193
|
method: "DELETE",
|
|
184
|
-
headers: { AccessKey:
|
|
185
|
-
}).then((
|
|
186
|
-
|
|
187
|
-
}).catch((
|
|
188
|
-
|
|
194
|
+
headers: { AccessKey: s.password }
|
|
195
|
+
}).then((a) => {
|
|
196
|
+
a.status === 200 ? c({ res: !0, message: "File deleted successfully" }) : c({ res: !1, message: "Failed to delete file" });
|
|
197
|
+
}).catch((a) => {
|
|
198
|
+
o({ res: !1, message: "Network error", error: a });
|
|
189
199
|
});
|
|
190
200
|
} catch {
|
|
191
|
-
|
|
201
|
+
o({ res: !1, message: "Server error" });
|
|
192
202
|
}
|
|
193
|
-
}),
|
|
203
|
+
}), x = { install: R, upload: D, list: Y, deleteFile: Z };
|
|
194
204
|
export {
|
|
195
|
-
|
|
196
|
-
|
|
205
|
+
x as default,
|
|
206
|
+
Z as deleteFile,
|
|
197
207
|
R as install,
|
|
198
|
-
|
|
208
|
+
Y as list,
|
|
199
209
|
D as upload
|
|
200
210
|
};
|
package/lib/type.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "lesca-node-bunnycdn",
|
|
3
3
|
"private": false,
|
|
4
4
|
"description": "use bunny CDN api by node",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.23",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"bunnycdn",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"path": "^0.12.7",
|
|
40
40
|
"prettier": "^3.8.0",
|
|
41
41
|
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
42
|
-
"sharp": "^0.34.5",
|
|
43
42
|
"tsx": "^4.21.0",
|
|
44
43
|
"typescript": "^5.9.3",
|
|
45
44
|
"typescript-eslint": "^8.53.0",
|
package/readme.md
CHANGED
|
@@ -281,16 +281,7 @@ export const handler = async (event, context) => {
|
|
|
281
281
|
|
|
282
282
|
## Features
|
|
283
283
|
|
|
284
|
-
-
|
|
285
|
-
- ✅ List files in storage zone
|
|
286
|
-
- ✅ Delete files from storage
|
|
287
|
-
- ✅ Support for different regions
|
|
288
|
-
- ✅ Folder organization
|
|
289
|
-
- ✅ Full TypeScript support
|
|
290
|
-
- ✅ Environment variable configuration
|
|
291
|
-
- ✅ Automatic file extension handling (.webp)
|
|
292
|
-
- ✅ UUID-based filename generation
|
|
293
|
-
- ✅ Perfect for serverless functions
|
|
284
|
+
- maintain if necessary
|
|
294
285
|
|
|
295
286
|
## License
|
|
296
287
|
|
|
@@ -299,7 +290,3 @@ MIT
|
|
|
299
290
|
## Contributing
|
|
300
291
|
|
|
301
292
|
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
302
|
-
|
|
303
|
-
### Features
|
|
304
|
-
|
|
305
|
-
- maintain if necessary
|