Add files via upload

This commit is contained in:
deep-soft 2023-12-12 21:51:53 +02:00 committed by GitHub
parent 41a0a57a73
commit 98f9765d99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 455 additions and 453 deletions

902
dist/37.index.js vendored
View file

@ -1,452 +1,452 @@
"use strict"; "use strict";
exports.id = 37; exports.id = 37;
exports.ids = [37]; exports.ids = [37];
exports.modules = { exports.modules = {
/***/ 4037: /***/ 4037:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "toFormData": () => (/* binding */ toFormData) /* harmony export */ "toFormData": () => (/* binding */ toFormData)
/* harmony export */ }); /* harmony export */ });
/* harmony import */ var fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2777); /* harmony import */ var fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2777);
/* harmony import */ var formdata_polyfill_esm_min_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8010); /* harmony import */ var formdata_polyfill_esm_min_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8010);
let s = 0; let s = 0;
const S = { const S = {
START_BOUNDARY: s++, START_BOUNDARY: s++,
HEADER_FIELD_START: s++, HEADER_FIELD_START: s++,
HEADER_FIELD: s++, HEADER_FIELD: s++,
HEADER_VALUE_START: s++, HEADER_VALUE_START: s++,
HEADER_VALUE: s++, HEADER_VALUE: s++,
HEADER_VALUE_ALMOST_DONE: s++, HEADER_VALUE_ALMOST_DONE: s++,
HEADERS_ALMOST_DONE: s++, HEADERS_ALMOST_DONE: s++,
PART_DATA_START: s++, PART_DATA_START: s++,
PART_DATA: s++, PART_DATA: s++,
END: s++ END: s++
}; };
let f = 1; let f = 1;
const F = { const F = {
PART_BOUNDARY: f, PART_BOUNDARY: f,
LAST_BOUNDARY: f *= 2 LAST_BOUNDARY: f *= 2
}; };
const LF = 10; const LF = 10;
const CR = 13; const CR = 13;
const SPACE = 32; const SPACE = 32;
const HYPHEN = 45; const HYPHEN = 45;
const COLON = 58; const COLON = 58;
const A = 97; const A = 97;
const Z = 122; const Z = 122;
const lower = c => c | 0x20; const lower = c => c | 0x20;
const noop = () => {}; const noop = () => {};
class MultipartParser { class MultipartParser {
/** /**
* @param {string} boundary * @param {string} boundary
*/ */
constructor(boundary) { constructor(boundary) {
this.index = 0; this.index = 0;
this.flags = 0; this.flags = 0;
this.onHeaderEnd = noop; this.onHeaderEnd = noop;
this.onHeaderField = noop; this.onHeaderField = noop;
this.onHeadersEnd = noop; this.onHeadersEnd = noop;
this.onHeaderValue = noop; this.onHeaderValue = noop;
this.onPartBegin = noop; this.onPartBegin = noop;
this.onPartData = noop; this.onPartData = noop;
this.onPartEnd = noop; this.onPartEnd = noop;
this.boundaryChars = {}; this.boundaryChars = {};
boundary = '\r\n--' + boundary; boundary = '\r\n--' + boundary;
const ui8a = new Uint8Array(boundary.length); const ui8a = new Uint8Array(boundary.length);
for (let i = 0; i < boundary.length; i++) { for (let i = 0; i < boundary.length; i++) {
ui8a[i] = boundary.charCodeAt(i); ui8a[i] = boundary.charCodeAt(i);
this.boundaryChars[ui8a[i]] = true; this.boundaryChars[ui8a[i]] = true;
} }
this.boundary = ui8a; this.boundary = ui8a;
this.lookbehind = new Uint8Array(this.boundary.length + 8); this.lookbehind = new Uint8Array(this.boundary.length + 8);
this.state = S.START_BOUNDARY; this.state = S.START_BOUNDARY;
} }
/** /**
* @param {Uint8Array} data * @param {Uint8Array} data
*/ */
write(data) { write(data) {
let i = 0; let i = 0;
const length_ = data.length; const length_ = data.length;
let previousIndex = this.index; let previousIndex = this.index;
let {lookbehind, boundary, boundaryChars, index, state, flags} = this; let {lookbehind, boundary, boundaryChars, index, state, flags} = this;
const boundaryLength = this.boundary.length; const boundaryLength = this.boundary.length;
const boundaryEnd = boundaryLength - 1; const boundaryEnd = boundaryLength - 1;
const bufferLength = data.length; const bufferLength = data.length;
let c; let c;
let cl; let cl;
const mark = name => { const mark = name => {
this[name + 'Mark'] = i; this[name + 'Mark'] = i;
}; };
const clear = name => { const clear = name => {
delete this[name + 'Mark']; delete this[name + 'Mark'];
}; };
const callback = (callbackSymbol, start, end, ui8a) => { const callback = (callbackSymbol, start, end, ui8a) => {
if (start === undefined || start !== end) { if (start === undefined || start !== end) {
this[callbackSymbol](ui8a && ui8a.subarray(start, end)); this[callbackSymbol](ui8a && ui8a.subarray(start, end));
} }
}; };
const dataCallback = (name, clear) => { const dataCallback = (name, clear) => {
const markSymbol = name + 'Mark'; const markSymbol = name + 'Mark';
if (!(markSymbol in this)) { if (!(markSymbol in this)) {
return; return;
} }
if (clear) { if (clear) {
callback(name, this[markSymbol], i, data); callback(name, this[markSymbol], i, data);
delete this[markSymbol]; delete this[markSymbol];
} else { } else {
callback(name, this[markSymbol], data.length, data); callback(name, this[markSymbol], data.length, data);
this[markSymbol] = 0; this[markSymbol] = 0;
} }
}; };
for (i = 0; i < length_; i++) { for (i = 0; i < length_; i++) {
c = data[i]; c = data[i];
switch (state) { switch (state) {
case S.START_BOUNDARY: case S.START_BOUNDARY:
if (index === boundary.length - 2) { if (index === boundary.length - 2) {
if (c === HYPHEN) { if (c === HYPHEN) {
flags |= F.LAST_BOUNDARY; flags |= F.LAST_BOUNDARY;
} else if (c !== CR) { } else if (c !== CR) {
return; return;
} }
index++; index++;
break; break;
} else if (index - 1 === boundary.length - 2) { } else if (index - 1 === boundary.length - 2) {
if (flags & F.LAST_BOUNDARY && c === HYPHEN) { if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
state = S.END; state = S.END;
flags = 0; flags = 0;
} else if (!(flags & F.LAST_BOUNDARY) && c === LF) { } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
index = 0; index = 0;
callback('onPartBegin'); callback('onPartBegin');
state = S.HEADER_FIELD_START; state = S.HEADER_FIELD_START;
} else { } else {
return; return;
} }
break; break;
} }
if (c !== boundary[index + 2]) { if (c !== boundary[index + 2]) {
index = -2; index = -2;
} }
if (c === boundary[index + 2]) { if (c === boundary[index + 2]) {
index++; index++;
} }
break; break;
case S.HEADER_FIELD_START: case S.HEADER_FIELD_START:
state = S.HEADER_FIELD; state = S.HEADER_FIELD;
mark('onHeaderField'); mark('onHeaderField');
index = 0; index = 0;
// falls through // falls through
case S.HEADER_FIELD: case S.HEADER_FIELD:
if (c === CR) { if (c === CR) {
clear('onHeaderField'); clear('onHeaderField');
state = S.HEADERS_ALMOST_DONE; state = S.HEADERS_ALMOST_DONE;
break; break;
} }
index++; index++;
if (c === HYPHEN) { if (c === HYPHEN) {
break; break;
} }
if (c === COLON) { if (c === COLON) {
if (index === 1) { if (index === 1) {
// empty header field // empty header field
return; return;
} }
dataCallback('onHeaderField', true); dataCallback('onHeaderField', true);
state = S.HEADER_VALUE_START; state = S.HEADER_VALUE_START;
break; break;
} }
cl = lower(c); cl = lower(c);
if (cl < A || cl > Z) { if (cl < A || cl > Z) {
return; return;
} }
break; break;
case S.HEADER_VALUE_START: case S.HEADER_VALUE_START:
if (c === SPACE) { if (c === SPACE) {
break; break;
} }
mark('onHeaderValue'); mark('onHeaderValue');
state = S.HEADER_VALUE; state = S.HEADER_VALUE;
// falls through // falls through
case S.HEADER_VALUE: case S.HEADER_VALUE:
if (c === CR) { if (c === CR) {
dataCallback('onHeaderValue', true); dataCallback('onHeaderValue', true);
callback('onHeaderEnd'); callback('onHeaderEnd');
state = S.HEADER_VALUE_ALMOST_DONE; state = S.HEADER_VALUE_ALMOST_DONE;
} }
break; break;
case S.HEADER_VALUE_ALMOST_DONE: case S.HEADER_VALUE_ALMOST_DONE:
if (c !== LF) { if (c !== LF) {
return; return;
} }
state = S.HEADER_FIELD_START; state = S.HEADER_FIELD_START;
break; break;
case S.HEADERS_ALMOST_DONE: case S.HEADERS_ALMOST_DONE:
if (c !== LF) { if (c !== LF) {
return; return;
} }
callback('onHeadersEnd'); callback('onHeadersEnd');
state = S.PART_DATA_START; state = S.PART_DATA_START;
break; break;
case S.PART_DATA_START: case S.PART_DATA_START:
state = S.PART_DATA; state = S.PART_DATA;
mark('onPartData'); mark('onPartData');
// falls through // falls through
case S.PART_DATA: case S.PART_DATA:
previousIndex = index; previousIndex = index;
if (index === 0) { if (index === 0) {
// boyer-moore derrived algorithm to safely skip non-boundary data // boyer-moore derrived algorithm to safely skip non-boundary data
i += boundaryEnd; i += boundaryEnd;
while (i < bufferLength && !(data[i] in boundaryChars)) { while (i < bufferLength && !(data[i] in boundaryChars)) {
i += boundaryLength; i += boundaryLength;
} }
i -= boundaryEnd; i -= boundaryEnd;
c = data[i]; c = data[i];
} }
if (index < boundary.length) { if (index < boundary.length) {
if (boundary[index] === c) { if (boundary[index] === c) {
if (index === 0) { if (index === 0) {
dataCallback('onPartData', true); dataCallback('onPartData', true);
} }
index++; index++;
} else { } else {
index = 0; index = 0;
} }
} else if (index === boundary.length) { } else if (index === boundary.length) {
index++; index++;
if (c === CR) { if (c === CR) {
// CR = part boundary // CR = part boundary
flags |= F.PART_BOUNDARY; flags |= F.PART_BOUNDARY;
} else if (c === HYPHEN) { } else if (c === HYPHEN) {
// HYPHEN = end boundary // HYPHEN = end boundary
flags |= F.LAST_BOUNDARY; flags |= F.LAST_BOUNDARY;
} else { } else {
index = 0; index = 0;
} }
} else if (index - 1 === boundary.length) { } else if (index - 1 === boundary.length) {
if (flags & F.PART_BOUNDARY) { if (flags & F.PART_BOUNDARY) {
index = 0; index = 0;
if (c === LF) { if (c === LF) {
// unset the PART_BOUNDARY flag // unset the PART_BOUNDARY flag
flags &= ~F.PART_BOUNDARY; flags &= ~F.PART_BOUNDARY;
callback('onPartEnd'); callback('onPartEnd');
callback('onPartBegin'); callback('onPartBegin');
state = S.HEADER_FIELD_START; state = S.HEADER_FIELD_START;
break; break;
} }
} else if (flags & F.LAST_BOUNDARY) { } else if (flags & F.LAST_BOUNDARY) {
if (c === HYPHEN) { if (c === HYPHEN) {
callback('onPartEnd'); callback('onPartEnd');
state = S.END; state = S.END;
flags = 0; flags = 0;
} else { } else {
index = 0; index = 0;
} }
} else { } else {
index = 0; index = 0;
} }
} }
if (index > 0) { if (index > 0) {
// when matching a possible boundary, keep a lookbehind reference // when matching a possible boundary, keep a lookbehind reference
// in case it turns out to be a false lead // in case it turns out to be a false lead
lookbehind[index - 1] = c; lookbehind[index - 1] = c;
} else if (previousIndex > 0) { } else if (previousIndex > 0) {
// if our boundary turned out to be rubbish, the captured lookbehind // if our boundary turned out to be rubbish, the captured lookbehind
// belongs to partData // belongs to partData
const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength); const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
callback('onPartData', 0, previousIndex, _lookbehind); callback('onPartData', 0, previousIndex, _lookbehind);
previousIndex = 0; previousIndex = 0;
mark('onPartData'); mark('onPartData');
// reconsider the current character even so it interrupted the sequence // reconsider the current character even so it interrupted the sequence
// it could be the beginning of a new sequence // it could be the beginning of a new sequence
i--; i--;
} }
break; break;
case S.END: case S.END:
break; break;
default: default:
throw new Error(`Unexpected state entered: ${state}`); throw new Error(`Unexpected state entered: ${state}`);
} }
} }
dataCallback('onHeaderField'); dataCallback('onHeaderField');
dataCallback('onHeaderValue'); dataCallback('onHeaderValue');
dataCallback('onPartData'); dataCallback('onPartData');
// Update properties for the next call // Update properties for the next call
this.index = index; this.index = index;
this.state = state; this.state = state;
this.flags = flags; this.flags = flags;
} }
end() { end() {
if ((this.state === S.HEADER_FIELD_START && this.index === 0) || if ((this.state === S.HEADER_FIELD_START && this.index === 0) ||
(this.state === S.PART_DATA && this.index === this.boundary.length)) { (this.state === S.PART_DATA && this.index === this.boundary.length)) {
this.onPartEnd(); this.onPartEnd();
} else if (this.state !== S.END) { } else if (this.state !== S.END) {
throw new Error('MultipartParser.end(): stream ended unexpectedly'); throw new Error('MultipartParser.end(): stream ended unexpectedly');
} }
} }
} }
function _fileName(headerValue) { function _fileName(headerValue) {
// matches either a quoted-string or a token (RFC 2616 section 19.5.1) // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i); const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
if (!m) { if (!m) {
return; return;
} }
const match = m[2] || m[3] || ''; const match = m[2] || m[3] || '';
let filename = match.slice(match.lastIndexOf('\\') + 1); let filename = match.slice(match.lastIndexOf('\\') + 1);
filename = filename.replace(/%22/g, '"'); filename = filename.replace(/%22/g, '"');
filename = filename.replace(/&#(\d{4});/g, (m, code) => { filename = filename.replace(/&#(\d{4});/g, (m, code) => {
return String.fromCharCode(code); return String.fromCharCode(code);
}); });
return filename; return filename;
} }
async function toFormData(Body, ct) { async function toFormData(Body, ct) {
if (!/multipart/i.test(ct)) { if (!/multipart/i.test(ct)) {
throw new TypeError('Failed to fetch'); throw new TypeError('Failed to fetch');
} }
const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i); const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
if (!m) { if (!m) {
throw new TypeError('no or bad content-type header, no multipart boundary'); throw new TypeError('no or bad content-type header, no multipart boundary');
} }
const parser = new MultipartParser(m[1] || m[2]); const parser = new MultipartParser(m[1] || m[2]);
let headerField; let headerField;
let headerValue; let headerValue;
let entryValue; let entryValue;
let entryName; let entryName;
let contentType; let contentType;
let filename; let filename;
const entryChunks = []; const entryChunks = [];
const formData = new formdata_polyfill_esm_min_js__WEBPACK_IMPORTED_MODULE_1__/* .FormData */ .Ct(); const formData = new formdata_polyfill_esm_min_js__WEBPACK_IMPORTED_MODULE_1__/* .FormData */ .Ct();
const onPartData = ui8a => { const onPartData = ui8a => {
entryValue += decoder.decode(ui8a, {stream: true}); entryValue += decoder.decode(ui8a, {stream: true});
}; };
const appendToFile = ui8a => { const appendToFile = ui8a => {
entryChunks.push(ui8a); entryChunks.push(ui8a);
}; };
const appendFileToFormData = () => { const appendFileToFormData = () => {
const file = new fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__/* .File */ .$B(entryChunks, filename, {type: contentType}); const file = new fetch_blob_from_js__WEBPACK_IMPORTED_MODULE_0__/* .File */ .$B(entryChunks, filename, {type: contentType});
formData.append(entryName, file); formData.append(entryName, file);
}; };
const appendEntryToFormData = () => { const appendEntryToFormData = () => {
formData.append(entryName, entryValue); formData.append(entryName, entryValue);
}; };
const decoder = new TextDecoder('utf-8'); const decoder = new TextDecoder('utf-8');
decoder.decode(); decoder.decode();
parser.onPartBegin = function () { parser.onPartBegin = function () {
parser.onPartData = onPartData; parser.onPartData = onPartData;
parser.onPartEnd = appendEntryToFormData; parser.onPartEnd = appendEntryToFormData;
headerField = ''; headerField = '';
headerValue = ''; headerValue = '';
entryValue = ''; entryValue = '';
entryName = ''; entryName = '';
contentType = ''; contentType = '';
filename = null; filename = null;
entryChunks.length = 0; entryChunks.length = 0;
}; };
parser.onHeaderField = function (ui8a) { parser.onHeaderField = function (ui8a) {
headerField += decoder.decode(ui8a, {stream: true}); headerField += decoder.decode(ui8a, {stream: true});
}; };
parser.onHeaderValue = function (ui8a) { parser.onHeaderValue = function (ui8a) {
headerValue += decoder.decode(ui8a, {stream: true}); headerValue += decoder.decode(ui8a, {stream: true});
}; };
parser.onHeaderEnd = function () { parser.onHeaderEnd = function () {
headerValue += decoder.decode(); headerValue += decoder.decode();
headerField = headerField.toLowerCase(); headerField = headerField.toLowerCase();
if (headerField === 'content-disposition') { if (headerField === 'content-disposition') {
// matches either a quoted-string or a token (RFC 2616 section 19.5.1) // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i); const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
if (m) { if (m) {
entryName = m[2] || m[3] || ''; entryName = m[2] || m[3] || '';
} }
filename = _fileName(headerValue); filename = _fileName(headerValue);
if (filename) { if (filename) {
parser.onPartData = appendToFile; parser.onPartData = appendToFile;
parser.onPartEnd = appendFileToFormData; parser.onPartEnd = appendFileToFormData;
} }
} else if (headerField === 'content-type') { } else if (headerField === 'content-type') {
contentType = headerValue; contentType = headerValue;
} }
headerValue = ''; headerValue = '';
headerField = ''; headerField = '';
}; };
for await (const chunk of Body) { for await (const chunk of Body) {
parser.write(chunk); parser.write(chunk);
} }
parser.end(); parser.end();
return formData; return formData;
} }
/***/ }) /***/ })
}; };
; ;

6
dist/index.js vendored

File diff suppressed because one or more lines are too long