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:
19
backend/apis/nodejs/node_modules/formidable/src/parsers/Dummy.js
generated
vendored
Normal file
19
backend/apis/nodejs/node_modules/formidable/src/parsers/Dummy.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
import { Transform } from 'node:stream';
|
||||
|
||||
class DummyParser extends Transform {
|
||||
constructor(incomingForm, options = {}) {
|
||||
super();
|
||||
this.globalOptions = { ...options };
|
||||
this.incomingForm = incomingForm;
|
||||
}
|
||||
|
||||
_flush(callback) {
|
||||
this.incomingForm.ended = true;
|
||||
this.incomingForm._maybeEnd();
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
export default DummyParser;
|
30
backend/apis/nodejs/node_modules/formidable/src/parsers/JSON.js
generated
vendored
Normal file
30
backend/apis/nodejs/node_modules/formidable/src/parsers/JSON.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
import { Transform } from 'node:stream';
|
||||
|
||||
class JSONParser extends 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();
|
||||
}
|
||||
}
|
||||
|
||||
export default JSONParser;
|
356
backend/apis/nodejs/node_modules/formidable/src/parsers/Multipart.js
generated
vendored
Normal file
356
backend/apis/nodejs/node_modules/formidable/src/parsers/Multipart.js
generated
vendored
Normal file
@ -0,0 +1,356 @@
|
||||
/* eslint-disable no-fallthrough */
|
||||
/* eslint-disable no-bitwise */
|
||||
/* eslint-disable no-plusplus */
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
import { Transform } from 'node:stream';
|
||||
import * as errors from '../FormidableError.js';
|
||||
import FormidableError from '../FormidableError.js';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export const STATES = {};
|
||||
|
||||
Object.keys(STATE).forEach((stateName) => {
|
||||
STATES[stateName] = STATE[stateName];
|
||||
});
|
||||
|
||||
class MultipartParser extends 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()}`,
|
||||
errors.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;
|
||||
}
|
||||
};
|
||||
|
||||
export default Object.assign(MultipartParser, { STATES });
|
10
backend/apis/nodejs/node_modules/formidable/src/parsers/OctetStream.js
generated
vendored
Normal file
10
backend/apis/nodejs/node_modules/formidable/src/parsers/OctetStream.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import { PassThrough } from 'node:stream';
|
||||
|
||||
class OctetStreamParser extends PassThrough {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
this.globalOptions = { ...options };
|
||||
}
|
||||
}
|
||||
|
||||
export default OctetStreamParser;
|
33
backend/apis/nodejs/node_modules/formidable/src/parsers/Querystring.js
generated
vendored
Normal file
33
backend/apis/nodejs/node_modules/formidable/src/parsers/Querystring.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
import { Transform } from 'node:stream';
|
||||
|
||||
// This is a buffering parser, have a look at StreamingQuerystring.js for a streaming parser
|
||||
class QuerystringParser extends 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();
|
||||
}
|
||||
}
|
||||
|
||||
export default QuerystringParser;
|
117
backend/apis/nodejs/node_modules/formidable/src/parsers/StreamingQuerystring.js
generated
vendored
Normal file
117
backend/apis/nodejs/node_modules/formidable/src/parsers/StreamingQuerystring.js
generated
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
// not used
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
import { Transform } from 'node:stream';
|
||||
import FormidableError, { maxFieldsSizeExceeded } from '../FormidableError.js';
|
||||
|
||||
const AMPERSAND = 38;
|
||||
const EQUALS = 61;
|
||||
|
||||
class QuerystringParser extends 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 || '' });
|
||||
}
|
||||
}
|
||||
|
||||
export default QuerystringParser;
|
||||
|
||||
// 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()
|
15
backend/apis/nodejs/node_modules/formidable/src/parsers/index.js
generated
vendored
Normal file
15
backend/apis/nodejs/node_modules/formidable/src/parsers/index.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import JSONParser from './JSON.js';
|
||||
import DummyParser from './Dummy.js';
|
||||
import MultipartParser from './Multipart.js';
|
||||
import OctetStreamParser from './OctetStream.js';
|
||||
import QueryStringParser from './Querystring.js';
|
||||
|
||||
export {
|
||||
JSONParser,
|
||||
DummyParser,
|
||||
MultipartParser,
|
||||
OctetStreamParser,
|
||||
OctetStreamParser as OctetstreamParser,
|
||||
QueryStringParser,
|
||||
QueryStringParser as QuerystringParser,
|
||||
};
|
Reference in New Issue
Block a user