summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-10-28 07:21:00 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-10-28 07:21:00 +0200
commitdc04ca93060443a3ce6263a476f4dafc66afc6b3 (patch)
treeb9c645cbe897af198ea0551509f901a249af35f2 /g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils
parentUpdate config supports_message_history (diff)
downloadgpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.gz
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.bz2
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.lz
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.xz
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.zst
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.zip
Diffstat (limited to 'g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils')
-rw-r--r--g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js54
-rw-r--r--g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/basename.js14
-rw-r--r--g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/decodeText.js26
-rw-r--r--g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/getLimit.js16
-rw-r--r--g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/parseParams.js87
5 files changed, 197 insertions, 0 deletions
diff --git a/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js
new file mode 100644
index 00000000..7917678c
--- /dev/null
+++ b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/Decoder.js
@@ -0,0 +1,54 @@
+'use strict'
+
+const RE_PLUS = /\+/g
+
+const HEX = [
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+]
+
+function Decoder () {
+ this.buffer = undefined
+}
+Decoder.prototype.write = function (str) {
+ // Replace '+' with ' ' before decoding
+ str = str.replace(RE_PLUS, ' ')
+ let res = ''
+ let i = 0; let p = 0; const len = str.length
+ for (; i < len; ++i) {
+ if (this.buffer !== undefined) {
+ if (!HEX[str.charCodeAt(i)]) {
+ res += '%' + this.buffer
+ this.buffer = undefined
+ --i // retry character
+ } else {
+ this.buffer += str[i]
+ ++p
+ if (this.buffer.length === 2) {
+ res += String.fromCharCode(parseInt(this.buffer, 16))
+ this.buffer = undefined
+ }
+ }
+ } else if (str[i] === '%') {
+ if (i > p) {
+ res += str.substring(p, i)
+ p = i
+ }
+ this.buffer = ''
+ ++p
+ }
+ }
+ if (p < len && this.buffer === undefined) { res += str.substring(p) }
+ return res
+}
+Decoder.prototype.reset = function () {
+ this.buffer = undefined
+}
+
+module.exports = Decoder
diff --git a/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/basename.js b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/basename.js
new file mode 100644
index 00000000..db588199
--- /dev/null
+++ b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/basename.js
@@ -0,0 +1,14 @@
+'use strict'
+
+module.exports = function basename (path) {
+ if (typeof path !== 'string') { return '' }
+ for (var i = path.length - 1; i >= 0; --i) { // eslint-disable-line no-var
+ switch (path.charCodeAt(i)) {
+ case 0x2F: // '/'
+ case 0x5C: // '\'
+ path = path.slice(i + 1)
+ return (path === '..' || path === '.' ? '' : path)
+ }
+ }
+ return (path === '..' || path === '.' ? '' : path)
+}
diff --git a/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/decodeText.js b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/decodeText.js
new file mode 100644
index 00000000..ee376062
--- /dev/null
+++ b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/decodeText.js
@@ -0,0 +1,26 @@
+'use strict'
+
+// Node has always utf-8
+const utf8Decoder = new TextDecoder('utf-8')
+const textDecoders = new Map([
+ ['utf-8', utf8Decoder],
+ ['utf8', utf8Decoder]
+])
+
+function decodeText (text, textEncoding, destEncoding) {
+ if (text) {
+ if (textDecoders.has(destEncoding)) {
+ try {
+ return textDecoders.get(destEncoding).decode(Buffer.from(text, textEncoding))
+ } catch (e) { }
+ } else {
+ try {
+ textDecoders.set(destEncoding, new TextDecoder(destEncoding))
+ return textDecoders.get(destEncoding).decode(Buffer.from(text, textEncoding))
+ } catch (e) { }
+ }
+ }
+ return text
+}
+
+module.exports = decodeText
diff --git a/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/getLimit.js b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/getLimit.js
new file mode 100644
index 00000000..cb64fd67
--- /dev/null
+++ b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/getLimit.js
@@ -0,0 +1,16 @@
+'use strict'
+
+module.exports = function getLimit (limits, name, defaultLimit) {
+ if (
+ !limits ||
+ limits[name] === undefined ||
+ limits[name] === null
+ ) { return defaultLimit }
+
+ if (
+ typeof limits[name] !== 'number' ||
+ isNaN(limits[name])
+ ) { throw new TypeError('Limit ' + name + ' is not a valid number') }
+
+ return limits[name]
+}
diff --git a/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/parseParams.js b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/parseParams.js
new file mode 100644
index 00000000..f9214180
--- /dev/null
+++ b/g4f/Provider/npm/node_modules/@fastify/busboy/lib/utils/parseParams.js
@@ -0,0 +1,87 @@
+'use strict'
+
+const decodeText = require('./decodeText')
+
+const RE_ENCODED = /%([a-fA-F0-9]{2})/g
+
+function encodedReplacer (match, byte) {
+ return String.fromCharCode(parseInt(byte, 16))
+}
+
+function parseParams (str) {
+ const res = []
+ let state = 'key'
+ let charset = ''
+ let inquote = false
+ let escaping = false
+ let p = 0
+ let tmp = ''
+
+ for (var i = 0, len = str.length; i < len; ++i) { // eslint-disable-line no-var
+ const char = str[i]
+ if (char === '\\' && inquote) {
+ if (escaping) { escaping = false } else {
+ escaping = true
+ continue
+ }
+ } else if (char === '"') {
+ if (!escaping) {
+ if (inquote) {
+ inquote = false
+ state = 'key'
+ } else { inquote = true }
+ continue
+ } else { escaping = false }
+ } else {
+ if (escaping && inquote) { tmp += '\\' }
+ escaping = false
+ if ((state === 'charset' || state === 'lang') && char === "'") {
+ if (state === 'charset') {
+ state = 'lang'
+ charset = tmp.substring(1)
+ } else { state = 'value' }
+ tmp = ''
+ continue
+ } else if (state === 'key' &&
+ (char === '*' || char === '=') &&
+ res.length) {
+ if (char === '*') { state = 'charset' } else { state = 'value' }
+ res[p] = [tmp, undefined]
+ tmp = ''
+ continue
+ } else if (!inquote && char === ';') {
+ state = 'key'
+ if (charset) {
+ if (tmp.length) {
+ tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer),
+ 'binary',
+ charset)
+ }
+ charset = ''
+ } else if (tmp.length) {
+ tmp = decodeText(tmp, 'binary', 'utf8')
+ }
+ if (res[p] === undefined) { res[p] = tmp } else { res[p][1] = tmp }
+ tmp = ''
+ ++p
+ continue
+ } else if (!inquote && (char === ' ' || char === '\t')) { continue }
+ }
+ tmp += char
+ }
+ if (charset && tmp.length) {
+ tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer),
+ 'binary',
+ charset)
+ } else if (tmp) {
+ tmp = decodeText(tmp, 'binary', 'utf8')
+ }
+
+ if (res[p] === undefined) {
+ if (tmp) { res[p] = tmp }
+ } else { res[p][1] = tmp }
+
+ return res
+}
+
+module.exports = parseParams