Framework updates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2026-03-04 23:20:19 +00:00
parent a89daf3d43
commit 3ed8517b2a
891 changed files with 11126 additions and 9600 deletions

View File

@@ -1,8 +1,8 @@
import util from 'util';
import {Readable} from 'stream';
import utils from "../utils.js";
import readBlob from "./readBlob.js";
import platform from "../platform/index.js";
import { Readable } from 'stream';
import utils from '../utils.js';
import readBlob from './readBlob.js';
import platform from '../platform/index.js';
const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_';
@@ -14,7 +14,7 @@ const CRLF_BYTES_COUNT = 2;
class FormDataPart {
constructor(name, value) {
const {escapeName} = this.constructor;
const { escapeName } = this.constructor;
const isStringValue = utils.isString(value);
let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${
@@ -24,7 +24,7 @@ class FormDataPart {
if (isStringValue) {
value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
} else {
headers += `Content-Type: ${value.type || "application/octet-stream"}${CRLF}`
headers += `Content-Type: ${value.type || 'application/octet-stream'}${CRLF}`;
}
this.headers = textEncoder.encode(headers + CRLF);
@@ -37,12 +37,12 @@ class FormDataPart {
this.value = value;
}
async *encode(){
async *encode() {
yield this.headers;
const {value} = this;
const { value } = this;
if(utils.isTypedArray(value)) {
if (utils.isTypedArray(value)) {
yield value;
} else {
yield* readBlob(value);
@@ -52,11 +52,15 @@ class FormDataPart {
}
static escapeName(name) {
return String(name).replace(/[\r\n"]/g, (match) => ({
'\r' : '%0D',
'\n' : '%0A',
'"' : '%22',
}[match]));
return String(name).replace(
/[\r\n"]/g,
(match) =>
({
'\r': '%0D',
'\n': '%0A',
'"': '%22',
})[match]
);
}
}
@@ -64,15 +68,15 @@ const formDataToStream = (form, headersHandler, options) => {
const {
tag = 'form-data-boundary',
size = 25,
boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET)
boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET),
} = options || {};
if(!utils.isFormData(form)) {
if (!utils.isFormData(form)) {
throw TypeError('FormData instance required');
}
if (boundary.length < 1 || boundary.length > 70) {
throw Error('boundary must be 10-70 characters long')
throw Error('boundary must be 10-70 characters long');
}
const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
@@ -90,8 +94,8 @@ const formDataToStream = (form, headersHandler, options) => {
contentLength = utils.toFiniteNumber(contentLength);
const computedHeaders = {
'Content-Type': `multipart/form-data; boundary=${boundary}`
}
'Content-Type': `multipart/form-data; boundary=${boundary}`,
};
if (Number.isFinite(contentLength)) {
computedHeaders['Content-Length'] = contentLength;
@@ -99,14 +103,16 @@ const formDataToStream = (form, headersHandler, options) => {
headersHandler && headersHandler(computedHeaders);
return Readable.from((async function *() {
for(const part of parts) {
yield boundaryBytes;
yield* part.encode();
}
return Readable.from(
(async function* () {
for (const part of parts) {
yield boundaryBytes;
yield* part.encode();
}
yield footerBytes;
})());
yield footerBytes;
})()
);
};
export default formDataToStream;