chaite
Version:
core for chatgpt-plugin and karin-plugin-chatgpt
87 lines (85 loc) • 3.25 kB
JavaScript
import { n as __esm } from "../../rolldown-runtime-DVriDoez.mjs";
import { a as init_fetch_blob, i as fetch_blob_default, n as file_default, r as init_file } from "../fetch-blob/index.mjs-ChDdLWI-.mjs";
//#region node_modules/.pnpm/formdata-polyfill@4.0.10/node_modules/formdata-polyfill/esm.min.js
/** @param {FormData} F */
function formDataToBlob(F, B = fetch_blob_default) {
var b = `${r()}${r()}`.replace(/\./g, "").slice(-28).padStart(32, "-"), c = [], p = `--${b}\r\nContent-Disposition: form-data; name="`;
F.forEach((v, n) => typeof v == "string" ? c.push(p + e(n) + `"\r\n\r\n${v.replace(/\r(?!\n)|(?<!\r)\n/g, "\r\n")}\r\n`) : c.push(p + e(n) + `"; filename="${e(v.name, 1)}"\r\nContent-Type: ${v.type || "application/octet-stream"}\r\n\r\n`, v, "\r\n"));
c.push(`--${b}--`);
return new B(c, { type: "multipart/form-data; boundary=" + b });
}
var t, i, h, r, m, f, e, x, FormData;
var init_esm_min = __esm({ "node_modules/.pnpm/formdata-polyfill@4.0.10/node_modules/formdata-polyfill/esm.min.js": (() => {
init_fetch_blob();
init_file();
({toStringTag: t, iterator: i, hasInstance: h} = Symbol), r = Math.random, m = "append,set,get,getAll,delete,keys,values,entries,forEach,constructor".split(","), f = (a, b, c) => (a += "", /^(Blob|File)$/.test(b && b[t]) ? [(c = c !== void 0 ? c + "" : b[t] == "File" ? b.name : "blob", a), b.name !== c || b[t] == "blob" ? new file_default([b], c, b) : b] : [a, b + ""]), e = (c, f$1) => (f$1 ? c : c.replace(/\r?\n|\r/g, "\r\n")).replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22"), x = (n, a, e$1) => {
if (a.length < e$1) throw new TypeError(`Failed to execute '${n}' on 'FormData': ${e$1} arguments required, but only ${a.length} present.`);
};
FormData = class FormData$1 {
#d = [];
constructor(...a) {
if (a.length) throw new TypeError(`Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.`);
}
get [t]() {
return "FormData";
}
[i]() {
return this.entries();
}
static [h](o) {
return o && typeof o === "object" && o[t] === "FormData" && !m.some((m$1) => typeof o[m$1] != "function");
}
append(...a) {
x("append", arguments, 2);
this.#d.push(f(...a));
}
delete(a) {
x("delete", arguments, 1);
a += "";
this.#d = this.#d.filter(([b]) => b !== a);
}
get(a) {
x("get", arguments, 1);
a += "";
for (var b = this.#d, l = b.length, c = 0; c < l; c++) if (b[c][0] === a) return b[c][1];
return null;
}
getAll(a, b) {
x("getAll", arguments, 1);
b = [];
a += "";
this.#d.forEach((c) => c[0] === a && b.push(c[1]));
return b;
}
has(a) {
x("has", arguments, 1);
a += "";
return this.#d.some((b) => b[0] === a);
}
forEach(a, b) {
x("forEach", arguments, 1);
for (var [c, d] of this) a.call(b, d, c, this);
}
set(...a) {
x("set", arguments, 2);
var b = [], c = !0;
a = f(...a);
this.#d.forEach((d) => {
d[0] === a[0] ? c && (c = !b.push(a)) : b.push(d);
});
c && b.push(a);
this.#d = b;
}
*entries() {
yield* this.#d;
}
*keys() {
for (var [a] of this) yield a;
}
*values() {
for (var [, a] of this) yield a;
}
};
}) });
//#endregion
export { formDataToBlob as n, init_esm_min as r, FormData as t };