@usync/drive 0.0.4 → 0.0.6
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/index.js +923 -1390
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,1393 +1,926 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { XMLParser as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
constructor: z,
|
|
24
|
-
toString: null,
|
|
25
|
-
valueOf: null
|
|
26
|
-
}, E = new z(1), D = 20, O = 4, k = -7, A = 21, j = -1e7, M = 1e7, N = !1, P = !0, F = 1, I = 0, L = {
|
|
27
|
-
prefix: "",
|
|
28
|
-
negativeSign: "-",
|
|
29
|
-
positiveSign: "",
|
|
30
|
-
groupSeparator: ",",
|
|
31
|
-
groupSize: 3,
|
|
32
|
-
secondaryGroupSize: 0,
|
|
33
|
-
decimalSeparator: ".",
|
|
34
|
-
fractionGroupSeparator: "",
|
|
35
|
-
fractionGroupSize: 0,
|
|
36
|
-
suffix: ""
|
|
37
|
-
}, R = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
38
|
-
function z(e, t) {
|
|
39
|
-
var n, s, c, u, d = this;
|
|
40
|
-
if (!(d instanceof z)) return new z(e, t);
|
|
41
|
-
if (u = typeof e, t == null) {
|
|
42
|
-
if (U(e)) {
|
|
43
|
-
d.s = e.s, !e.c || e.e > M ? d.c = d.e = null : e.e < j ? d.c = [d.e = 0] : (d.e = e.e, d.c = e.c.slice());
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (u == "number") {
|
|
47
|
-
if (e * 0 != 0) {
|
|
48
|
-
d.s = isNaN(e) ? null : e < 0 ? -1 : 1, d.c = d.e = null;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (d.s = 1 / e < 0 ? (e = -e, -1) : 1, e === ~~e) {
|
|
52
|
-
for (n = 0, s = e; s >= 10; s /= 10, n++);
|
|
53
|
-
n > M ? d.c = d.e = null : (d.e = n, d.c = [e]);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
return B(d, String(e));
|
|
57
|
-
}
|
|
58
|
-
if (u == "bigint") return d.s = e < 0 ? (e = -e, -1) : 1, B(d, String(e));
|
|
59
|
-
if (u == "string") c = e;
|
|
60
|
-
else {
|
|
61
|
-
if (P) throw Error(l + "BigNumber, string, number, or BigInt expected: " + e);
|
|
62
|
-
c = String(e);
|
|
63
|
-
}
|
|
64
|
-
if (o.test(c)) return d.s = c.charCodeAt(0) == 45 ? (c = c.slice(1), -1) : 1, B(d, c);
|
|
65
|
-
if (c = c.replace(a, ""), i.test(c)) {
|
|
66
|
-
d.s = isNaN(c) ? null : c < 0 ? -1 : 1, d.c = d.e = null;
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (c = c.replace(r, function(e, n, r) {
|
|
70
|
-
return t = (r = r.toLowerCase()) == "x" ? 16 : r == "b" ? 2 : 8, n;
|
|
71
|
-
}), t) return V(d, c, t, e);
|
|
72
|
-
if (c = c.replace(/(\d)_(?=\d)/g, "$1"), o.test(c)) return d.s = c.charCodeAt(0) == 45 ? (c = c.slice(1), -1) : 1, B(d, c);
|
|
73
|
-
if (P) throw Error(l + "Not a number: " + e);
|
|
74
|
-
d.s = d.c = d.e = null;
|
|
75
|
-
} else {
|
|
76
|
-
if (u != "string") {
|
|
77
|
-
if (P) throw Error(l + "String expected: " + e);
|
|
78
|
-
e = String(e);
|
|
79
|
-
}
|
|
80
|
-
b(t, 2, R.length, "Base"), V(d, e.replace(a, ""), t, e);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
z.clone = g, z.ROUND_UP = 0, z.ROUND_DOWN = 1, z.ROUND_CEIL = 2, z.ROUND_FLOOR = 3, z.ROUND_HALF_UP = 4, z.ROUND_HALF_DOWN = 5, z.ROUND_HALF_EVEN = 6, z.ROUND_HALF_CEIL = 7, z.ROUND_HALF_FLOOR = 8, z.EUCLID = 9, z.config = z.set = function(e) {
|
|
84
|
-
var t, n;
|
|
85
|
-
if (e != null) if (typeof e == "object") {
|
|
86
|
-
if (e.hasOwnProperty(t = "DECIMAL_PLACES") && (D = b(e[t], 0, h, t)), e.hasOwnProperty(t = "ROUNDING_MODE") && (O = b(e[t], 0, 8, t)), e.hasOwnProperty(t = "EXPONENTIAL_AT") && (n = e[t], x(n) ? (b(n[0], -h, 0, t), b(n[1], 0, h, t), k = n[0], A = n[1]) : k = -(A = b(n, -h, h, t) < 0 ? -n : n)), e.hasOwnProperty(t = "RANGE")) if (n = e[t], n) x(n) ? (b(n[0], -h, -1, t), b(n[1], 1, h, t), j = n[0], M = n[1]) : j = -(M = b(n, -h, h, t) < 0 ? -n : n);
|
|
87
|
-
else throw Error(l + t + " cannot be zero: " + n);
|
|
88
|
-
if (e.hasOwnProperty(t = "CRYPTO")) if (n = e[t], n === !!n) if (n) if (typeof crypto < "u" && crypto && (crypto.getRandomValues || crypto.randomBytes)) N = n;
|
|
89
|
-
else throw N = !n, Error(l + "crypto unavailable");
|
|
90
|
-
else N = n;
|
|
91
|
-
else throw Error(l + t + " not true or false: " + n);
|
|
92
|
-
if (e.hasOwnProperty(t = "STRICT")) if (n = e[t], n === !!n) P = n;
|
|
93
|
-
else throw Error(l + t + " not true or false: " + n);
|
|
94
|
-
if (e.hasOwnProperty(t = "MODULO_MODE") && (F = b(e[t], 0, 9, t)), e.hasOwnProperty(t = "POW_PRECISION") && (I = b(e[t], 0, h, t)), e.hasOwnProperty(t = "FORMAT")) if (n = e[t], typeof n == "object") for (t in n) n.hasOwnProperty(t) && L.hasOwnProperty(t) && (L[t] = n[t]);
|
|
95
|
-
else throw Error(l + t + " not an object: " + n);
|
|
96
|
-
if (e.hasOwnProperty(t = "ALPHABET")) if (n = e[t], typeof n == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(n)) R = n;
|
|
97
|
-
else throw Error(l + t + " invalid: " + n);
|
|
98
|
-
} else throw Error(l + "Object expected: " + e);
|
|
99
|
-
return {
|
|
100
|
-
DECIMAL_PLACES: D,
|
|
101
|
-
ROUNDING_MODE: O,
|
|
102
|
-
EXPONENTIAL_AT: [k, A],
|
|
103
|
-
RANGE: [j, M],
|
|
104
|
-
CRYPTO: N,
|
|
105
|
-
STRICT: P,
|
|
106
|
-
MODULO_MODE: F,
|
|
107
|
-
POW_PRECISION: I,
|
|
108
|
-
FORMAT: L,
|
|
109
|
-
ALPHABET: R
|
|
110
|
-
};
|
|
111
|
-
}, z.fromFormat = function(e, t) {
|
|
112
|
-
if (typeof e != "string") throw Error(l + "Not a string: " + e);
|
|
113
|
-
if (t == null) t = L;
|
|
114
|
-
else if (typeof t != "object") throw Error(l + "Argument not an object: " + t);
|
|
115
|
-
else t = K(t);
|
|
116
|
-
var n, r, i, a, o = t.negativeSign || "-", s = t.positiveSign || "", c = t.prefix || "", u = t.suffix || "", d = t.groupSeparator || "", f = t.decimalSeparator || ".", p = t.fractionGroupSeparator || "";
|
|
117
|
-
if (c && e.indexOf(c) === 0 && (e = e.slice(c.length)), u && e.lastIndexOf(u) === e.length - u.length && (e = e.slice(0, -u.length)), o && e.indexOf(o) === 0 ? (e = e.slice(o.length), r = !0) : s && e.indexOf(s) === 0 && (e = e.slice(s.length)), n = e.indexOf(f), n < 0) {
|
|
118
|
-
if (d) for (; e.indexOf(d) > -1;) e = e.replace(d, "");
|
|
119
|
-
} else {
|
|
120
|
-
if (i = e.slice(0, n), a = e.slice(n + f.length), d) for (; i.indexOf(d) > -1;) i = i.replace(d, "");
|
|
121
|
-
if (p) for (; a.indexOf(p) > -1;) a = a.replace(p, "");
|
|
122
|
-
e = i + "." + a;
|
|
123
|
-
}
|
|
124
|
-
return new z(r ? "-" + e : e);
|
|
125
|
-
}, z.isBigNumber = function(e) {
|
|
126
|
-
if (!U(e)) return !1;
|
|
127
|
-
var t, n, r = e.c, i = e.e, a = e.s;
|
|
128
|
-
if (!x(r)) return r === null && i === null && (a === null || a === 1 || a === -1);
|
|
129
|
-
if (a !== 1 && a !== -1 || i < -h || i > h || i !== c(i)) return !1;
|
|
130
|
-
if (r[0] === 0) return i === 0 && r.length === 1;
|
|
131
|
-
if (t = (i + 1) % d, t < 1 && (t += d), String(r[0]).length !== t) return !1;
|
|
132
|
-
for (t = 0; t < r.length; t++) if (n = r[t], n < 0 || n >= u || n !== c(n)) return !1;
|
|
133
|
-
return n !== 0;
|
|
134
|
-
}, z.maximum = z.max = function() {
|
|
135
|
-
return W(arguments, -1);
|
|
136
|
-
}, z.minimum = z.min = function() {
|
|
137
|
-
return W(arguments, 1);
|
|
138
|
-
}, z.random = (function() {
|
|
139
|
-
var e = 9007199254740992, t = Math.random() * e & 2097151 ? function() {
|
|
140
|
-
return c(Math.random() * e);
|
|
141
|
-
} : function() {
|
|
142
|
-
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
143
|
-
};
|
|
144
|
-
return function(e) {
|
|
145
|
-
var n, r, i, a, o, u = 0, f = [], m = new z(E);
|
|
146
|
-
if (e = e == null ? D : b(e, 0, h), a = s(e / d), N) if (crypto.getRandomValues) {
|
|
147
|
-
for (n = crypto.getRandomValues(new Uint32Array(a *= 2)); u < a;) o = n[u] * 131072 + (n[u + 1] >>> 11), o >= 9e15 ? (r = crypto.getRandomValues(new Uint32Array(2)), n[u] = r[0], n[u + 1] = r[1]) : (f.push(o % 0x5af3107a4000), u += 2);
|
|
148
|
-
u = a / 2;
|
|
149
|
-
} else if (crypto.randomBytes) {
|
|
150
|
-
for (n = crypto.randomBytes(a *= 7); u < a;) o = (n[u] & 31) * 281474976710656 + n[u + 1] * 1099511627776 + n[u + 2] * 4294967296 + n[u + 3] * 16777216 + (n[u + 4] << 16) + (n[u + 5] << 8) + n[u + 6], o >= 9e15 ? crypto.randomBytes(7).copy(n, u) : (f.push(o % 0x5af3107a4000), u += 7);
|
|
151
|
-
u = a / 7;
|
|
152
|
-
} else throw N = !1, Error(l + "crypto unavailable");
|
|
153
|
-
if (!N) for (; u < a;) o = t(), o < 9e15 && (f[u++] = o % 0x5af3107a4000);
|
|
154
|
-
for (a = f[--u], e %= d, a && e && (o = p[d - e], f[u] = c(a / o) * o); f[u] === 0; f.pop(), u--);
|
|
155
|
-
if (u < 0) f = [i = 0];
|
|
156
|
-
else {
|
|
157
|
-
for (i = -1; f[0] === 0; f.splice(0, 1), i -= d);
|
|
158
|
-
for (u = 1, o = f[0]; o >= 10; o /= 10, u++);
|
|
159
|
-
u < d && (i -= d - u);
|
|
160
|
-
}
|
|
161
|
-
return m.e = i, m.c = f, m;
|
|
162
|
-
};
|
|
163
|
-
})(), z.sum = function() {
|
|
164
|
-
for (var e = 0, t = new z(0); e < arguments.length;) t = t.plus(arguments[e++]);
|
|
165
|
-
return t;
|
|
166
|
-
};
|
|
167
|
-
function B(e, t) {
|
|
168
|
-
var n, r, i;
|
|
169
|
-
for ((n = t.indexOf(".")) > -1 && (t = t.replace(".", "")), (r = t.search(/e/i)) > 0 ? (n < 0 && (n = r), n += +t.slice(r + 1), t = t.substring(0, r)) : n < 0 && (n = t.length), r = 0; t.charCodeAt(r) === 48; r++);
|
|
170
|
-
for (i = t.length; t.charCodeAt(--i) === 48;);
|
|
171
|
-
if (t = t.slice(r, ++i)) if (i -= r, n = n - r - 1, n > M) e.c = e.e = null;
|
|
172
|
-
else if (n < j) e.c = [e.e = 0];
|
|
173
|
-
else {
|
|
174
|
-
if (e.e = n, e.c = [], r = (n + 1) % d, n < 0 && (r += d), r < i) {
|
|
175
|
-
for (r && e.c.push(+t.slice(0, r)), i -= d; r < i;) e.c.push(+t.slice(r, r += d));
|
|
176
|
-
r = d - (t = t.slice(r)).length;
|
|
177
|
-
} else r -= i;
|
|
178
|
-
for (; r--; t += "0");
|
|
179
|
-
e.c.push(+t);
|
|
180
|
-
}
|
|
181
|
-
else e.c = [e.e = 0];
|
|
182
|
-
}
|
|
183
|
-
function V(e, t, r, i) {
|
|
184
|
-
var a, o, s = R.slice(0, r), c = 0, u = "", d = !1, f = !1, p = !1;
|
|
185
|
-
for (e.s = t.charCodeAt(0) === 45 ? (t = t.slice(1), -1) : 1, o = t.length; c < o; c++) {
|
|
186
|
-
if (a = t.charAt(c), s.indexOf(a) >= 0) {
|
|
187
|
-
u += a, f = !0;
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
if (a == "_") {
|
|
191
|
-
if (f && c + 1 < o) {
|
|
192
|
-
f = !1;
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
} else if (a == ".") {
|
|
196
|
-
if (c == 0 || !d && f) {
|
|
197
|
-
if (c + 1 == o) break;
|
|
198
|
-
c == 0 && (u = "0"), u += a, d = !0, f = !1;
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
} else if (!p && (t == t.toUpperCase() && s == s.toLowerCase() && (t = t.toLowerCase()) || t == t.toLowerCase() && s == s.toUpperCase() && (t = t.toUpperCase()))) {
|
|
202
|
-
c = -1, u = "", p = !0, d = f = !1;
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
if (P) throw Error(l + "Not a base " + r + " number: " + i);
|
|
206
|
-
e.s = e.c = e.e = null;
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
B(e, n(u, r, 10, e.s));
|
|
210
|
-
}
|
|
211
|
-
n = (function() {
|
|
212
|
-
var e = "0123456789";
|
|
213
|
-
function n(e, t, n, r) {
|
|
214
|
-
for (var i, a = [0], o, s = 0, c = e.length; s < c;) {
|
|
215
|
-
for (o = a.length; o--; a[o] *= t);
|
|
216
|
-
for (a[0] += r.indexOf(e.charAt(s++)), i = 0; i < a.length; i++) a[i] > n - 1 && (a[i + 1] ?? (a[i + 1] = 0), a[i + 1] += a[i] / n | 0, a[i] %= n);
|
|
217
|
-
}
|
|
218
|
-
return a.reverse();
|
|
219
|
-
}
|
|
220
|
-
return function(r, i, a, o, s) {
|
|
221
|
-
var c, l, u, d, f, p, m, h, g = r.indexOf("."), _ = D, y = O;
|
|
222
|
-
for (g >= 0 && (d = I, I = 0, r = r.replace(".", ""), h = new z(i), p = h.pow(r.length - g), I = d, h.c = n(w(v(p.c), p.e, "0"), 10, a, e), h.e = h.c.length), m = n(r, i, a, s ? (c = R, e) : (c = e, R)), u = d = m.length; m[--d] == 0; m.pop());
|
|
223
|
-
if (!m[0]) return c.charAt(0);
|
|
224
|
-
if (g < 0 ? --u : (p.c = m, p.e = u, p.s = o, p = t(p, h, _, y, a), m = p.c, f = p.r, u = p.e), l = u + _ + 1, g = m[l], d = a / 2, f = f || l < 0 || m[l + 1] != null, f = y < 4 ? (g != null || f) && (y == 0 || y == (p.s < 0 ? 3 : 2)) : g > d || g == d && (y == 4 || f || y == 6 && m[l - 1] & 1 || y == (p.s < 0 ? 8 : 7)), l < 1 || !m[0]) r = f ? w(c.charAt(1), -_, c.charAt(0)) : c.charAt(0);
|
|
225
|
-
else {
|
|
226
|
-
if (l < m.length && (m.length = l), f) for (--a; ++m[--l] > a;) m[l] = 0, l || (++u, m = [1].concat(m));
|
|
227
|
-
for (d = m.length; !m[--d];);
|
|
228
|
-
for (g = 0, r = ""; g <= d; r += c.charAt(m[g++]));
|
|
229
|
-
r = w(r, u, c.charAt(0));
|
|
230
|
-
}
|
|
231
|
-
return r;
|
|
232
|
-
};
|
|
233
|
-
})(), t = (function() {
|
|
234
|
-
function e(e, t, n) {
|
|
235
|
-
var r, i, a, o, s = 0, c = e.length, l = t % m, u = t / m | 0;
|
|
236
|
-
for (e = e.slice(); c--;) a = e[c] % m, o = e[c] / m | 0, r = u * a + o * l, i = l * a + r % m * m + s, s = (i / n | 0) + (r / m | 0) + u * o, e[c] = i % n;
|
|
237
|
-
return s && (e = [s].concat(e)), e;
|
|
238
|
-
}
|
|
239
|
-
function t(e, t, n, r) {
|
|
240
|
-
var i, a;
|
|
241
|
-
if (n != r) a = n > r ? 1 : -1;
|
|
242
|
-
else for (i = a = 0; i < n; i++) if (e[i] != t[i]) {
|
|
243
|
-
a = e[i] > t[i] ? 1 : -1;
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
return a;
|
|
247
|
-
}
|
|
248
|
-
function n(e, t, n, r) {
|
|
249
|
-
for (var i = 0; n--;) e[n] -= i, i = +(e[n] < t[n]), e[n] = i * r + e[n] - t[n];
|
|
250
|
-
for (; !e[0] && e.length > 1; e.splice(0, 1));
|
|
251
|
-
}
|
|
252
|
-
return function(r, i, a, o, s) {
|
|
253
|
-
var l, f, p, m, h, g, v, y, b, x, S, C, w, T, E, D, O, k = r.s == i.s ? 1 : -1, A = r.c, j = i.c;
|
|
254
|
-
if (!A || !A[0] || !j || !j[0]) return new z(!r.s || !i.s || (A ? j && A[0] == j[0] : !j) ? NaN : A && A[0] == 0 || !j ? k * 0 : k / 0);
|
|
255
|
-
for (y = new z(k), b = y.c = [], f = r.e - i.e, k = a + f + 1, s || (s = u, f = _(r.e / d) - _(i.e / d), k = k / d | 0), p = 0; j[p] == (A[p] || 0); p++);
|
|
256
|
-
if (j[p] > (A[p] || 0) && f--, k < 0) b.push(1), m = !0;
|
|
257
|
-
else {
|
|
258
|
-
for (T = A.length, D = j.length, p = 0, k += 2, h = c(s / (j[0] + 1)), h > 1 && (j = e(j, h, s), A = e(A, h, s), D = j.length, T = A.length), w = D, x = A.slice(0, D), S = x.length; S < D; x[S++] = 0);
|
|
259
|
-
O = j.slice(), O = [0].concat(O), E = j[0], j[1] >= s / 2 && E++;
|
|
260
|
-
do {
|
|
261
|
-
if (h = 0, l = t(j, x, D, S), l < 0) {
|
|
262
|
-
if (C = x[0], D != S && (C = C * s + (x[1] || 0)), h = c(C / E), h > 1) for (h >= s && (h = s - 1), g = e(j, h, s), v = g.length, S = x.length; t(g, x, v, S) == 1;) h--, n(g, D < v ? O : j, v, s), v = g.length, l = 1;
|
|
263
|
-
else h == 0 && (l = h = 1), g = j.slice(), v = g.length;
|
|
264
|
-
if (v < S && (g = [0].concat(g)), n(x, g, S, s), S = x.length, l == -1) for (; t(j, x, D, S) < 1;) h++, n(x, D < S ? O : j, S, s), S = x.length;
|
|
265
|
-
} else l === 0 && (h++, x = [0]);
|
|
266
|
-
b[p++] = h, x[0] ? x[S++] = A[w] || 0 : (x = [A[w]], S = 1);
|
|
267
|
-
} while ((w++ < T || x[0] != null) && k--);
|
|
268
|
-
m = x[0] != null, b[0] || b.splice(0, 1);
|
|
269
|
-
}
|
|
270
|
-
if (s == u) {
|
|
271
|
-
for (p = 1, k = b[0]; k >= 10; k /= 10, p++);
|
|
272
|
-
q(y, a + (y.e = p + f * d - 1) + 1, o, m);
|
|
273
|
-
} else y.e = f, y.r = +m;
|
|
274
|
-
return y;
|
|
275
|
-
};
|
|
276
|
-
})();
|
|
277
|
-
function H(e, t, n, r) {
|
|
278
|
-
var i, a, o, s, c;
|
|
279
|
-
if (n = n == null ? O : b(n, 0, 8), !e.c) return e.toString();
|
|
280
|
-
if (i = e.c[0], o = e.e, t == null) c = v(e.c), c = r == 1 || r == 2 && (o <= k || o >= A) ? C(c, o) : w(c, o, "0");
|
|
281
|
-
else if (e = q(new z(e), t, n), a = e.e, c = v(e.c), s = c.length, r == 1 || r == 2 && (t <= a || a <= k)) {
|
|
282
|
-
for (; s < t; c += "0", s++);
|
|
283
|
-
c = C(c, a);
|
|
284
|
-
} else if (t -= o + (r === 2 && a > o), c = w(c, a, "0"), a + 1 > s) {
|
|
285
|
-
if (--t > 0) for (c += "."; t--; c += "0");
|
|
286
|
-
} else if (t += a - s, t > 0) for (a + 1 == s && (c += "."); t--; c += "0");
|
|
287
|
-
return e.s < 0 && i ? "-" + c : c;
|
|
288
|
-
}
|
|
289
|
-
function U(e) {
|
|
290
|
-
return e instanceof z || !!e && e._isBigNumber === !0;
|
|
291
|
-
}
|
|
292
|
-
function W(e, t) {
|
|
293
|
-
for (var n, r, i = 1, a = new z(e[0]); i < e.length; i++) r = new z(e[i]), (!r.s || (n = y(a, r)) === t || n === 0 && a.s === t) && (a = r);
|
|
294
|
-
return a;
|
|
295
|
-
}
|
|
296
|
-
function G(e, t, n) {
|
|
297
|
-
for (var r = 1, i = t.length; !t[--i]; t.pop());
|
|
298
|
-
for (i = t[0]; i >= 10; i /= 10, r++);
|
|
299
|
-
return (n = r + n * d - 1) > M ? e.c = e.e = null : n < j ? e.c = [e.e = 0] : (e.e = n, e.c = t), e;
|
|
300
|
-
}
|
|
301
|
-
function K(e) {
|
|
302
|
-
var t, n = {};
|
|
303
|
-
for (t in L) L.hasOwnProperty(t) && (n[t] = e.hasOwnProperty(t) ? e[t] : L[t]);
|
|
304
|
-
return n;
|
|
305
|
-
}
|
|
306
|
-
function q(e, t, n, r) {
|
|
307
|
-
var i, a, o, l, f, m, h, g = e.c, _ = p;
|
|
308
|
-
if (g) {
|
|
309
|
-
out: {
|
|
310
|
-
for (i = 1, l = g[0]; l >= 10; l /= 10, i++);
|
|
311
|
-
if (a = t - i, a < 0) a += d, o = t, f = g[m = 0], h = c(f / _[i - o - 1] % 10);
|
|
312
|
-
else if (m = s((a + 1) / d), m >= g.length) if (r) {
|
|
313
|
-
for (; g.length <= m; g.push(0));
|
|
314
|
-
f = h = 0, i = 1, a %= d, o = a - d + 1;
|
|
315
|
-
} else break out;
|
|
316
|
-
else {
|
|
317
|
-
for (f = l = g[m], i = 1; l >= 10; l /= 10, i++);
|
|
318
|
-
a %= d, o = a - d + i, h = o < 0 ? 0 : c(f / _[i - o - 1] % 10);
|
|
319
|
-
}
|
|
320
|
-
if (r = r || t < 0 || g[m + 1] != null || (o < 0 ? f : f % _[i - o - 1]), r = n < 4 ? (h || r) && (n == 0 || n == (e.s < 0 ? 3 : 2)) : h > 5 || h == 5 && (n == 4 || r || n == 6 && (a > 0 ? o > 0 ? f / _[i - o] : 0 : g[m - 1]) % 10 & 1 || n == (e.s < 0 ? 8 : 7)), t < 1 || !g[0]) return g.length = 0, r ? (t -= e.e + 1, g[0] = _[(d - t % d) % d], e.e = -t || 0) : g[0] = e.e = 0, e;
|
|
321
|
-
if (a == 0 ? (g.length = m, l = 1, m--) : (g.length = m + 1, l = _[d - a], g[m] = o > 0 ? c(f / _[i - o] % _[o]) * l : 0), r) for (;;) if (m == 0) {
|
|
322
|
-
for (a = 1, o = g[0]; o >= 10; o /= 10, a++);
|
|
323
|
-
for (o = g[0] += l, l = 1; o >= 10; o /= 10, l++);
|
|
324
|
-
a != l && (e.e++, g[0] == u && (g[0] = 1));
|
|
325
|
-
break;
|
|
326
|
-
} else {
|
|
327
|
-
if (g[m] += l, g[m] != u) break;
|
|
328
|
-
g[m--] = 0, l = 1;
|
|
329
|
-
}
|
|
330
|
-
for (a = g.length; g[--a] === 0; g.pop());
|
|
331
|
-
}
|
|
332
|
-
e.e > M ? e.c = e.e = null : e.e < j && (e.c = [e.e = 0]);
|
|
333
|
-
}
|
|
334
|
-
return e;
|
|
335
|
-
}
|
|
336
|
-
function J(e) {
|
|
337
|
-
var t, n = e.e;
|
|
338
|
-
return n === null ? e.toString() : (t = v(e.c), t = n <= k || n >= A ? C(t, n) : w(t, n, "0"), e.s < 0 ? "-" + t : t);
|
|
339
|
-
}
|
|
340
|
-
return T.absoluteValue = T.abs = function() {
|
|
341
|
-
var e = new z(this);
|
|
342
|
-
return e.s < 0 && (e.s = 1), e;
|
|
343
|
-
}, T.comparedTo = function(e, t) {
|
|
344
|
-
return y(this, new z(e, t));
|
|
345
|
-
}, T.decimalPlaces = T.dp = function(e, t) {
|
|
346
|
-
var n, r, i, a = this;
|
|
347
|
-
if (e != null) return q(new z(a), b(e, -h, h) + a.e + 1, t == null ? O : b(t, 0, 8));
|
|
348
|
-
if (!(n = a.c)) return null;
|
|
349
|
-
if (r = ((i = n.length - 1) - _(this.e / d)) * d, i = n[i]) for (; i % 10 == 0; i /= 10, r--);
|
|
350
|
-
return r < 0 && (r = 0), r;
|
|
351
|
-
}, T.dividedBy = T.div = function(e, n) {
|
|
352
|
-
return t(this, new z(e, n), D, O);
|
|
353
|
-
}, T.dividedToIntegerBy = T.idiv = function(e, n) {
|
|
354
|
-
return t(this, new z(e, n), 0, 1);
|
|
355
|
-
}, T.exponentiatedBy = T.pow = function(e, t) {
|
|
356
|
-
var n, r, i, a, o, u, f, p, m, h = this;
|
|
357
|
-
if (e = new z(e), e.c && !e.isInteger()) throw Error(l + "Exponent not an integer: " + J(e));
|
|
358
|
-
if (t != null && (t = new z(t)), u = e.e > 14, !h.c || !h.c[0] || h.c[0] == 1 && !h.e && h.c.length == 1 || !e.c || !e.c[0]) return m = new z(J(h) ** (u ? e.s * (2 - S(e)) : +J(e))), t ? m.mod(t) : m;
|
|
359
|
-
if (f = e.s < 0, t) {
|
|
360
|
-
if (t.c ? !t.c[0] : !t.s) return new z(NaN);
|
|
361
|
-
r = !f && h.isInteger() && t.isInteger(), r && (h = h.mod(t));
|
|
362
|
-
} else if (e.e > 9 && (h.e > 0 || h.e < -1 || (h.e == 0 ? h.c[0] > 1 || u && h.c[1] >= 24e7 : h.c[0] < 8e13 || u && h.c[0] <= 9999975e7))) return a = h.s < 0 && S(e) ? -0 : 0, h.e > -1 && (a = 1 / a), new z(f ? 1 / a : a);
|
|
363
|
-
else I && (a = s(I / d + 2));
|
|
364
|
-
for (u ? (n = new z(.5), f && (e.s = 1), p = S(e)) : (i = Math.abs(+J(e)), p = i % 2), m = new z(E);;) {
|
|
365
|
-
if (p) {
|
|
366
|
-
if (m = m.times(h), !m.c) break;
|
|
367
|
-
a ? m.c.length > a && (m.c.length = a) : r && (m = m.mod(t));
|
|
368
|
-
}
|
|
369
|
-
if (i) {
|
|
370
|
-
if (i = c(i / 2), i === 0) break;
|
|
371
|
-
p = i % 2;
|
|
372
|
-
} else if (e = e.times(n), q(e, e.e + 1, 1), e.e > 14) p = S(e);
|
|
373
|
-
else {
|
|
374
|
-
if (i = +J(e), i === 0) break;
|
|
375
|
-
p = i % 2;
|
|
376
|
-
}
|
|
377
|
-
h = h.times(h), a ? h.c && h.c.length > a && (h.c.length = a) : r && (h = h.mod(t));
|
|
378
|
-
}
|
|
379
|
-
return r ? m : (f && (m = E.div(m)), t ? m.mod(t) : a ? q(m, I, O, o) : m);
|
|
380
|
-
}, T.integerValue = function(e) {
|
|
381
|
-
var t = new z(this);
|
|
382
|
-
return q(t, t.e + 1, e == null ? O : b(e, 0, 8));
|
|
383
|
-
}, T.isEqualTo = T.eq = function(e, t) {
|
|
384
|
-
return y(this, new z(e, t)) === 0;
|
|
385
|
-
}, T.isFinite = function() {
|
|
386
|
-
return !!this.c;
|
|
387
|
-
}, T.isGreaterThan = T.gt = function(e, t) {
|
|
388
|
-
return y(this, new z(e, t)) > 0;
|
|
389
|
-
}, T.isGreaterThanOrEqualTo = T.gte = function(e, t) {
|
|
390
|
-
return (t = y(this, new z(e, t))) === 1 || t === 0;
|
|
391
|
-
}, T.isInteger = function() {
|
|
392
|
-
return !!this.c && _(this.e / d) > this.c.length - 2;
|
|
393
|
-
}, T.isLessThan = T.lt = function(e, t) {
|
|
394
|
-
return y(this, new z(e, t)) < 0;
|
|
395
|
-
}, T.isLessThanOrEqualTo = T.lte = function(e, t) {
|
|
396
|
-
return (t = y(this, new z(e, t))) === -1 || t === 0;
|
|
397
|
-
}, T.isNaN = function() {
|
|
398
|
-
return !this.s;
|
|
399
|
-
}, T.isNegative = function() {
|
|
400
|
-
return this.s < 0;
|
|
401
|
-
}, T.isPositive = function() {
|
|
402
|
-
return this.s > 0;
|
|
403
|
-
}, T.isZero = function() {
|
|
404
|
-
return !!this.c && this.c[0] == 0;
|
|
405
|
-
}, T.minus = function(e, t) {
|
|
406
|
-
var n, r, i, a, o = this, s = o.s;
|
|
407
|
-
if (e = new z(e, t), t = e.s, !s || !t) return new z(NaN);
|
|
408
|
-
if (s != t) return e.s = -t, o.plus(e);
|
|
409
|
-
var c = o.e / d, l = e.e / d, f = o.c, p = e.c;
|
|
410
|
-
if (!c || !l) {
|
|
411
|
-
if (!f || !p) return f ? (e.s = -t, e) : new z(p ? o : NaN);
|
|
412
|
-
if (!f[0] || !p[0]) return p[0] ? (e.s = -t, e) : new z(f[0] ? o : O == 3 ? -0 : 0);
|
|
413
|
-
}
|
|
414
|
-
if (c = _(c), l = _(l), f = f.slice(), s = c - l) {
|
|
415
|
-
for ((a = s < 0) ? (s = -s, i = f) : (l = c, i = p), i.reverse(), t = s; t--; i.push(0));
|
|
416
|
-
i.reverse();
|
|
417
|
-
} else for (r = (a = (s = f.length) < (t = p.length)) ? s : t, s = t = 0; t < r; t++) if (f[t] != p[t]) {
|
|
418
|
-
a = f[t] < p[t];
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
421
|
-
if (a && (i = f, f = p, p = i, e.s = -e.s), t = (r = p.length) - (n = f.length), t > 0) for (; t--; f[n++] = 0);
|
|
422
|
-
for (t = u - 1; r > s;) {
|
|
423
|
-
if (f[--r] < p[r]) {
|
|
424
|
-
for (n = r; n && !f[--n]; f[n] = t);
|
|
425
|
-
--f[n], f[r] += u;
|
|
426
|
-
}
|
|
427
|
-
f[r] -= p[r];
|
|
428
|
-
}
|
|
429
|
-
for (; f[0] == 0; f.splice(0, 1), --l);
|
|
430
|
-
return f[0] ? G(e, f, l) : (e.s = O == 3 ? -1 : 1, e.c = [e.e = 0], e);
|
|
431
|
-
}, T.modulo = T.mod = function(e, n) {
|
|
432
|
-
var r, i, a = this;
|
|
433
|
-
return e = new z(e, n), !a.c || !e.s || e.c && !e.c[0] ? new z(NaN) : !e.c || a.c && !a.c[0] ? new z(a) : (F == 9 ? (i = e.s, e.s = 1, r = t(a, e, 0, 3), e.s = i, r.s *= i) : r = t(a, e, 0, F), e = a.minus(r.times(e)), !e.c[0] && F == 1 && (e.s = a.s), e);
|
|
434
|
-
}, T.multipliedBy = T.times = function(e, t) {
|
|
435
|
-
var n, r, i, a, o, s, c, l, f, p, h, g, v, y, b, x = this, S = x.c, C = (e = new z(e, t)).c;
|
|
436
|
-
if (!S || !C || !S[0] || !C[0]) return !x.s || !e.s || S && !S[0] && !C || C && !C[0] && !S ? e.c = e.e = e.s = null : (e.s *= x.s, !S || !C ? e.c = e.e = null : (e.c = [0], e.e = 0)), e;
|
|
437
|
-
for (r = _(x.e / d) + _(e.e / d), e.s *= x.s, c = S.length, p = C.length, c < p && (v = S, S = C, C = v, i = c, c = p, p = i), i = c + p, v = []; i--; v.push(0));
|
|
438
|
-
for (y = u, b = m, i = p; --i >= 0;) {
|
|
439
|
-
for (n = 0, h = C[i] % b, g = C[i] / b | 0, o = c, a = i + o; a > i;) l = S[--o] % b, f = S[o] / b | 0, s = g * l + f * h, l = h * l + s % b * b + v[a] + n, n = (l / y | 0) + (s / b | 0) + g * f, v[a--] = l % y;
|
|
440
|
-
v[a] = n;
|
|
441
|
-
}
|
|
442
|
-
return n ? ++r : v.splice(0, 1), G(e, v, r);
|
|
443
|
-
}, T.negated = function() {
|
|
444
|
-
var e = new z(this);
|
|
445
|
-
return e.s = -e.s || null, e;
|
|
446
|
-
}, T.plus = function(e, t) {
|
|
447
|
-
var n, r = this, i = r.s;
|
|
448
|
-
if (e = new z(e, t), t = e.s, !i || !t) return new z(NaN);
|
|
449
|
-
if (i != t) return e.s = -t, r.minus(e);
|
|
450
|
-
var a = r.e / d, o = e.e / d, s = r.c, c = e.c;
|
|
451
|
-
if (!a || !o) {
|
|
452
|
-
if (!s || !c) return new z(i / 0);
|
|
453
|
-
if (!s[0] || !c[0]) return c[0] ? e : new z(s[0] ? r : i * 0);
|
|
454
|
-
}
|
|
455
|
-
if (a = _(a), o = _(o), s = s.slice(), i = a - o) {
|
|
456
|
-
for (i > 0 ? (o = a, n = c) : (i = -i, n = s), n.reverse(); i--; n.push(0));
|
|
457
|
-
n.reverse();
|
|
458
|
-
}
|
|
459
|
-
for (i = s.length, t = c.length, i - t < 0 && (n = c, c = s, s = n, t = i), i = 0; t;) i = (s[--t] = s[t] + c[t] + i) / u | 0, s[t] = u === s[t] ? 0 : s[t] % u;
|
|
460
|
-
return i && (s = [i].concat(s), ++o), G(e, s, o);
|
|
461
|
-
}, T.precision = T.sd = function(e, t) {
|
|
462
|
-
var n, r, i, a = this;
|
|
463
|
-
if (e != null && e !== !!e) return q(new z(a), b(e, 1, h), t == null ? O : b(t, 0, 8));
|
|
464
|
-
if (!(n = a.c)) return null;
|
|
465
|
-
if (i = n.length - 1, r = i * d + 1, i = n[i]) {
|
|
466
|
-
for (; i % 10 == 0; i /= 10, r--);
|
|
467
|
-
for (i = n[0]; i >= 10; i /= 10, r++);
|
|
468
|
-
}
|
|
469
|
-
return e && a.e + 1 > r && (r = a.e + 1), r;
|
|
470
|
-
}, T.shiftedBy = function(e) {
|
|
471
|
-
return this.times("1e" + b(e, -f, f));
|
|
472
|
-
}, T.squareRoot = T.sqrt = function() {
|
|
473
|
-
var e, n, r, i, a, o = this, s = o.c, c = o.s, l = o.e, u = D + 4, d = new z("0.5");
|
|
474
|
-
if (c !== 1 || !s || !s[0]) return new z(!c || c < 0 && (!s || s[0]) ? NaN : s ? o : Infinity);
|
|
475
|
-
if (c = Math.sqrt(+J(o)), c == 0 || c == Infinity ? (n = v(s), (n.length + l) % 2 == 0 && (n += "0"), c = Math.sqrt(+n), l = _((l + 1) / 2) - (l < 0 || l % 2), c == Infinity ? n = "5e" + l : (n = c.toExponential(), n = n.slice(0, n.indexOf("e") + 1) + l), r = new z(n)) : r = new z(c + ""), r.c[0]) {
|
|
476
|
-
for (l = r.e, c = l + u, c < 3 && (c = 0);;) if (a = r, r = d.times(a.plus(t(o, a, u, 1))), v(a.c).slice(0, c) === (n = v(r.c)).slice(0, c)) if (r.e < l && --c, n = n.slice(c - 3, c + 1), n == "9999" || !i && n == "4999") {
|
|
477
|
-
if (!i && (q(a, a.e + D + 2, 0), a.times(a).eq(o))) {
|
|
478
|
-
r = a;
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
u += 4, c += 4, i = 1;
|
|
482
|
-
} else {
|
|
483
|
-
(!+n || !+n.slice(1) && n.charAt(0) == "5") && (q(r, r.e + D + 2, 1), e = !r.times(r).eq(o));
|
|
484
|
-
break;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
return q(r, r.e + D + 1, O, e);
|
|
488
|
-
}, typeof BigInt == "function" && (T.toBigInt = function(e) {
|
|
489
|
-
var t = this;
|
|
490
|
-
return t.c ? BigInt(H(t, t.e + 1, e)) : null;
|
|
491
|
-
}), T.toExponential = function(e, t) {
|
|
492
|
-
return H(this, e == null ? e : b(e, 0, h) + 1, t, 1);
|
|
493
|
-
}, T.toFixed = function(e, t) {
|
|
494
|
-
return H(this, e == null ? e : b(e, -h, h) + this.e + 1, t);
|
|
495
|
-
}, T.toFormat = function(e, t, n) {
|
|
496
|
-
var r, i, a, o, s = this;
|
|
497
|
-
if (n == null) n = L, e != null && (t == null ? typeof e == "object" && !x(e) && (n = K(e), e = t = null) : typeof t == "object" && (n = K(t), t = null));
|
|
498
|
-
else if (typeof n != "object") throw Error(l + "Argument not an object: " + n);
|
|
499
|
-
else n = K(n);
|
|
500
|
-
if (e != null) if (x(e) && e.length <= 2) {
|
|
501
|
-
if (i = e[0], a = e[1], e = s.dp(), a != null && e > b(a, 0, h) && (e = a), i != null && b(i, 0, h) !== 0) {
|
|
502
|
-
if (a != null && i > a) throw Error(l + "Minimum must not exceed maximum");
|
|
503
|
-
e < i && (e = i);
|
|
504
|
-
}
|
|
505
|
-
} else b(e, -h, h);
|
|
506
|
-
if (o = s.toFixed(e, t), r = o.charCodeAt(0) === 45, r && (o = o.slice(1)), s.c) {
|
|
507
|
-
var c, u = o.split("."), d = +n.groupSize, f = +n.secondaryGroupSize, p = n.groupSeparator || "", m = u[0], g = u[1], _ = m.length;
|
|
508
|
-
if (f && (c = d, d = f, f = c, _ -= c), d > 0 && _ > 0) {
|
|
509
|
-
for (c = _ % d || d, o = m.substr(0, c); c < _; c += d) o += p + m.substr(c, d);
|
|
510
|
-
f > 0 && (o += p + m.slice(c));
|
|
511
|
-
}
|
|
512
|
-
g && (c = +n.fractionGroupSize, c && (g = g.replace(RegExp("\\d{" + c + "}\\B", "g"), "$&" + (n.fractionGroupSeparator || ""))), o += (n.decimalSeparator || "") + g);
|
|
513
|
-
}
|
|
514
|
-
return (n.prefix || "") + (r ? n.negativeSign || "" : s.s > 0 && n.positiveSign || "") + o + (n.suffix || "");
|
|
515
|
-
}, T.toFraction = function(e) {
|
|
516
|
-
var n, r, i, a, o, s, c, u, f, m, h, g, _ = this, y = _.c;
|
|
517
|
-
if (e != null && (c = new z(e), !c.isInteger() && (c.c || c.s !== 1) || c.lt(E))) throw Error(l + "Argument " + (c.isInteger() ? "out of range: " : "not an integer: ") + J(c));
|
|
518
|
-
if (!y) return [new z(_.s || 0), new z(0)];
|
|
519
|
-
for (n = new z(E), f = r = new z(E), i = u = new z(E), g = v(y), o = n.e = g.length - _.e - 1, n.c[0] = p[(s = o % d) < 0 ? d + s : s], e = !e || c.comparedTo(n) > 0 ? o > 0 ? n : f : c, s = M, M = Infinity, c = new z(g), u.c[0] = 0; m = t(c, n, 0, 1), a = r.plus(m.times(i)), a.comparedTo(e) != 1;) r = i, i = a, f = u.plus(m.times(a = f)), u = a, n = c.minus(m.times(a = n)), c = a;
|
|
520
|
-
return a = t(e.minus(r), i, 0, 1), u = u.plus(a.times(f)), r = r.plus(a.times(i)), u.s = f.s = _.s, o *= 2, h = t(f, i, o, O).minus(_).abs().comparedTo(t(u, r, o, O).minus(_).abs()) < 1 ? [f, i] : [u, r], M = s, h;
|
|
521
|
-
}, T.toNumber = function() {
|
|
522
|
-
return +J(this);
|
|
523
|
-
}, T.toObject = function() {
|
|
524
|
-
var e = this;
|
|
525
|
-
return {
|
|
526
|
-
c: e.c ? e.c.slice() : null,
|
|
527
|
-
e: e.e,
|
|
528
|
-
s: e.s
|
|
529
|
-
};
|
|
530
|
-
}, T.toPrecision = function(e, t) {
|
|
531
|
-
return H(this, e == null ? e : b(e, 1, h), t, 2);
|
|
532
|
-
}, T.toString = function(e) {
|
|
533
|
-
var t, r = this, i = r.s, a = r.e;
|
|
534
|
-
return a === null ? i ? (t = "Infinity", i < 0 && (t = "-" + t)) : t = "NaN" : (e == null ? t = a <= k || a >= A ? C(v(r.c), a) : w(v(r.c), a, "0") : (b(e, 2, R.length, "Base"), t = n(w(v(r.c), a, "0"), 10, e, i, !0)), i < 0 && r.c[0] && (t = "-" + t)), t;
|
|
535
|
-
}, T.valueOf = T.toJSON = function() {
|
|
536
|
-
return J(this);
|
|
537
|
-
}, T._isBigNumber = !0, e != null && z.set(e), z;
|
|
538
|
-
}
|
|
539
|
-
function _(e) {
|
|
540
|
-
var t = e | 0;
|
|
541
|
-
return e > 0 || e === t ? t : t - 1;
|
|
542
|
-
}
|
|
543
|
-
function v(e) {
|
|
544
|
-
for (var t, n, r = 1, i = e.length, a = e[0] + ""; r < i;) {
|
|
545
|
-
for (t = e[r++] + "", n = d - t.length; n--; t = "0" + t);
|
|
546
|
-
a += t;
|
|
547
|
-
}
|
|
548
|
-
for (i = a.length; a.charCodeAt(--i) === 48;);
|
|
549
|
-
return a.slice(0, i + 1 || 1);
|
|
550
|
-
}
|
|
551
|
-
function y(e, t) {
|
|
552
|
-
var n, r, i = e.c, a = t.c, o = e.s, s = t.s, c = e.e, l = t.e;
|
|
553
|
-
if (!o || !s) return null;
|
|
554
|
-
if (n = i && !i[0], r = a && !a[0], n || r) return n ? r ? 0 : -s : o;
|
|
555
|
-
if (o != s) return o;
|
|
556
|
-
if (n = o < 0, r = c == l, !i || !a) return r ? 0 : !i ^ n ? 1 : -1;
|
|
557
|
-
if (!r) return c > l ^ n ? 1 : -1;
|
|
558
|
-
for (s = (c = i.length) < (l = a.length) ? c : l, o = 0; o < s; o++) if (i[o] != a[o]) return i[o] > a[o] ^ n ? 1 : -1;
|
|
559
|
-
return c == l ? 0 : c > l ^ n ? 1 : -1;
|
|
560
|
-
}
|
|
561
|
-
function b(e, t, n, r) {
|
|
562
|
-
if (e < t || e > n || e !== c(e)) throw Error(l + (r || "Argument") + (typeof e == "number" ? e < t || e > n ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(e));
|
|
563
|
-
return e;
|
|
564
|
-
}
|
|
565
|
-
function x(e) {
|
|
566
|
-
return {}.toString.call(e) == "[object Array]";
|
|
567
|
-
}
|
|
568
|
-
function S(e) {
|
|
569
|
-
var t = e.c.length - 1;
|
|
570
|
-
return _(e.e / d) == t && e.c[t] % 2 != 0;
|
|
571
|
-
}
|
|
572
|
-
function C(e, t) {
|
|
573
|
-
return (e.length > 1 ? e.charAt(0) + "." + e.slice(1) : e) + (t < 0 ? "e" : "e+") + t;
|
|
574
|
-
}
|
|
575
|
-
function w(e, t, n) {
|
|
576
|
-
var r, i;
|
|
577
|
-
if (t < 0) {
|
|
578
|
-
for (i = n + "."; ++t; i += n);
|
|
579
|
-
e = i + e;
|
|
580
|
-
} else if (r = e.length, ++t > r) {
|
|
581
|
-
for (i = n, t -= r; --t; i += n);
|
|
582
|
-
e += i;
|
|
583
|
-
} else t < r && (e = e.slice(0, t) + "." + e.slice(t));
|
|
584
|
-
return e;
|
|
585
|
-
}
|
|
586
|
-
//#endregion
|
|
587
|
-
//#region ../../node_modules/.pnpm/@gera2ld+common@0.0.20/node_modules/@gera2ld/common/dist/index.js
|
|
588
|
-
var T = "=", E = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
589
|
-
function D(e, t, n) {
|
|
590
|
-
let r = "", i = 0;
|
|
591
|
-
for (; i < e.length;) {
|
|
592
|
-
let a = e[i++], o = e[i++], s = e[i++];
|
|
593
|
-
if (r += t[a >> 2], r += t[(a & 3) << 4 | (o || 0) >> 4], o == null ? n && (r += T) : r += t[(o & 15) << 2 | (s || 0) >> 6], s == null) {
|
|
594
|
-
n && (r += T);
|
|
595
|
-
break;
|
|
596
|
-
}
|
|
597
|
-
r += t[s & 63];
|
|
598
|
-
}
|
|
599
|
-
return r;
|
|
600
|
-
}
|
|
601
|
-
function O(e) {
|
|
602
|
-
return D(e, E, !0);
|
|
603
|
-
}
|
|
604
|
-
new Uint8Array([13, 10]);
|
|
605
|
-
var k = class extends Error {
|
|
606
|
-
constructor(e, t, n, r) {
|
|
607
|
-
super(e, { cause: r }), this.request = t, this.response = n;
|
|
608
|
-
}
|
|
1
|
+
import { ensureAccessToken as C, OAuth2Authorizers as _, OAuth2Error as B, OAUTH2_UNAUTHORIZED as N, OAUTH2_NEED_REFRESH as M } from "@usync/oauth2";
|
|
2
|
+
import { XMLParser as j } from "fast-xml-parser";
|
|
3
|
+
var U = "=", G = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4
|
+
function J(r, e, t) {
|
|
5
|
+
let s = "", n = 0;
|
|
6
|
+
for (; n < r.length; ) {
|
|
7
|
+
let o = r[n++], i = r[n++], a = r[n++];
|
|
8
|
+
if (s += e[o >> 2], s += e[(o & 3) << 4 | (i || 0) >> 4], i == null ? s += U : s += e[(i & 15) << 2 | (a || 0) >> 6], a == null) {
|
|
9
|
+
s += U;
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
s += e[a & 63];
|
|
13
|
+
}
|
|
14
|
+
return s;
|
|
15
|
+
}
|
|
16
|
+
function Q(r) {
|
|
17
|
+
return J(r, G);
|
|
18
|
+
}
|
|
19
|
+
var A = class extends Error {
|
|
20
|
+
constructor(r, e, t, s) {
|
|
21
|
+
super(r, { cause: s }), this.request = e, this.response = t;
|
|
22
|
+
}
|
|
609
23
|
};
|
|
610
|
-
function
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
function
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
|
|
24
|
+
function X(r) {
|
|
25
|
+
let e = new URLSearchParams();
|
|
26
|
+
return Array.isArray(r) || r instanceof URLSearchParams ? new URLSearchParams(r).forEach((t, s) => {
|
|
27
|
+
e.append(s, t);
|
|
28
|
+
}) : r && Object.entries(r).forEach(([t, s]) => {
|
|
29
|
+
if (Array.isArray(s)) {
|
|
30
|
+
let n = t.endsWith("[]") ? t : `${t}[]`;
|
|
31
|
+
s.forEach((o) => {
|
|
32
|
+
e.append(n, o);
|
|
33
|
+
});
|
|
34
|
+
} else e.append(t, s);
|
|
35
|
+
}), e;
|
|
36
|
+
}
|
|
37
|
+
function w(r, e) {
|
|
38
|
+
let { json: t, timeout: s = 1e4, searchParams: n, ...o } = e || {}, i = new AbortController(), a = s ? setTimeout(() => i.abort(), s) : null, c = new Headers(o.headers);
|
|
39
|
+
t != null && (o.body = JSON.stringify(t), c.set("content-type", "application/json"));
|
|
40
|
+
let h = new URL(r);
|
|
41
|
+
n && (h.search = X(n).toString());
|
|
42
|
+
async function p(l) {
|
|
43
|
+
let u;
|
|
44
|
+
try {
|
|
45
|
+
u = await fetch(h, {
|
|
46
|
+
...o,
|
|
47
|
+
headers: c,
|
|
48
|
+
signal: i.signal
|
|
49
|
+
});
|
|
50
|
+
let d = await l(u);
|
|
51
|
+
if (!u.ok) throw new A(u.statusText, {
|
|
52
|
+
url: h.toString(),
|
|
53
|
+
method: o.method || "GET",
|
|
54
|
+
options: e
|
|
55
|
+
}, u, d);
|
|
56
|
+
return d;
|
|
57
|
+
} catch (d) {
|
|
58
|
+
throw d instanceof A ? d : new A(d?.message || `${d}`, {
|
|
59
|
+
url: h.toString(),
|
|
60
|
+
method: o.method || "GET",
|
|
61
|
+
options: e
|
|
62
|
+
}, u, d);
|
|
63
|
+
} finally {
|
|
64
|
+
a && clearTimeout(a);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
async arrayBuffer() {
|
|
69
|
+
return p((l) => l.arrayBuffer());
|
|
70
|
+
},
|
|
71
|
+
async blob() {
|
|
72
|
+
return p((l) => l.blob());
|
|
73
|
+
},
|
|
74
|
+
async json() {
|
|
75
|
+
return c.has("accept") || c.set("accept", "application/json"), p((l) => l.json());
|
|
76
|
+
},
|
|
77
|
+
async text() {
|
|
78
|
+
return p((l) => l.text());
|
|
79
|
+
},
|
|
80
|
+
abort() {
|
|
81
|
+
i.abort();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function Y(r) {
|
|
86
|
+
return new Promise((e) => setTimeout(e, r));
|
|
87
|
+
}
|
|
88
|
+
function $(r) {
|
|
89
|
+
let e = 0;
|
|
90
|
+
return async (t, s) => {
|
|
91
|
+
let n = e, o;
|
|
92
|
+
for (let i = 5; i > 0; i -= 1) {
|
|
93
|
+
await Y(n);
|
|
94
|
+
try {
|
|
95
|
+
const a = await r(t, s);
|
|
96
|
+
return e >>= 1, a;
|
|
97
|
+
} catch (a) {
|
|
98
|
+
if (o = a, a instanceof A && a.response?.status === 429) {
|
|
99
|
+
const c = a.response.headers.get("retry-after"), h = c && (isNaN(+c) ? new Date(c).getTime() - Date.now() : +c * 1e3);
|
|
100
|
+
h ? n = h : (n = Math.max(1e3, n * 2), e = n);
|
|
101
|
+
} else
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
throw o;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function Z(r, e) {
|
|
109
|
+
if (!r) throw new Error("Invalid authorizer");
|
|
110
|
+
return (t) => async (s, n) => {
|
|
111
|
+
const { headers: o, ...i } = n, a = new Headers(o), c = await C(r, e);
|
|
112
|
+
return a.set("authorization", `Bearer ${c}`), await t(s, {
|
|
113
|
+
...i,
|
|
114
|
+
headers: a
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
class V {
|
|
119
|
+
}
|
|
120
|
+
class T extends V {
|
|
121
|
+
constructor(e, t) {
|
|
122
|
+
super(), this.authConfig = e, this.context = t, this.request = this.initRequest();
|
|
123
|
+
}
|
|
124
|
+
initRequest() {
|
|
125
|
+
let e = async (n, o) => {
|
|
126
|
+
const { responseType: i, ...a } = o;
|
|
127
|
+
return await w(new URL(n, this.baseUrl), a)[i]();
|
|
128
|
+
};
|
|
129
|
+
const { authorizer: t, handleOAuth2: s } = this.context;
|
|
130
|
+
return e = Z(
|
|
131
|
+
t,
|
|
132
|
+
s
|
|
133
|
+
)(e), e = $(e), e;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function ee(r, e) {
|
|
137
|
+
return typeof e == "string" ? e.replace(/[^\x00-\x7F]/g, function(t) {
|
|
138
|
+
return "\\u" + t.codePointAt(0).toString(16).padStart(4, "0");
|
|
139
|
+
}) : e;
|
|
140
|
+
}
|
|
141
|
+
class te extends T {
|
|
142
|
+
normalizeEntry(e) {
|
|
143
|
+
return {
|
|
144
|
+
kind: e[".tag"] === "file" ? "file" : "folder",
|
|
145
|
+
id: e.id,
|
|
146
|
+
name: e.name,
|
|
147
|
+
size: e.size || 0,
|
|
148
|
+
modifiedTime: e.server_modified || ""
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
getDropboxPath(e, t) {
|
|
152
|
+
if (e?.id) return `id:${e.id}`;
|
|
153
|
+
const s = e?.path;
|
|
154
|
+
if (s?.[0] === "/") return s;
|
|
155
|
+
if (
|
|
156
|
+
// Invalid path
|
|
157
|
+
s || // Empty path
|
|
158
|
+
!t
|
|
159
|
+
)
|
|
160
|
+
throw new Error("Invalid path");
|
|
161
|
+
return "";
|
|
162
|
+
}
|
|
163
|
+
async getAccount() {
|
|
164
|
+
const e = await this.request("https://api.dropboxapi.com/2/users/get_current_account", {
|
|
165
|
+
method: "POST",
|
|
166
|
+
responseType: "json"
|
|
167
|
+
});
|
|
168
|
+
return this.account = {
|
|
169
|
+
id: e.account_id,
|
|
170
|
+
name: e.name.display_name,
|
|
171
|
+
avatar: e.profile_photo_url
|
|
172
|
+
}, this.account;
|
|
173
|
+
}
|
|
174
|
+
async mkdir(e) {
|
|
175
|
+
const t = [this.getDropboxPath(e.parent, !0), e.name].filter(Boolean).join("/"), s = await this.request("https://api.dropboxapi.com/2/files/create_folder_v2", {
|
|
176
|
+
method: "POST",
|
|
177
|
+
json: {
|
|
178
|
+
path: t
|
|
179
|
+
},
|
|
180
|
+
responseType: "json"
|
|
181
|
+
});
|
|
182
|
+
return this.normalizeEntry({
|
|
183
|
+
...s.metadata,
|
|
184
|
+
".tag": "folder"
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
async find(e) {
|
|
188
|
+
const t = this.getDropboxPath(e, !1), s = await this.request(
|
|
189
|
+
"https://api.dropboxapi.com/2/files/get_metadata",
|
|
190
|
+
{
|
|
191
|
+
method: "POST",
|
|
192
|
+
json: {
|
|
193
|
+
path: t
|
|
194
|
+
},
|
|
195
|
+
responseType: "json"
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
return this.normalizeEntry(s);
|
|
199
|
+
}
|
|
200
|
+
async *list(e) {
|
|
201
|
+
const t = e ? this.getDropboxPath(e, !0) : "";
|
|
202
|
+
let s = await this.request("https://api.dropboxapi.com/2/files/list_folder", {
|
|
203
|
+
method: "POST",
|
|
204
|
+
json: {
|
|
205
|
+
path: t
|
|
206
|
+
},
|
|
207
|
+
responseType: "json"
|
|
208
|
+
});
|
|
209
|
+
for (yield s.entries.map((n) => this.normalizeEntry(n)); s.has_more; )
|
|
210
|
+
s = await this.request("https://api.dropboxapi.com/2/files/list_folder/continue", {
|
|
211
|
+
method: "POST",
|
|
212
|
+
json: {
|
|
213
|
+
cursor: s.cursor
|
|
214
|
+
},
|
|
215
|
+
responseType: "json"
|
|
216
|
+
}), yield s.entries.map((n) => this.normalizeEntry(n));
|
|
217
|
+
}
|
|
218
|
+
get(e) {
|
|
219
|
+
const t = this.getDropboxPath(e, !1);
|
|
220
|
+
return this.request("https://content.dropboxapi.com/2/files/download", {
|
|
221
|
+
method: "POST",
|
|
222
|
+
headers: {
|
|
223
|
+
"Dropbox-API-Arg": JSON.stringify({
|
|
224
|
+
path: t
|
|
225
|
+
})
|
|
226
|
+
},
|
|
227
|
+
responseType: "blob"
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async remove(e) {
|
|
231
|
+
const t = this.getDropboxPath(e, !1);
|
|
232
|
+
await this.request("https://api.dropboxapi.com/2/files/delete", {
|
|
233
|
+
method: "POST",
|
|
234
|
+
json: {
|
|
235
|
+
path: t
|
|
236
|
+
},
|
|
237
|
+
responseType: "json"
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
async put(e, t) {
|
|
241
|
+
const s = e.name && !e.id ? [this.getDropboxPath(e.parent, !0), e.name].filter(Boolean).join("/") : this.getDropboxPath(e, !0);
|
|
242
|
+
if (!s) throw new Error("Invalid path");
|
|
243
|
+
const n = await this.request(
|
|
244
|
+
"https://content.dropboxapi.com/2/files/upload",
|
|
245
|
+
{
|
|
246
|
+
method: "POST",
|
|
247
|
+
headers: {
|
|
248
|
+
"Dropbox-API-Arg": JSON.stringify(
|
|
249
|
+
{
|
|
250
|
+
path: s,
|
|
251
|
+
mode: "overwrite"
|
|
252
|
+
},
|
|
253
|
+
ee
|
|
254
|
+
),
|
|
255
|
+
"Content-Type": "application/octet-stream"
|
|
256
|
+
},
|
|
257
|
+
body: t,
|
|
258
|
+
responseType: "json"
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
return this.normalizeEntry({
|
|
262
|
+
...n,
|
|
263
|
+
".tag": "file"
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
class se extends T {
|
|
268
|
+
constructor() {
|
|
269
|
+
super(...arguments), this.baseUrl = "https://www.googleapis.com/drive/v3/", this.rootId = "appDataFolder";
|
|
270
|
+
}
|
|
271
|
+
async getAccount() {
|
|
272
|
+
const e = await this.request("https://www.googleapis.com/oauth2/v1/userinfo?alt=json", {
|
|
273
|
+
responseType: "json"
|
|
274
|
+
});
|
|
275
|
+
return this.account = {
|
|
276
|
+
id: e.id,
|
|
277
|
+
name: e.name,
|
|
278
|
+
avatar: e.picture
|
|
279
|
+
}, this.account;
|
|
280
|
+
}
|
|
281
|
+
normalizeEntry(e) {
|
|
282
|
+
return {
|
|
283
|
+
kind: e.kind.endsWith("#file") ? "file" : "folder",
|
|
284
|
+
id: e.id,
|
|
285
|
+
name: e.name,
|
|
286
|
+
size: Number(e.size),
|
|
287
|
+
modifiedTime: e.modifiedTime
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
async stat(e) {
|
|
291
|
+
const t = await this.request(`files/${e}`, {
|
|
292
|
+
responseType: "json"
|
|
293
|
+
});
|
|
294
|
+
return this.normalizeEntry(t);
|
|
295
|
+
}
|
|
296
|
+
async resolveId(e) {
|
|
297
|
+
return e.id ? e.id : (await this.find(e)).id;
|
|
298
|
+
}
|
|
299
|
+
async find(e) {
|
|
300
|
+
if (e.id) return this.stat(e.id);
|
|
301
|
+
let t;
|
|
302
|
+
if (!e.path) throw new Error("Invalid path");
|
|
303
|
+
const s = e.path.split("/").filter(Boolean);
|
|
304
|
+
for (const n of s) {
|
|
305
|
+
const o = t;
|
|
306
|
+
t = void 0;
|
|
307
|
+
for await (const i of this.list(o)) {
|
|
308
|
+
const a = i.find((c) => c.name === n);
|
|
309
|
+
if (a) {
|
|
310
|
+
t = a;
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (!t) throw new Error("Item not found");
|
|
316
|
+
return t;
|
|
317
|
+
}
|
|
318
|
+
async mkdir(e) {
|
|
319
|
+
const t = e.parent && await this.resolveId(e.parent), s = await this.request("files", {
|
|
320
|
+
method: "POST",
|
|
321
|
+
json: {
|
|
322
|
+
name: e.name,
|
|
323
|
+
parents: [t || this.rootId],
|
|
324
|
+
mimeType: "application/vnd.google-apps.folder"
|
|
325
|
+
},
|
|
326
|
+
responseType: "json"
|
|
327
|
+
});
|
|
328
|
+
return this.normalizeEntry(s);
|
|
329
|
+
}
|
|
330
|
+
async *list(e) {
|
|
331
|
+
const t = e && await this.resolveId(e);
|
|
332
|
+
let s = "";
|
|
333
|
+
for (; ; ) {
|
|
334
|
+
const n = new URLSearchParams({
|
|
335
|
+
spaces: this.rootId,
|
|
336
|
+
fields: "files(id,name,size,kind,mimeType,createdTime,modifiedTime),nextPageToken",
|
|
337
|
+
pageToken: s,
|
|
338
|
+
...t && {
|
|
339
|
+
q: `'${t}' in parents`
|
|
340
|
+
}
|
|
341
|
+
}), o = await this.request(`files?${n}`, { responseType: "json" });
|
|
342
|
+
if (yield o.files.map((i) => this.normalizeEntry(i)), !o.nextPageToken) break;
|
|
343
|
+
s = o.nextPageToken;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
async get(e) {
|
|
347
|
+
const t = await this.resolveId(e);
|
|
348
|
+
return await this.request(`files/${t}?alt=media`, {
|
|
349
|
+
responseType: "blob"
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
async remove(e) {
|
|
353
|
+
const t = await this.resolveId(e);
|
|
354
|
+
await this.request(`files/${t}`, {
|
|
355
|
+
method: "DELETE",
|
|
356
|
+
responseType: "json"
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
async put(e, t) {
|
|
360
|
+
let s = e.parent ? await this.resolveId(e.parent) : "", n = e.id;
|
|
361
|
+
if (!n && !s && e.path)
|
|
362
|
+
try {
|
|
363
|
+
n = await this.resolveId(e);
|
|
364
|
+
} catch {
|
|
365
|
+
const c = e.path.lastIndexOf("/"), h = c < 0 ? "" : e.path.slice(0, c);
|
|
366
|
+
s = await this.resolveId({ path: h });
|
|
367
|
+
}
|
|
368
|
+
if (!n && !e.name) throw new Error("Invalid file name");
|
|
369
|
+
const o = new FormData();
|
|
370
|
+
o.append(
|
|
371
|
+
"metadata",
|
|
372
|
+
new Blob(
|
|
373
|
+
[
|
|
374
|
+
JSON.stringify({
|
|
375
|
+
name: e.name || "",
|
|
376
|
+
...!n && { parents: [s || this.rootId] }
|
|
377
|
+
})
|
|
378
|
+
],
|
|
379
|
+
{ type: "application/json" }
|
|
380
|
+
)
|
|
381
|
+
), o.append("file", t);
|
|
382
|
+
const i = n ? `https://www.googleapis.com/upload/drive/v3/files/${n}?uploadType=multipart` : "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart", a = await this.request(i, {
|
|
383
|
+
body: o,
|
|
384
|
+
method: n ? "PATCH" : "POST",
|
|
385
|
+
responseType: "json"
|
|
386
|
+
});
|
|
387
|
+
return this.normalizeEntry(a);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
class ne extends T {
|
|
391
|
+
constructor() {
|
|
392
|
+
super(...arguments), this.baseUrl = "https://graph.microsoft.com/v1.0/", this.root = "me/drive/special/approot";
|
|
393
|
+
}
|
|
394
|
+
// or 'me/drive/root' for a personal drive
|
|
395
|
+
async getAccount() {
|
|
396
|
+
const e = await this.request("/oidc/userinfo", { responseType: "json" });
|
|
397
|
+
return this.account = {
|
|
398
|
+
id: e.sub,
|
|
399
|
+
name: e.givenname + " " + e.familyname,
|
|
400
|
+
avatar: e.picture
|
|
401
|
+
}, this.account;
|
|
402
|
+
}
|
|
403
|
+
normalizeEntry(e) {
|
|
404
|
+
return {
|
|
405
|
+
id: e.id,
|
|
406
|
+
name: e.name,
|
|
407
|
+
size: e.size,
|
|
408
|
+
kind: "file",
|
|
409
|
+
modifiedTime: e.lastModifiedDateTime
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
getOneDrivePath(e, t, s) {
|
|
413
|
+
let n;
|
|
414
|
+
if (e?.id)
|
|
415
|
+
n = `me/drive/items/${e.id}`;
|
|
416
|
+
else if (e?.parent?.id ? n = `me/drive/items/${e.parent.id}` : n = this.root, e?.name)
|
|
417
|
+
n += ":", e.parent?.path && !e.parent.id && (n += `${e.parent.path}`), n += `/${e.name}`, s && (n += ":");
|
|
418
|
+
else if (!t)
|
|
419
|
+
throw new Error("Invalid path");
|
|
420
|
+
return s && (n += s), n;
|
|
421
|
+
}
|
|
422
|
+
async mkdir(e) {
|
|
423
|
+
const t = this.getOneDrivePath(e.parent, !0, "/children"), s = await this.request(t, {
|
|
424
|
+
method: "POST",
|
|
425
|
+
json: {
|
|
426
|
+
name: e.name,
|
|
427
|
+
folder: {},
|
|
428
|
+
"@microsoft.graph.conflictBehavior": "fail"
|
|
429
|
+
},
|
|
430
|
+
responseType: "json"
|
|
431
|
+
});
|
|
432
|
+
return this.normalizeEntry(s);
|
|
433
|
+
}
|
|
434
|
+
async find(e) {
|
|
435
|
+
const t = this.getOneDrivePath(e, !1), s = await this.request(t, {
|
|
436
|
+
responseType: "json"
|
|
437
|
+
});
|
|
438
|
+
return this.normalizeEntry(s);
|
|
439
|
+
}
|
|
440
|
+
async *list(e) {
|
|
441
|
+
let t = this.getOneDrivePath(e, !0, "/children");
|
|
442
|
+
for (; t; ) {
|
|
443
|
+
const s = await this.request(t, { responseType: "json" });
|
|
444
|
+
t = s["@odata.nextLink"] || "", yield s.value.map((n) => this.normalizeEntry(n));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
get(e) {
|
|
448
|
+
const t = this.getOneDrivePath(e, !1, "/content");
|
|
449
|
+
return this.request(t, { responseType: "blob" });
|
|
450
|
+
}
|
|
451
|
+
async remove(e) {
|
|
452
|
+
const t = this.getOneDrivePath(e, !1);
|
|
453
|
+
await this.request(t, {
|
|
454
|
+
method: "DELETE",
|
|
455
|
+
responseType: "blob"
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
async put(e, t) {
|
|
459
|
+
const s = this.getOneDrivePath(e, !1, "/content"), n = await this.request(s, {
|
|
460
|
+
method: "PUT",
|
|
461
|
+
headers: {
|
|
462
|
+
"Content-Type": "application/octet-stream"
|
|
463
|
+
},
|
|
464
|
+
body: t,
|
|
465
|
+
responseType: "json"
|
|
466
|
+
});
|
|
467
|
+
return this.normalizeEntry(n);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const re = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", S = new TextEncoder(), oe = new j({
|
|
471
|
+
ignoreAttributes: !1,
|
|
472
|
+
removeNSPrefix: !0
|
|
999
473
|
});
|
|
1000
|
-
function
|
|
1001
|
-
|
|
1002
|
-
}
|
|
1003
|
-
function
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
}
|
|
1032
|
-
function
|
|
1033
|
-
|
|
1034
|
-
}
|
|
1035
|
-
function
|
|
1036
|
-
|
|
1037
|
-
}
|
|
1038
|
-
function
|
|
1039
|
-
|
|
1040
|
-
}
|
|
1041
|
-
function
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
474
|
+
function q(r) {
|
|
475
|
+
return r ? Array.isArray(r) ? r : [r] : [];
|
|
476
|
+
}
|
|
477
|
+
function E(r) {
|
|
478
|
+
return encodeURIComponent(r).replace(
|
|
479
|
+
/[!'()*]/g,
|
|
480
|
+
(e) => `%${e.codePointAt(0).toString(16).toUpperCase()}`
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
function K(r) {
|
|
484
|
+
return Array.from(r).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
485
|
+
}
|
|
486
|
+
async function z(r) {
|
|
487
|
+
let e;
|
|
488
|
+
typeof r == "string" ? e = S.encode(r).buffer : r instanceof Blob ? e = await r.arrayBuffer() : r instanceof Uint8Array ? e = r.buffer.slice(r.byteOffset, r.byteOffset + r.byteLength) : e = r;
|
|
489
|
+
const t = await crypto.subtle.digest("SHA-256", e);
|
|
490
|
+
return K(new Uint8Array(t));
|
|
491
|
+
}
|
|
492
|
+
async function v(r, e) {
|
|
493
|
+
const t = typeof r == "string" ? S.encode(r) : r, s = await crypto.subtle.importKey(
|
|
494
|
+
"raw",
|
|
495
|
+
t,
|
|
496
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
497
|
+
!1,
|
|
498
|
+
["sign"]
|
|
499
|
+
);
|
|
500
|
+
return new Uint8Array(await crypto.subtle.sign("HMAC", s, S.encode(e)));
|
|
501
|
+
}
|
|
502
|
+
async function ie(r, e, t) {
|
|
503
|
+
let s = await v(`AWS4${r}`, e);
|
|
504
|
+
return s = await v(s, t), s = await v(s, "s3"), v(s, "aws4_request");
|
|
505
|
+
}
|
|
506
|
+
function ae(r) {
|
|
507
|
+
return r.includes("://") ? r : `https://${r}`;
|
|
508
|
+
}
|
|
509
|
+
function ce(r) {
|
|
510
|
+
return r.replace(/^\/+|\/+$/g, "");
|
|
511
|
+
}
|
|
512
|
+
function g(r) {
|
|
513
|
+
return r.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
514
|
+
}
|
|
515
|
+
function he(r) {
|
|
516
|
+
return g(r).split("/").filter(Boolean);
|
|
517
|
+
}
|
|
518
|
+
function le(r) {
|
|
519
|
+
return g(r).split("/").pop() || "";
|
|
520
|
+
}
|
|
521
|
+
function de(r) {
|
|
522
|
+
const t = oe.parse(r).ListBucketResult || {}, s = q(t.Contents).map((o) => ({
|
|
523
|
+
key: o.Key || "",
|
|
524
|
+
lastModified: o.LastModified || "",
|
|
525
|
+
size: Number(o.Size || 0)
|
|
526
|
+
})), n = q(t.CommonPrefixes).map((o) => o.Prefix || "");
|
|
527
|
+
return {
|
|
528
|
+
contents: s,
|
|
529
|
+
commonPrefixes: n,
|
|
530
|
+
nextContinuationToken: t.NextContinuationToken || ""
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
async function b({
|
|
534
|
+
method: r,
|
|
535
|
+
endpoint: e,
|
|
536
|
+
path: t,
|
|
537
|
+
query: s,
|
|
538
|
+
accessKeyId: n,
|
|
539
|
+
secretAccessKey: o,
|
|
540
|
+
region: i,
|
|
541
|
+
body: a
|
|
542
|
+
}) {
|
|
543
|
+
const h = (/* @__PURE__ */ new Date()).toISOString().replace(/[:-]|\.\d{3}/g, ""), p = h.slice(0, 8), l = `/${he(t).map(E).join("/")}`, u = [...s].sort(
|
|
544
|
+
([m, x], [O, I]) => m === O ? x < I ? -1 : x > I ? 1 : 0 : m < O ? -1 : 1
|
|
545
|
+
).map(([m, x]) => `${E(m)}=${E(x)}`).join("&"), d = `${e.replace(/\/$/, "")}${l}${u ? `?${u}` : ""}`, y = a ? await z(a) : re, f = {
|
|
546
|
+
host: new URL(d).host,
|
|
547
|
+
"x-amz-content-sha256": y,
|
|
548
|
+
"x-amz-date": h
|
|
549
|
+
}, P = Object.keys(f).sort(), R = P.map((m) => `${m}:${f[m]}
|
|
550
|
+
`).join(""), D = P.join(";"), H = [
|
|
551
|
+
r,
|
|
552
|
+
l,
|
|
553
|
+
u,
|
|
554
|
+
R,
|
|
555
|
+
D,
|
|
556
|
+
y
|
|
557
|
+
].join(`
|
|
558
|
+
`), k = `${p}/${i}/s3/aws4_request`, L = [
|
|
559
|
+
"AWS4-HMAC-SHA256",
|
|
560
|
+
h,
|
|
561
|
+
k,
|
|
562
|
+
await z(H)
|
|
563
|
+
].join(`
|
|
564
|
+
`), F = await ie(o, p, i), W = K(await v(F, L));
|
|
565
|
+
return {
|
|
566
|
+
url: d,
|
|
567
|
+
headers: {
|
|
568
|
+
...f,
|
|
569
|
+
Authorization: `AWS4-HMAC-SHA256 Credential=${n}/${k}, SignedHeaders=${D}, Signature=${W}`
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
class pe extends T {
|
|
574
|
+
getOptions() {
|
|
575
|
+
const e = this.authConfig.serverOptions || {}, t = e.bucket?.trim() || "", s = ae(e.endpoint?.trim() || ""), n = ce(e.prefix?.trim() || ""), o = e.region?.trim() || "us-east-1", i = this.authConfig.user?.trim() || "", a = this.authConfig.password?.trim() || "", c = e.name?.trim() || t || "S3", h = e.avatar?.trim() || "";
|
|
576
|
+
return {
|
|
577
|
+
bucket: t,
|
|
578
|
+
endpoint: s,
|
|
579
|
+
prefix: n,
|
|
580
|
+
region: o,
|
|
581
|
+
accessKeyId: i,
|
|
582
|
+
secretAccessKey: a,
|
|
583
|
+
name: c,
|
|
584
|
+
avatar: h
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
getRootPrefix() {
|
|
588
|
+
const { prefix: e } = this.getOptions();
|
|
589
|
+
return e ? `${e}/` : "";
|
|
590
|
+
}
|
|
591
|
+
resolveKey(e) {
|
|
592
|
+
const t = e?.id || e?.path || "";
|
|
593
|
+
return g(t);
|
|
594
|
+
}
|
|
595
|
+
resolveFullKey(e) {
|
|
596
|
+
return `${this.getRootPrefix()}${this.resolveKey(e)}`.replace(/\/+$/, "");
|
|
597
|
+
}
|
|
598
|
+
normalizeFile(e, t, s, n) {
|
|
599
|
+
return {
|
|
600
|
+
id: g(e).replace(/\/+$/, ""),
|
|
601
|
+
name: le(e),
|
|
602
|
+
size: t,
|
|
603
|
+
kind: n,
|
|
604
|
+
modifiedTime: s
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
initRequest() {
|
|
608
|
+
return $(async (t, s) => {
|
|
609
|
+
const { responseType: n, headers: o, body: i, ...a } = s, c = this.getOptions();
|
|
610
|
+
if (!c.bucket || !c.endpoint || !c.accessKeyId || !c.secretAccessKey)
|
|
611
|
+
throw new Error("Invalid S3 configuration");
|
|
612
|
+
const h = new URL(t, c.endpoint), p = Array.from(h.searchParams.entries()), { url: l, headers: u } = await b({
|
|
613
|
+
method: (a.method || "GET").toUpperCase(),
|
|
614
|
+
endpoint: c.endpoint,
|
|
615
|
+
path: h.pathname,
|
|
616
|
+
query: p,
|
|
617
|
+
accessKeyId: c.accessKeyId,
|
|
618
|
+
secretAccessKey: c.secretAccessKey,
|
|
619
|
+
region: c.region,
|
|
620
|
+
body: i
|
|
621
|
+
}), d = new Headers(o);
|
|
622
|
+
for (const [f, P] of Object.entries(u))
|
|
623
|
+
d.set(f, P);
|
|
624
|
+
return await w(new URL(l), {
|
|
625
|
+
...a,
|
|
626
|
+
headers: d,
|
|
627
|
+
body: i
|
|
628
|
+
})[n]();
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
async getAccount() {
|
|
632
|
+
const e = this.getOptions();
|
|
633
|
+
return this.account = {
|
|
634
|
+
id: e.bucket,
|
|
635
|
+
name: e.name,
|
|
636
|
+
avatar: e.avatar || void 0
|
|
637
|
+
}, this.account;
|
|
638
|
+
}
|
|
639
|
+
async mkdir(e) {
|
|
640
|
+
throw new Error("Not supported");
|
|
641
|
+
}
|
|
642
|
+
async find(e) {
|
|
643
|
+
const t = this.resolveKey(e);
|
|
644
|
+
if (!t) throw new Error("Invalid path");
|
|
645
|
+
let s;
|
|
646
|
+
const n = t.split("/").filter(Boolean);
|
|
647
|
+
for (let o = 0; o < n.length; o += 1) {
|
|
648
|
+
const i = s?.kind === "folder" ? { id: s.id } : void 0;
|
|
649
|
+
s = void 0;
|
|
650
|
+
for await (const a of this.list(i)) {
|
|
651
|
+
const c = a.find((h) => h.name === n[o]);
|
|
652
|
+
if (c) {
|
|
653
|
+
s = c;
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (!s) throw new Error("Item not found");
|
|
659
|
+
return s;
|
|
660
|
+
}
|
|
661
|
+
async *list(e) {
|
|
662
|
+
const t = this.getOptions(), s = this.getRootPrefix(), n = e ? this.resolveKey(e) : "", o = `${s}${n ? `${n}/` : ""}`;
|
|
663
|
+
let i = "";
|
|
664
|
+
do {
|
|
665
|
+
const a = new URLSearchParams({
|
|
666
|
+
"list-type": "2",
|
|
667
|
+
delimiter: "/",
|
|
668
|
+
prefix: o
|
|
669
|
+
});
|
|
670
|
+
i && a.set("continuation-token", i);
|
|
671
|
+
const { url: c, headers: h } = await b({
|
|
672
|
+
method: "GET",
|
|
673
|
+
endpoint: t.endpoint,
|
|
674
|
+
path: t.bucket,
|
|
675
|
+
query: Array.from(a.entries()),
|
|
676
|
+
accessKeyId: t.accessKeyId,
|
|
677
|
+
secretAccessKey: t.secretAccessKey,
|
|
678
|
+
region: t.region
|
|
679
|
+
}), p = await w(new URL(c), {
|
|
680
|
+
headers: h
|
|
681
|
+
}).text(), l = de(p), u = [];
|
|
682
|
+
for (const d of l.contents) {
|
|
683
|
+
const y = g(d.key);
|
|
684
|
+
if (!y.startsWith(o)) continue;
|
|
685
|
+
const f = y.slice(o.length);
|
|
686
|
+
f && u.push(this.normalizeFile(f, d.size, d.lastModified, "file"));
|
|
687
|
+
}
|
|
688
|
+
for (const d of l.commonPrefixes) {
|
|
689
|
+
const y = g(d);
|
|
690
|
+
if (!y.startsWith(o)) continue;
|
|
691
|
+
const f = y.slice(o.length);
|
|
692
|
+
f && u.push(this.normalizeFile(f, 0, "", "folder"));
|
|
693
|
+
}
|
|
694
|
+
yield u, i = l.nextContinuationToken;
|
|
695
|
+
} while (i);
|
|
696
|
+
}
|
|
697
|
+
async get(e) {
|
|
698
|
+
const t = this.resolveFullKey(e), s = this.getOptions(), { url: n, headers: o } = await b({
|
|
699
|
+
method: "GET",
|
|
700
|
+
endpoint: s.endpoint,
|
|
701
|
+
path: `${s.bucket}/${t}`,
|
|
702
|
+
query: [],
|
|
703
|
+
accessKeyId: s.accessKeyId,
|
|
704
|
+
secretAccessKey: s.secretAccessKey,
|
|
705
|
+
region: s.region
|
|
706
|
+
});
|
|
707
|
+
return w(new URL(n), {
|
|
708
|
+
headers: o
|
|
709
|
+
}).blob();
|
|
710
|
+
}
|
|
711
|
+
async remove(e) {
|
|
712
|
+
const t = this.resolveFullKey(e), s = this.getOptions(), { url: n, headers: o } = await b({
|
|
713
|
+
method: "DELETE",
|
|
714
|
+
endpoint: s.endpoint,
|
|
715
|
+
path: `${s.bucket}/${t}`,
|
|
716
|
+
query: [],
|
|
717
|
+
accessKeyId: s.accessKeyId,
|
|
718
|
+
secretAccessKey: s.secretAccessKey,
|
|
719
|
+
region: s.region
|
|
720
|
+
});
|
|
721
|
+
await w(new URL(n), {
|
|
722
|
+
method: "DELETE",
|
|
723
|
+
headers: o
|
|
724
|
+
}).blob();
|
|
725
|
+
}
|
|
726
|
+
async put(e, t) {
|
|
727
|
+
const s = this.resolveFullKey(e.parent), n = e.name ? `${s ? `${s}/` : this.getRootPrefix()}${e.name}` : this.resolveFullKey(e);
|
|
728
|
+
if (!n) throw new Error("Invalid file name");
|
|
729
|
+
const o = this.getOptions(), i = `${o.bucket}/${n}`, { url: a, headers: c } = await b({
|
|
730
|
+
method: "PUT",
|
|
731
|
+
endpoint: o.endpoint,
|
|
732
|
+
path: i,
|
|
733
|
+
query: [],
|
|
734
|
+
accessKeyId: o.accessKeyId,
|
|
735
|
+
secretAccessKey: o.secretAccessKey,
|
|
736
|
+
region: o.region,
|
|
737
|
+
body: t
|
|
738
|
+
});
|
|
739
|
+
return await w(new URL(a), {
|
|
740
|
+
method: "PUT",
|
|
741
|
+
headers: c,
|
|
742
|
+
body: t
|
|
743
|
+
}).blob(), this.normalizeFile(
|
|
744
|
+
n,
|
|
745
|
+
t.size,
|
|
746
|
+
(/* @__PURE__ */ new Date()).toISOString(),
|
|
747
|
+
n.endsWith("/") ? "folder" : "file"
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
const ue = new j({
|
|
752
|
+
ignoreAttributes: !1,
|
|
753
|
+
removeNSPrefix: !0
|
|
754
|
+
});
|
|
755
|
+
class fe extends T {
|
|
756
|
+
constructor(e, t) {
|
|
757
|
+
super(e, t);
|
|
758
|
+
let s = e.serverOptions?.baseUrl;
|
|
759
|
+
if (!s) throw new Error("baseUrl is required");
|
|
760
|
+
s.endsWith("/") || (s += "/"), this.baseUrl = s;
|
|
761
|
+
}
|
|
762
|
+
initRequest() {
|
|
763
|
+
let e = (t, s) => {
|
|
764
|
+
const { responseType: n, headers: o, ...i } = s, a = new Headers(o), { serverOptions: c = {}, user: h, password: p } = this.authConfig;
|
|
765
|
+
if (c && !c.anonymous) {
|
|
766
|
+
const l = Q(new TextEncoder().encode(`${h}:${p}`));
|
|
767
|
+
a.set("authorization", `Basic ${l}`);
|
|
768
|
+
}
|
|
769
|
+
return t.startsWith("/") && (t = `.${t}`), w(new URL(t, this.baseUrl), {
|
|
770
|
+
// Bypass login CSRF protection in NextCloud by not sending cookies
|
|
771
|
+
credentials: "omit",
|
|
772
|
+
...i,
|
|
773
|
+
headers: a
|
|
774
|
+
})[n]();
|
|
775
|
+
};
|
|
776
|
+
return e = $(e), e;
|
|
777
|
+
}
|
|
778
|
+
async getAccount() {
|
|
779
|
+
const { serverOptions: e = {} } = this.authConfig;
|
|
780
|
+
return this.account = {
|
|
781
|
+
id: `${e.id || "webdav"}`,
|
|
782
|
+
name: `${e.name || "WebDav"}`,
|
|
783
|
+
avatar: `${e.avatar || ""}`
|
|
784
|
+
}, this.account;
|
|
785
|
+
}
|
|
786
|
+
getWebDavPath(e, t) {
|
|
787
|
+
let s = e?.path || e?.id || "";
|
|
788
|
+
if (s[0] === "/" && (s = s.slice(1)), !s && !t) throw new Error("Invalid path");
|
|
789
|
+
return s;
|
|
790
|
+
}
|
|
791
|
+
getFullUrl(e) {
|
|
792
|
+
return new URL(e, this.baseUrl).href;
|
|
793
|
+
}
|
|
794
|
+
async mkdir(e) {
|
|
795
|
+
const t = [this.getWebDavPath(e.parent, !0), e.name].filter(Boolean).join("/");
|
|
796
|
+
return await this.request(t, {
|
|
797
|
+
method: "MKCOL",
|
|
798
|
+
responseType: "blob"
|
|
799
|
+
}), {
|
|
800
|
+
id: this.getFullUrl(t),
|
|
801
|
+
name: e.name,
|
|
802
|
+
size: 0,
|
|
803
|
+
kind: "folder",
|
|
804
|
+
modifiedTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
async propFind(e) {
|
|
808
|
+
const t = await this.request(e, {
|
|
809
|
+
method: "PROPFIND",
|
|
810
|
+
headers: {
|
|
811
|
+
depth: "1"
|
|
812
|
+
},
|
|
813
|
+
responseType: "text"
|
|
814
|
+
});
|
|
815
|
+
let n = ue.parse(t).multistatus.response;
|
|
816
|
+
return Array.isArray(n) || (n = n ? [n] : []), n.map((o) => {
|
|
817
|
+
const i = o.propstat.prop, a = i.resourcetype?.collection;
|
|
818
|
+
return {
|
|
819
|
+
id: this.getFullUrl(o.href),
|
|
820
|
+
name: i.displayname,
|
|
821
|
+
kind: a ? "folder" : "file",
|
|
822
|
+
size: a ? 0 : i.getcontentlength,
|
|
823
|
+
modifiedTime: new Date(i.getlastmodified).toISOString()
|
|
824
|
+
};
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
async find(e) {
|
|
828
|
+
const t = this.getWebDavPath(e, !1), s = this.getFullUrl(t), o = (await this.propFind(t)).find((i) => i.id === s);
|
|
829
|
+
if (!o) throw new Error("Item not found");
|
|
830
|
+
return o;
|
|
831
|
+
}
|
|
832
|
+
async *list(e) {
|
|
833
|
+
const t = this.getWebDavPath(e, !0), s = this.getFullUrl(t);
|
|
834
|
+
let n = await this.propFind(t);
|
|
835
|
+
n = n.filter((o) => o.id !== s), yield n;
|
|
836
|
+
}
|
|
837
|
+
async get(e) {
|
|
838
|
+
const t = this.getWebDavPath(e, !1);
|
|
839
|
+
return this.request(t, { responseType: "blob" });
|
|
840
|
+
}
|
|
841
|
+
async remove(e) {
|
|
842
|
+
const t = this.getWebDavPath(e, !1);
|
|
843
|
+
await this.request(t, {
|
|
844
|
+
method: "DELETE",
|
|
845
|
+
responseType: "blob"
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
async put(e, t) {
|
|
849
|
+
const s = this.getWebDavPath(e, !0) || [this.getWebDavPath(e.parent, !0), e.name || ""].filter(Boolean).join("/");
|
|
850
|
+
if (!s) throw new Error("Invalid path");
|
|
851
|
+
return await this.request(s, {
|
|
852
|
+
method: "PUT",
|
|
853
|
+
headers: {
|
|
854
|
+
"Content-Type": "application/octet-stream"
|
|
855
|
+
},
|
|
856
|
+
body: t,
|
|
857
|
+
responseType: "blob"
|
|
858
|
+
}), {
|
|
859
|
+
id: this.getFullUrl(s),
|
|
860
|
+
name: s.slice(s.lastIndexOf("/") + 1),
|
|
861
|
+
size: t.size,
|
|
862
|
+
kind: "file",
|
|
863
|
+
modifiedTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
const ye = {
|
|
868
|
+
dropbox: te,
|
|
869
|
+
googledrive: se,
|
|
870
|
+
onedrive: ne,
|
|
871
|
+
s3: pe,
|
|
872
|
+
webdav: fe
|
|
873
|
+
};
|
|
874
|
+
function me(r) {
|
|
875
|
+
if (r instanceof B)
|
|
876
|
+
return r.code === N || r.code === M;
|
|
877
|
+
if (typeof r == "object" && r) {
|
|
878
|
+
const e = r.response?.status;
|
|
879
|
+
return e === 401 || e === 403;
|
|
880
|
+
}
|
|
881
|
+
return !1;
|
|
882
|
+
}
|
|
883
|
+
async function be(r, e, t) {
|
|
884
|
+
let s = {};
|
|
885
|
+
if (e.auth.authProvider !== "password") {
|
|
886
|
+
const i = e.auth.authProvider, a = r.authProviders[i];
|
|
887
|
+
if (!a)
|
|
888
|
+
throw new Error(`Missing OAuth2 config for provider: ${i}`);
|
|
889
|
+
const c = _[i], h = new c(
|
|
890
|
+
{
|
|
891
|
+
redirectUrl: r.redirectUrl,
|
|
892
|
+
...a,
|
|
893
|
+
onSetAccessToken: (p) => {
|
|
894
|
+
t?.onUpdateToken?.({
|
|
895
|
+
accessToken: p ?? void 0
|
|
896
|
+
});
|
|
897
|
+
},
|
|
898
|
+
onSetRefreshToken: (p) => {
|
|
899
|
+
t?.onUpdateToken?.({
|
|
900
|
+
refreshToken: p ?? void 0
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
},
|
|
904
|
+
t?.initialData
|
|
905
|
+
);
|
|
906
|
+
s.authorizer = h;
|
|
907
|
+
}
|
|
908
|
+
const n = ye[e.driveProvider], o = new n(e.auth, s);
|
|
909
|
+
if (e.auth.authProvider !== "password")
|
|
910
|
+
try {
|
|
911
|
+
await o.getAccount();
|
|
912
|
+
} catch (i) {
|
|
913
|
+
if (!me(i)) throw i;
|
|
914
|
+
o.account = void 0;
|
|
915
|
+
}
|
|
916
|
+
return o;
|
|
917
|
+
}
|
|
918
|
+
export {
|
|
919
|
+
T as AuthenticatedDriveBase,
|
|
920
|
+
V as DriveBase,
|
|
921
|
+
ye as DriveProviders,
|
|
922
|
+
be as connectDrive,
|
|
923
|
+
ee as unicodeReplacer,
|
|
924
|
+
$ as withDelay,
|
|
925
|
+
Z as withToken
|
|
1355
926
|
};
|
|
1356
|
-
//#endregion
|
|
1357
|
-
//#region src/index.ts
|
|
1358
|
-
function oe(n) {
|
|
1359
|
-
if (n instanceof r) return n.code === t || n.code === e;
|
|
1360
|
-
if (typeof n == "object" && n) {
|
|
1361
|
-
let e = n.response?.status;
|
|
1362
|
-
return e === 401 || e === 403;
|
|
1363
|
-
}
|
|
1364
|
-
return !1;
|
|
1365
|
-
}
|
|
1366
|
-
async function se(e, t, r) {
|
|
1367
|
-
let i = {};
|
|
1368
|
-
if (t.auth.authProvider !== "password") {
|
|
1369
|
-
let a = t.auth.authProvider, o = e.authProviders[a];
|
|
1370
|
-
if (!o) throw Error(`Missing OAuth2 config for provider: ${a}`);
|
|
1371
|
-
let s = n[a];
|
|
1372
|
-
i.authorizer = new s({
|
|
1373
|
-
redirectUrl: e.redirectUrl,
|
|
1374
|
-
...o,
|
|
1375
|
-
onSetAccessToken: (e) => {
|
|
1376
|
-
r?.onUpdateToken?.({ accessToken: e ?? void 0 });
|
|
1377
|
-
},
|
|
1378
|
-
onSetRefreshToken: (e) => {
|
|
1379
|
-
r?.onUpdateToken?.({ refreshToken: e ?? void 0 });
|
|
1380
|
-
}
|
|
1381
|
-
}, r?.initialData);
|
|
1382
|
-
}
|
|
1383
|
-
let a = $[t.driveProvider], o = new a(t.auth, i);
|
|
1384
|
-
if (t.auth.authProvider !== "password") try {
|
|
1385
|
-
await o.getAccount();
|
|
1386
|
-
} catch (e) {
|
|
1387
|
-
if (!oe(e)) throw e;
|
|
1388
|
-
o.account = void 0;
|
|
1389
|
-
}
|
|
1390
|
-
return o;
|
|
1391
|
-
}
|
|
1392
|
-
//#endregion
|
|
1393
|
-
export { I as AuthenticatedDriveBase, F as DriveBase, $ as DriveProviders, se as connectDrive, L as unicodeReplacer, N as withDelay, P as withToken };
|