mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
Change endpoint from persons to people
This commit is contained in:
35
backend/apis/nodejs/node_modules/formidable/dist/parsers/JSON.cjs
generated
vendored
Normal file
35
backend/apis/nodejs/node_modules/formidable/dist/parsers/JSON.cjs
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var node_stream = require('node:stream');
|
||||
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
|
||||
class JSONParser extends node_stream.Transform {
|
||||
constructor(options = {}) {
|
||||
super({ readableObjectMode: true });
|
||||
this.chunks = [];
|
||||
this.globalOptions = { ...options };
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
this.chunks.push(String(chunk)); // todo consider using a string decoder
|
||||
callback();
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
try {
|
||||
const fields = JSON.parse(this.chunks.join(''));
|
||||
this.push(fields);
|
||||
} catch (e) {
|
||||
callback(e);
|
||||
return;
|
||||
}
|
||||
this.chunks = null;
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
exports.default = JSONParser;
|
372
backend/apis/nodejs/node_modules/formidable/dist/parsers/Multipart.cjs
generated
vendored
Normal file
372
backend/apis/nodejs/node_modules/formidable/dist/parsers/Multipart.cjs
generated
vendored
Normal file
@ -0,0 +1,372 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var node_stream = require('node:stream');
|
||||
|
||||
const malformedMultipart = 1012;
|
||||
|
||||
const FormidableError = class extends Error {
|
||||
constructor(message, internalCode, httpCode = 500) {
|
||||
super(message);
|
||||
this.code = internalCode;
|
||||
this.httpCode = httpCode;
|
||||
}
|
||||
};
|
||||
|
||||
/* eslint-disable no-fallthrough */
|
||||
/* eslint-disable no-bitwise */
|
||||
/* eslint-disable no-plusplus */
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
|
||||
let s = 0;
|
||||
const STATE = {
|
||||
PARSER_UNINITIALIZED: s++,
|
||||
START: s++,
|
||||
START_BOUNDARY: s++,
|
||||
HEADER_FIELD_START: s++,
|
||||
HEADER_FIELD: s++,
|
||||
HEADER_VALUE_START: s++,
|
||||
HEADER_VALUE: s++,
|
||||
HEADER_VALUE_ALMOST_DONE: s++,
|
||||
HEADERS_ALMOST_DONE: s++,
|
||||
PART_DATA_START: s++,
|
||||
PART_DATA: s++,
|
||||
PART_END: s++,
|
||||
END: s++,
|
||||
};
|
||||
|
||||
let f = 1;
|
||||
const FBOUNDARY = { PART_BOUNDARY: f, LAST_BOUNDARY: (f *= 2) };
|
||||
|
||||
const LF = 10;
|
||||
const CR = 13;
|
||||
const SPACE = 32;
|
||||
const HYPHEN = 45;
|
||||
const COLON = 58;
|
||||
const A = 97;
|
||||
const Z = 122;
|
||||
|
||||
function lower(c) {
|
||||
return c | 0x20;
|
||||
}
|
||||
|
||||
const STATES = {};
|
||||
|
||||
Object.keys(STATE).forEach((stateName) => {
|
||||
STATES[stateName] = STATE[stateName];
|
||||
});
|
||||
|
||||
class MultipartParser extends node_stream.Transform {
|
||||
constructor(options = {}) {
|
||||
super({ readableObjectMode: true });
|
||||
this.boundary = null;
|
||||
this.boundaryChars = null;
|
||||
this.lookbehind = null;
|
||||
this.bufferLength = 0;
|
||||
this.state = STATE.PARSER_UNINITIALIZED;
|
||||
|
||||
this.globalOptions = { ...options };
|
||||
this.index = null;
|
||||
this.flags = 0;
|
||||
}
|
||||
|
||||
_endUnexpected() {
|
||||
return new FormidableError(
|
||||
`MultipartParser.end(): stream ended unexpectedly: ${this.explain()}`,
|
||||
malformedMultipart,
|
||||
400,
|
||||
);
|
||||
}
|
||||
|
||||
_flush(done) {
|
||||
if (
|
||||
(this.state === STATE.HEADER_FIELD_START && this.index === 0) ||
|
||||
(this.state === STATE.PART_DATA && this.index === this.boundary.length)
|
||||
) {
|
||||
this._handleCallback('partEnd');
|
||||
this._handleCallback('end');
|
||||
done();
|
||||
} else if (this.state !== STATE.END) {
|
||||
done(this._endUnexpected());
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
initWithBoundary(str) {
|
||||
this.boundary = Buffer.from(`\r\n--${str}`);
|
||||
this.lookbehind = Buffer.alloc(this.boundary.length + 8);
|
||||
this.state = STATE.START;
|
||||
this.boundaryChars = {};
|
||||
|
||||
for (let i = 0; i < this.boundary.length; i++) {
|
||||
this.boundaryChars[this.boundary[i]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-params
|
||||
_handleCallback(name, buf, start, end) {
|
||||
if (start !== undefined && start === end) {
|
||||
return;
|
||||
}
|
||||
this.push({ name, buffer: buf, start, end });
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-statements
|
||||
_transform(buffer, _, done) {
|
||||
let i = 0;
|
||||
let prevIndex = this.index;
|
||||
let { index, state, flags } = this;
|
||||
const { lookbehind, boundary, boundaryChars } = this;
|
||||
const boundaryLength = boundary.length;
|
||||
const boundaryEnd = boundaryLength - 1;
|
||||
this.bufferLength = buffer.length;
|
||||
let c = null;
|
||||
let cl = null;
|
||||
|
||||
const setMark = (name, idx) => {
|
||||
this[`${name}Mark`] = typeof idx === 'number' ? idx : i;
|
||||
};
|
||||
|
||||
const clearMarkSymbol = (name) => {
|
||||
delete this[`${name}Mark`];
|
||||
};
|
||||
|
||||
const dataCallback = (name, shouldClear) => {
|
||||
const markSymbol = `${name}Mark`;
|
||||
if (!(markSymbol in this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldClear) {
|
||||
this._handleCallback(name, buffer, this[markSymbol], buffer.length);
|
||||
setMark(name, 0);
|
||||
} else {
|
||||
this._handleCallback(name, buffer, this[markSymbol], i);
|
||||
clearMarkSymbol(name);
|
||||
}
|
||||
};
|
||||
|
||||
for (i = 0; i < this.bufferLength; i++) {
|
||||
c = buffer[i];
|
||||
switch (state) {
|
||||
case STATE.PARSER_UNINITIALIZED:
|
||||
done(this._endUnexpected());
|
||||
return;
|
||||
case STATE.START:
|
||||
index = 0;
|
||||
state = STATE.START_BOUNDARY;
|
||||
case STATE.START_BOUNDARY:
|
||||
if (index === boundary.length - 2) {
|
||||
if (c === HYPHEN) {
|
||||
flags |= FBOUNDARY.LAST_BOUNDARY;
|
||||
} else if (c !== CR) {
|
||||
done(this._endUnexpected());
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
break;
|
||||
} else if (index - 1 === boundary.length - 2) {
|
||||
if (flags & FBOUNDARY.LAST_BOUNDARY && c === HYPHEN) {
|
||||
this._handleCallback('end');
|
||||
state = STATE.END;
|
||||
flags = 0;
|
||||
} else if (!(flags & FBOUNDARY.LAST_BOUNDARY) && c === LF) {
|
||||
index = 0;
|
||||
this._handleCallback('partBegin');
|
||||
state = STATE.HEADER_FIELD_START;
|
||||
} else {
|
||||
done(this._endUnexpected());
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (c !== boundary[index + 2]) {
|
||||
index = -2;
|
||||
}
|
||||
if (c === boundary[index + 2]) {
|
||||
index++;
|
||||
}
|
||||
break;
|
||||
case STATE.HEADER_FIELD_START:
|
||||
state = STATE.HEADER_FIELD;
|
||||
setMark('headerField');
|
||||
index = 0;
|
||||
case STATE.HEADER_FIELD:
|
||||
if (c === CR) {
|
||||
clearMarkSymbol('headerField');
|
||||
state = STATE.HEADERS_ALMOST_DONE;
|
||||
break;
|
||||
}
|
||||
|
||||
index++;
|
||||
if (c === HYPHEN) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (c === COLON) {
|
||||
if (index === 1) {
|
||||
// empty header field
|
||||
done(this._endUnexpected());
|
||||
return;
|
||||
}
|
||||
dataCallback('headerField', true);
|
||||
state = STATE.HEADER_VALUE_START;
|
||||
break;
|
||||
}
|
||||
|
||||
cl = lower(c);
|
||||
if (cl < A || cl > Z) {
|
||||
done(this._endUnexpected());
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case STATE.HEADER_VALUE_START:
|
||||
if (c === SPACE) {
|
||||
break;
|
||||
}
|
||||
|
||||
setMark('headerValue');
|
||||
state = STATE.HEADER_VALUE;
|
||||
case STATE.HEADER_VALUE:
|
||||
if (c === CR) {
|
||||
dataCallback('headerValue', true);
|
||||
this._handleCallback('headerEnd');
|
||||
state = STATE.HEADER_VALUE_ALMOST_DONE;
|
||||
}
|
||||
break;
|
||||
case STATE.HEADER_VALUE_ALMOST_DONE:
|
||||
if (c !== LF) {
|
||||
done(this._endUnexpected());
|
||||
return;
|
||||
}
|
||||
state = STATE.HEADER_FIELD_START;
|
||||
break;
|
||||
case STATE.HEADERS_ALMOST_DONE:
|
||||
if (c !== LF) {
|
||||
done(this._endUnexpected());
|
||||
return;
|
||||
}
|
||||
|
||||
this._handleCallback('headersEnd');
|
||||
state = STATE.PART_DATA_START;
|
||||
break;
|
||||
case STATE.PART_DATA_START:
|
||||
state = STATE.PART_DATA;
|
||||
setMark('partData');
|
||||
case STATE.PART_DATA:
|
||||
prevIndex = index;
|
||||
|
||||
if (index === 0) {
|
||||
// boyer-moore derived algorithm to safely skip non-boundary data
|
||||
i += boundaryEnd;
|
||||
while (i < this.bufferLength && !(buffer[i] in boundaryChars)) {
|
||||
i += boundaryLength;
|
||||
}
|
||||
i -= boundaryEnd;
|
||||
c = buffer[i];
|
||||
}
|
||||
|
||||
if (index < boundary.length) {
|
||||
if (boundary[index] === c) {
|
||||
if (index === 0) {
|
||||
dataCallback('partData', true);
|
||||
}
|
||||
index++;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else if (index === boundary.length) {
|
||||
index++;
|
||||
if (c === CR) {
|
||||
// CR = part boundary
|
||||
flags |= FBOUNDARY.PART_BOUNDARY;
|
||||
} else if (c === HYPHEN) {
|
||||
// HYPHEN = end boundary
|
||||
flags |= FBOUNDARY.LAST_BOUNDARY;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else if (index - 1 === boundary.length) {
|
||||
if (flags & FBOUNDARY.PART_BOUNDARY) {
|
||||
index = 0;
|
||||
if (c === LF) {
|
||||
// unset the PART_BOUNDARY flag
|
||||
flags &= ~FBOUNDARY.PART_BOUNDARY;
|
||||
this._handleCallback('partEnd');
|
||||
this._handleCallback('partBegin');
|
||||
state = STATE.HEADER_FIELD_START;
|
||||
break;
|
||||
}
|
||||
} else if (flags & FBOUNDARY.LAST_BOUNDARY) {
|
||||
if (c === HYPHEN) {
|
||||
this._handleCallback('partEnd');
|
||||
this._handleCallback('end');
|
||||
state = STATE.END;
|
||||
flags = 0;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (index > 0) {
|
||||
// when matching a possible boundary, keep a lookbehind reference
|
||||
// in case it turns out to be a false lead
|
||||
lookbehind[index - 1] = c;
|
||||
} else if (prevIndex > 0) {
|
||||
// if our boundary turned out to be rubbish, the captured lookbehind
|
||||
// belongs to partData
|
||||
this._handleCallback('partData', lookbehind, 0, prevIndex);
|
||||
prevIndex = 0;
|
||||
setMark('partData');
|
||||
|
||||
// reconsider the current character even so it interrupted the sequence
|
||||
// it could be the beginning of a new sequence
|
||||
i--;
|
||||
}
|
||||
|
||||
break;
|
||||
case STATE.END:
|
||||
break;
|
||||
default:
|
||||
done(this._endUnexpected());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
dataCallback('headerField');
|
||||
dataCallback('headerValue');
|
||||
dataCallback('partData');
|
||||
|
||||
this.index = index;
|
||||
this.state = state;
|
||||
this.flags = flags;
|
||||
|
||||
done();
|
||||
return this.bufferLength;
|
||||
}
|
||||
|
||||
explain() {
|
||||
return `state = ${MultipartParser.stateToString(this.state)}`;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
MultipartParser.stateToString = (stateNumber) => {
|
||||
// eslint-disable-next-line no-restricted-syntax, guard-for-in
|
||||
for (const stateName in STATE) {
|
||||
const number = STATE[stateName];
|
||||
if (number === stateNumber) return stateName;
|
||||
}
|
||||
};
|
||||
|
||||
var Multipart = Object.assign(MultipartParser, { STATES });
|
||||
|
||||
exports.STATES = STATES;
|
||||
exports.default = Multipart;
|
14
backend/apis/nodejs/node_modules/formidable/dist/parsers/OctetStream.cjs
generated
vendored
Normal file
14
backend/apis/nodejs/node_modules/formidable/dist/parsers/OctetStream.cjs
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var node_stream = require('node:stream');
|
||||
|
||||
class OctetStreamParser extends node_stream.PassThrough {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
this.globalOptions = { ...options };
|
||||
}
|
||||
}
|
||||
|
||||
exports.default = OctetStreamParser;
|
38
backend/apis/nodejs/node_modules/formidable/dist/parsers/Querystring.cjs
generated
vendored
Normal file
38
backend/apis/nodejs/node_modules/formidable/dist/parsers/Querystring.cjs
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var node_stream = require('node:stream');
|
||||
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
|
||||
// This is a buffering parser, have a look at StreamingQuerystring.js for a streaming parser
|
||||
class QuerystringParser extends node_stream.Transform {
|
||||
constructor(options = {}) {
|
||||
super({ readableObjectMode: true });
|
||||
this.globalOptions = { ...options };
|
||||
this.buffer = '';
|
||||
this.bufferLength = 0;
|
||||
}
|
||||
|
||||
_transform(buffer, encoding, callback) {
|
||||
this.buffer += buffer.toString('ascii');
|
||||
this.bufferLength = this.buffer.length;
|
||||
callback();
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
const fields = new URLSearchParams(this.buffer);
|
||||
for (const [key, value] of fields) {
|
||||
this.push({
|
||||
key,
|
||||
value,
|
||||
});
|
||||
}
|
||||
this.buffer = '';
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
exports.default = QuerystringParser;
|
131
backend/apis/nodejs/node_modules/formidable/dist/parsers/StreamingQuerystring.cjs
generated
vendored
Normal file
131
backend/apis/nodejs/node_modules/formidable/dist/parsers/StreamingQuerystring.cjs
generated
vendored
Normal file
@ -0,0 +1,131 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var node_stream = require('node:stream');
|
||||
|
||||
const maxFieldsSizeExceeded = 1006;
|
||||
|
||||
const FormidableError = class extends Error {
|
||||
constructor(message, internalCode, httpCode = 500) {
|
||||
super(message);
|
||||
this.code = internalCode;
|
||||
this.httpCode = httpCode;
|
||||
}
|
||||
};
|
||||
|
||||
// not used
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
|
||||
const AMPERSAND = 38;
|
||||
const EQUALS = 61;
|
||||
|
||||
class QuerystringParser extends node_stream.Transform {
|
||||
constructor(options = {}) {
|
||||
super({ readableObjectMode: true });
|
||||
|
||||
const { maxFieldSize } = options;
|
||||
this.maxFieldLength = maxFieldSize;
|
||||
this.buffer = Buffer.from('');
|
||||
this.fieldCount = 0;
|
||||
this.sectionStart = 0;
|
||||
this.key = '';
|
||||
this.readingKey = true;
|
||||
}
|
||||
|
||||
_transform(buffer, encoding, callback) {
|
||||
let len = buffer.length;
|
||||
if (this.buffer && this.buffer.length) {
|
||||
// we have some data left over from the last write which we are in the middle of processing
|
||||
len += this.buffer.length;
|
||||
buffer = Buffer.concat([this.buffer, buffer], len);
|
||||
}
|
||||
|
||||
for (let i = this.buffer.length || 0; i < len; i += 1) {
|
||||
const c = buffer[i];
|
||||
if (this.readingKey) {
|
||||
// KEY, check for =
|
||||
if (c === EQUALS) {
|
||||
this.key = this.getSection(buffer, i);
|
||||
this.readingKey = false;
|
||||
this.sectionStart = i + 1;
|
||||
} else if (c === AMPERSAND) {
|
||||
// just key, no value. Prepare to read another key
|
||||
this.emitField(this.getSection(buffer, i));
|
||||
this.sectionStart = i + 1;
|
||||
}
|
||||
// VALUE, check for &
|
||||
} else if (c === AMPERSAND) {
|
||||
this.emitField(this.key, this.getSection(buffer, i));
|
||||
this.sectionStart = i + 1;
|
||||
}
|
||||
|
||||
if (
|
||||
this.maxFieldLength &&
|
||||
i - this.sectionStart === this.maxFieldLength
|
||||
) {
|
||||
callback(
|
||||
new FormidableError(
|
||||
`${
|
||||
this.readingKey ? 'Key' : `Value for ${this.key}`
|
||||
} longer than maxFieldLength`,
|
||||
),
|
||||
maxFieldsSizeExceeded,
|
||||
413,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare the remaining key or value (from sectionStart to the end) for the next write() or for end()
|
||||
len -= this.sectionStart;
|
||||
if (len) {
|
||||
// i.e. Unless the last character was a & or =
|
||||
this.buffer = Buffer.from(this.buffer, 0, this.sectionStart);
|
||||
} else this.buffer = null;
|
||||
|
||||
this.sectionStart = 0;
|
||||
callback();
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
// Emit the last field
|
||||
if (this.readingKey) {
|
||||
// we only have a key if there's something in the buffer. We definitely have no value
|
||||
if (this.buffer && this.buffer.length) {
|
||||
this.emitField(this.buffer.toString('ascii'));
|
||||
}
|
||||
} else {
|
||||
// We have a key, we may or may not have a value
|
||||
this.emitField(
|
||||
this.key,
|
||||
this.buffer && this.buffer.length && this.buffer.toString('ascii'),
|
||||
);
|
||||
}
|
||||
this.buffer = '';
|
||||
callback();
|
||||
}
|
||||
|
||||
getSection(buffer, i) {
|
||||
if (i === this.sectionStart) return '';
|
||||
|
||||
return buffer.toString('ascii', this.sectionStart, i);
|
||||
}
|
||||
|
||||
emitField(key, val) {
|
||||
this.key = '';
|
||||
this.readingKey = true;
|
||||
this.push({ key, value: val || '' });
|
||||
}
|
||||
}
|
||||
|
||||
// const q = new QuerystringParser({maxFieldSize: 100});
|
||||
// (async function() {
|
||||
// for await (const chunk of q) {
|
||||
// console.log(chunk);
|
||||
// }
|
||||
// })();
|
||||
// q.write("a=b&c=d")
|
||||
// q.end()
|
||||
|
||||
exports.default = QuerystringParser;
|
Reference in New Issue
Block a user