multipart-parser-BS1x8A2O.mjs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import { Z as Zt, Y as Yr } from './server.mjs';
  2. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/vue@3.5.14_typescript@5.8.3/node_modules/vue/index.mjs';
  3. import 'node:http';
  4. import 'node:https';
  5. import 'node:zlib';
  6. import 'node:stream';
  7. import 'node:buffer';
  8. import 'node:util';
  9. import 'node:url';
  10. import 'node:net';
  11. import 'node:fs';
  12. import 'node:path';
  13. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/destr@2.0.5/node_modules/destr/dist/index.mjs';
  14. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/ufo@1.6.1/node_modules/ufo/dist/index.mjs';
  15. import '../_/renderer.mjs';
  16. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/vue-bundle-renderer@2.1.1/node_modules/vue-bundle-renderer/dist/runtime.mjs';
  17. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/h3@1.15.3/node_modules/h3/dist/index.mjs';
  18. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/vue@3.5.14_typescript@5.8.3/node_modules/vue/server-renderer/index.mjs';
  19. import '../nitro/nitro.mjs';
  20. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/hookable@5.5.3/node_modules/hookable/dist/index.mjs';
  21. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/ofetch@1.4.1/node_modules/ofetch/dist/node.mjs';
  22. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/node-mock-http@1.0.0/node_modules/node-mock-http/dist/index.mjs';
  23. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/unstorage@1.16.0_db0@0.3.2_ioredis@5.6.1/node_modules/unstorage/dist/index.mjs';
  24. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/unstorage@1.16.0_db0@0.3.2_ioredis@5.6.1/node_modules/unstorage/drivers/fs.mjs';
  25. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/unstorage@1.16.0_db0@0.3.2_ioredis@5.6.1/node_modules/unstorage/drivers/fs-lite.mjs';
  26. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/unstorage@1.16.0_db0@0.3.2_ioredis@5.6.1/node_modules/unstorage/drivers/lru-cache.mjs';
  27. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/index.mjs';
  28. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/klona@2.0.6/node_modules/klona/dist/index.mjs';
  29. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs';
  30. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs';
  31. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/unctx@2.4.1/node_modules/unctx/dist/index.mjs';
  32. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/radix3@1.1.2/node_modules/radix3/dist/index.mjs';
  33. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs';
  34. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/unhead@2.0.9/node_modules/unhead/dist/server.mjs';
  35. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/devalue@5.1.1/node_modules/devalue/index.js';
  36. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/unhead@2.0.9/node_modules/unhead/dist/utils.mjs';
  37. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/unhead@2.0.9/node_modules/unhead/dist/plugins.mjs';
  38. import 'file:///Users/yuxin/local/code/ccdw-website/node_modules/.pnpm/vue-router@4.5.1_vue@3.5.14_typescript@5.8.3_/node_modules/vue-router/dist/vue-router.node.mjs';
  39. var U = Object.defineProperty;
  40. var E = (_, o) => U(_, "name", { value: o, configurable: true });
  41. let D = 0;
  42. const t = { START_BOUNDARY: D++, HEADER_FIELD_START: D++, HEADER_FIELD: D++, HEADER_VALUE_START: D++, HEADER_VALUE: D++, HEADER_VALUE_ALMOST_DONE: D++, HEADERS_ALMOST_DONE: D++, PART_DATA_START: D++, PART_DATA: D++, END: D++ };
  43. let F = 1;
  44. const u = { PART_BOUNDARY: F, LAST_BOUNDARY: F *= 2 }, g = 10, N = 13, V = 32, S = 45, Y = 58, x = 97, C = 122, I = E((_) => _ | 32, "lower"), p = E(() => {
  45. }, "noop");
  46. const _M = class _M2 {
  47. constructor(o) {
  48. this.index = 0, this.flags = 0, this.onHeaderEnd = p, this.onHeaderField = p, this.onHeadersEnd = p, this.onHeaderValue = p, this.onPartBegin = p, this.onPartData = p, this.onPartEnd = p, this.boundaryChars = {}, o = `\r
  49. --` + o;
  50. const n = new Uint8Array(o.length);
  51. for (let r = 0; r < o.length; r++) n[r] = o.charCodeAt(r), this.boundaryChars[n[r]] = true;
  52. this.boundary = n, this.lookbehind = new Uint8Array(this.boundary.length + 8), this.state = t.START_BOUNDARY;
  53. }
  54. write(o) {
  55. let n = 0;
  56. const r = o.length;
  57. let d = this.index, { lookbehind: l, boundary: c, boundaryChars: m, index: e, state: i, flags: A } = this;
  58. const H = this.boundary.length, O = H - 1, y = o.length;
  59. let a, L;
  60. const f = E((h) => {
  61. this[h + "Mark"] = n;
  62. }, "mark"), s = E((h) => {
  63. delete this[h + "Mark"];
  64. }, "clear"), T = E((h, P, R, k) => {
  65. (P === void 0 || P !== R) && this[h](k && k.subarray(P, R));
  66. }, "callback"), b = E((h, P) => {
  67. const R = h + "Mark";
  68. R in this && (P ? (T(h, this[R], n, o), delete this[R]) : (T(h, this[R], o.length, o), this[R] = 0));
  69. }, "dataCallback");
  70. for (n = 0; n < r; n++) switch (a = o[n], i) {
  71. case t.START_BOUNDARY:
  72. if (e === c.length - 2) {
  73. if (a === S) A |= u.LAST_BOUNDARY;
  74. else if (a !== N) return;
  75. e++;
  76. break;
  77. } else if (e - 1 === c.length - 2) {
  78. if (A & u.LAST_BOUNDARY && a === S) i = t.END, A = 0;
  79. else if (!(A & u.LAST_BOUNDARY) && a === g) e = 0, T("onPartBegin"), i = t.HEADER_FIELD_START;
  80. else return;
  81. break;
  82. }
  83. a !== c[e + 2] && (e = -2), a === c[e + 2] && e++;
  84. break;
  85. case t.HEADER_FIELD_START:
  86. i = t.HEADER_FIELD, f("onHeaderField"), e = 0;
  87. case t.HEADER_FIELD:
  88. if (a === N) {
  89. s("onHeaderField"), i = t.HEADERS_ALMOST_DONE;
  90. break;
  91. }
  92. if (e++, a === S) break;
  93. if (a === Y) {
  94. if (e === 1) return;
  95. b("onHeaderField", true), i = t.HEADER_VALUE_START;
  96. break;
  97. }
  98. if (L = I(a), L < x || L > C) return;
  99. break;
  100. case t.HEADER_VALUE_START:
  101. if (a === V) break;
  102. f("onHeaderValue"), i = t.HEADER_VALUE;
  103. case t.HEADER_VALUE:
  104. a === N && (b("onHeaderValue", true), T("onHeaderEnd"), i = t.HEADER_VALUE_ALMOST_DONE);
  105. break;
  106. case t.HEADER_VALUE_ALMOST_DONE:
  107. if (a !== g) return;
  108. i = t.HEADER_FIELD_START;
  109. break;
  110. case t.HEADERS_ALMOST_DONE:
  111. if (a !== g) return;
  112. T("onHeadersEnd"), i = t.PART_DATA_START;
  113. break;
  114. case t.PART_DATA_START:
  115. i = t.PART_DATA, f("onPartData");
  116. case t.PART_DATA:
  117. if (d = e, e === 0) {
  118. for (n += O; n < y && !(o[n] in m); ) n += H;
  119. n -= O, a = o[n];
  120. }
  121. if (e < c.length) c[e] === a ? (e === 0 && b("onPartData", true), e++) : e = 0;
  122. else if (e === c.length) e++, a === N ? A |= u.PART_BOUNDARY : a === S ? A |= u.LAST_BOUNDARY : e = 0;
  123. else if (e - 1 === c.length) if (A & u.PART_BOUNDARY) {
  124. if (e = 0, a === g) {
  125. A &= ~u.PART_BOUNDARY, T("onPartEnd"), T("onPartBegin"), i = t.HEADER_FIELD_START;
  126. break;
  127. }
  128. } else A & u.LAST_BOUNDARY && a === S ? (T("onPartEnd"), i = t.END, A = 0) : e = 0;
  129. if (e > 0) l[e - 1] = a;
  130. else if (d > 0) {
  131. const h = new Uint8Array(l.buffer, l.byteOffset, l.byteLength);
  132. T("onPartData", 0, d, h), d = 0, f("onPartData"), n--;
  133. }
  134. break;
  135. case t.END:
  136. break;
  137. default:
  138. throw new Error(`Unexpected state entered: ${i}`);
  139. }
  140. b("onHeaderField"), b("onHeaderValue"), b("onPartData"), this.index = e, this.state = i, this.flags = A;
  141. }
  142. end() {
  143. if (this.state === t.HEADER_FIELD_START && this.index === 0 || this.state === t.PART_DATA && this.index === this.boundary.length) this.onPartEnd();
  144. else if (this.state !== t.END) throw new Error("MultipartParser.end(): stream ended unexpectedly");
  145. }
  146. };
  147. E(_M, "MultipartParser");
  148. let M = _M;
  149. function $(_) {
  150. const o = _.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
  151. if (!o) return;
  152. const n = o[2] || o[3] || "";
  153. let r = n.slice(n.lastIndexOf("\\") + 1);
  154. return r = r.replace(/%22/g, '"'), r = r.replace(/&#(\d{4});/g, (d, l) => String.fromCharCode(l)), r;
  155. }
  156. E($, "_fileName");
  157. async function v(_, o) {
  158. if (!/multipart/i.test(o)) throw new TypeError("Failed to fetch");
  159. const n = o.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
  160. if (!n) throw new TypeError("no or bad content-type header, no multipart boundary");
  161. const r = new M(n[1] || n[2]);
  162. let d, l, c, m, e, i;
  163. const A = [], H = new Zt(), O = E((s) => {
  164. c += f.decode(s, { stream: true });
  165. }, "onPartData"), y = E((s) => {
  166. A.push(s);
  167. }, "appendToFile"), a = E(() => {
  168. const s = new Yr(A, i, { type: e });
  169. H.append(m, s);
  170. }, "appendFileToFormData"), L = E(() => {
  171. H.append(m, c);
  172. }, "appendEntryToFormData"), f = new TextDecoder("utf-8");
  173. f.decode(), r.onPartBegin = function() {
  174. r.onPartData = O, r.onPartEnd = L, d = "", l = "", c = "", m = "", e = "", i = null, A.length = 0;
  175. }, r.onHeaderField = function(s) {
  176. d += f.decode(s, { stream: true });
  177. }, r.onHeaderValue = function(s) {
  178. l += f.decode(s, { stream: true });
  179. }, r.onHeaderEnd = function() {
  180. if (l += f.decode(), d = d.toLowerCase(), d === "content-disposition") {
  181. const s = l.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
  182. s && (m = s[2] || s[3] || ""), i = $(l), i && (r.onPartData = y, r.onPartEnd = a);
  183. } else d === "content-type" && (e = l);
  184. l = "", d = "";
  185. };
  186. for await (const s of _) r.write(s);
  187. return r.end(), H;
  188. }
  189. E(v, "toFormData");
  190. export { v as toFormData };
  191. //# sourceMappingURL=multipart-parser-BS1x8A2O.mjs.map