Your Name 1912bcd25b
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
chore: sync all remaining local workspace changes
2026-05-08 11:26:57 +08:00

367 lines
10 KiB
JavaScript

/*
* Extracted from browser-delivered Turbopack chunk: 042913757dfeb33b.7750222294.js
* Module id: 301710
* For reading/searching only; this factory depends on the original Turbopack runtime.
*/
const moduleFactory = (e) => {
"use strict";
var t = e.i(325528),
r = e.i(708771);
async function i(e) {
let t = await e.arrayBuffer();
return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-1", t)))
.map((e) => e.toString(16).padStart(2, "0"))
.join("");
}
async function n(e) {
let {
path: t,
fileSize: r,
partSize: i,
token: n,
baseUrl: a,
bizCode: s = "4",
signal: l,
} = e,
o = `${a.replace(/\/$/, "")}/gateway/oss-server-api/oss-service/api/oss/pre-sign/multipart/init/${s}`,
u = await fetch(o, {
method: "POST",
headers: { Token: n, "Content-Type": "application/json" },
body: JSON.stringify({ path: t, fileSize: r, partSize: i }),
signal: l,
});
if (!u.ok) {
let e = await u.text().catch(() => "");
throw Error(`initMultipartUpload failed: ${u.status} ${e}`);
}
let c = await u.json(),
d = c?.data;
if (!d?.uploadId || !Array.isArray(d?.parts))
throw Error("initMultipartUpload: invalid response");
return d;
}
async function a(e) {
let {
path: t,
uploadId: r,
token: i,
baseUrl: n,
bizCode: a = "4",
signal: s,
} = e,
l = `${n.replace(/\/$/, "")}/gateway/oss-server-api/oss-service/api/oss/pre-sign/multipart/complete/${a}`,
o = await fetch(l, {
method: "POST",
headers: { Token: i, "Content-Type": "application/json" },
body: JSON.stringify({ path: t, uploadId: r }),
signal: s,
});
if (!o.ok) {
let e = await o.text().catch(() => "");
throw Error(`completeMultipartUpload failed: ${o.status} ${e}`);
}
let u = await o.json(),
c = u?.data;
if (!c?.path) throw Error("completeMultipartUpload: invalid response");
return c;
}
class s extends Error {
status;
stage;
constructor(e, t, r) {
super(e),
(this.status = t),
(this.stage = r),
(this.name = "UploadHttpError");
}
}
function l(e) {
return (
!!e &&
(e instanceof DOMException || e instanceof Error) &&
"AbortError" === e.name
);
}
function o(e, t) {
let r = new AbortController(),
i = setTimeout(() => {
r.abort(new DOMException("upload timeout", "AbortError"));
}, e),
n = () => {
r.abort(t?.reason ?? new DOMException("aborted", "AbortError"));
};
return (
t &&
(t.aborted
? r.abort(t.reason ?? new DOMException("aborted", "AbortError"))
: t.addEventListener("abort", n, { once: !0 })),
{
signal: r.signal,
cleanup: () => {
clearTimeout(i), t && t.removeEventListener("abort", n);
},
}
);
}
async function u(e, t) {
e <= 0 ||
(await new Promise((r, i) => {
let n,
a = () => {
clearTimeout(n), i(new DOMException("aborted", "AbortError"));
};
if (
((n = setTimeout(() => {
t && t.removeEventListener("abort", a), r();
}, e)),
t)
) {
if (t.aborted) {
clearTimeout(n), i(new DOMException("aborted", "AbortError"));
return;
}
t.addEventListener("abort", a, { once: !0 });
}
}));
}
class c {
limit;
active;
waiting;
constructor(e) {
(this.limit = e), (this.active = 0), (this.waiting = []);
}
get currentLimit() {
return this.limit;
}
set currentLimit(e) {
(this.limit = Math.max(2, Math.min(6, e))), this.drain();
}
async acquire() {
this.active < this.limit
? this.active++
: await new Promise((e) => this.waiting.push(e));
}
release() {
this.active--, this.drain();
}
drain() {
for (; this.waiting.length > 0 && this.active < this.limit; ) {
this.active++;
let e = this.waiting.shift();
e && e();
}
}
}
async function d(e) {
let t,
r,
{
file: i,
path: d,
token: f,
baseUrl: p,
mode: m,
chunkSize: g = 5242880,
signal: h,
timeoutMs: y = 45e3,
maxRetries: v = 2,
retryBaseDelayMs: b = 800,
onProgress: w,
concurrency: x = 4,
} = e,
A =
"single" ===
(function (e, t, r = 5242880) {
return t <= r || "single" === e
? "single"
: "multi" === e || t > 5242880
? "multi"
: "single";
})(m, i.size, g)
? i.size
: g;
if (h?.aborted) throw new DOMException("aborted", "AbortError");
let { signal: S, cleanup: j } = o(y, h);
try {
t = await n({
path: d,
fileSize: i.size,
partSize: A,
token: f,
baseUrl: p,
signal: S,
});
} finally {
j();
}
let { uploadId: C, parts: E } = t,
T = new c(Math.min(x, E.length)),
N = 0,
M = i.size,
O = 0,
P = async (e) => {
await T.acquire();
try {
let r,
n = E[e],
a = e * A,
c = Math.min(a + A, i.size),
d = i.slice(a, c),
f = c - a,
p = v + 1;
for (let e = 1; e <= p; e++) {
if (h?.aborted) throw new DOMException("aborted", "AbortError");
try {
let { signal: e, cleanup: t } = o(y, h);
try {
let t = await fetch(n.url, {
method: n.method || "PUT",
body: d,
signal: e,
});
if (!t.ok)
throw new s(
`Part ${n.partNumber} failed: ${t.status}`,
t.status,
"part-put",
);
} finally {
t();
}
(N += f),
(O = 0),
w?.(N / M),
T.currentLimit < x &&
0 === O &&
(T.currentLimit = T.currentLimit + 1);
return;
} catch (i) {
var t;
if (l(i)) throw i;
(r = i),
++O >= 2 &&
T.currentLimit > 2 &&
(T.currentLimit = T.currentLimit - 1),
e < p &&
(await u(
((t = e),
b * 2 ** Math.max(0, t - 1) +
Math.floor(250 * Math.random())),
h,
));
}
}
throw r ?? Error(`Part ${E[e].partNumber} upload failed`);
} finally {
T.release();
}
};
if ((await Promise.all(E.map((e, t) => P(t))), h?.aborted))
throw new DOMException("aborted", "AbortError");
let { signal: L, cleanup: k } = o(y, h);
try {
r = await a({ path: d, uploadId: C, token: f, baseUrl: p, signal: L });
} finally {
k();
}
return w?.(1), { path: r.path, url: r.cdnUrl };
}
e.s(
[
"UploadHttpError",
() => s,
"isAbortError",
() => l,
"uploadViaEngine",
() => d,
],
160543,
),
e.i(616803);
let f = 0,
p = [];
async function m() {
if (f < 3) {
f += 1;
return;
}
await new Promise((e) => {
p.push(e);
});
}
async function g(e) {
await m();
try {
return await e();
} finally {
let e;
(e = p.shift()) ? e() : (f = Math.max(0, f - 1));
}
}
async function h(n, a) {
let {
token: s,
uuid: l,
onCalcHashEnd: o,
verify: u = !0,
baseUrl: c = t.config.tv.bridgeApiHost,
signal: f,
timeoutMs: p,
maxRetries: m,
retryBaseDelayMs: h,
mode: y,
chunkSize: v,
onProgress: b,
onReviewing: w,
} = a;
if (!n) throw Error("uploadViaPreSign: file is required");
if (!s || "string" != typeof s)
throw Error("uploadViaPreSign: token is required");
let x = await i(n);
o?.(x);
let A = n.name.includes(".")
? n.name.substring(n.name.lastIndexOf("."))
: "",
S = `upload-images/${l}/${x}${A}`.replace(
"liblibai-tmp-image.oss-cn-beijing.aliyuncs.com",
"liblibai-tmp-image.liblib.cloud",
);
return g(async () => {
let t = await d({
file: n,
path: S,
token: s,
baseUrl: c,
mode: y,
chunkSize: v,
signal: f,
timeoutMs: p,
maxRetries: m,
retryBaseDelayMs: h,
onProgress: b,
});
if (u && t.url) {
w?.();
let i = await (0, r.fileReview)([t.url]);
if (i?.[0]?.result) {
let { FileReviewError: t } = await e.A(638833);
throw new t();
}
}
return t;
});
}
function y(e) {
let t = e.url || e.path;
return t && "string" == typeof t && "" !== t.trim()
? t
: (console.warn("[preSignUpload] 上传结果中无有效 URL:", e), null);
}
e.s(["resolveUploadUrl", () => y, "uploadViaPreSign", () => h], 301710),
e.s([], 954175);
};
export default moduleFactory;