node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

104
server/node_modules/koa-compress/lib/encodings.js generated vendored Normal file
View File

@@ -0,0 +1,104 @@
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
const errors = require('http-errors')
const zlib = require('zlib')
class Encodings {
constructor (options = {}) {
this.wildcardAcceptEncoding = options.wildcardAcceptEncoding || Encodings.wildcardAcceptEncoding
this.preferredEncodings = options.preferredEncodings || Encodings.preferredEncodings
this.reDirective = options.reDirective || Encodings.reDirective
this.encodingWeights = new Map()
}
parseAcceptEncoding (acceptEncoding = '*') {
const { encodingWeights, reDirective } = this
acceptEncoding.split(',').forEach((directive) => {
const match = reDirective.exec(directive)
if (!match) return // not a supported encoding above
const encoding = match[1]
// weight must be in [0, 1]
let weight = match[2] && !isNaN(match[2]) ? parseFloat(match[2], 10) : 1
weight = Math.max(weight, 0)
weight = Math.min(weight, 1)
if (encoding === '*') {
// set the weights for the default encodings
this.wildcardAcceptEncoding.forEach((enc) => {
if (!encodingWeights.has(enc)) encodingWeights.set(enc, weight)
})
return
}
encodingWeights.set(encoding, weight)
})
}
getPreferredContentEncoding () {
const {
encodingWeights,
preferredEncodings
} = this
// get ordered list of accepted encodings
const acceptedEncodings = Array.from(encodingWeights.keys())
// sort by weight
.sort((a, b) => encodingWeights.get(b) - encodingWeights.get(a))
// filter by supported encodings
.filter((encoding) => encoding === 'identity' || typeof Encodings.encodingMethods[encoding] === 'function')
// group them by weights
const weightClasses = new Map()
acceptedEncodings.forEach((encoding) => {
const weight = encodingWeights.get(encoding)
if (!weightClasses.has(weight)) weightClasses.set(weight, new Set())
weightClasses.get(weight).add(encoding)
})
// search by weight, descending
const weights = Array.from(weightClasses.keys()).sort((a, b) => b - a)
for (let i = 0; i < weights.length; i++) {
// encodings at this weight
const encodings = weightClasses.get(weights[i])
// return the first encoding in the preferred list
for (let j = 0; j < preferredEncodings.length; j++) {
const preferredEncoding = preferredEncodings[j]
if (encodings.has(preferredEncoding)) return preferredEncoding
}
}
// no encoding matches, check to see if the client set identity, q=0
if (encodingWeights.get('identity') === 0) throw errors(406, 'Please accept br, gzip, deflate, or identity.')
// by default, return nothing
return 'identity'
}
}
Encodings.encodingMethods = {
gzip: zlib.createGzip,
deflate: zlib.createDeflate,
br: zlib.createBrotliCompress
}
Encodings.encodingMethodDefaultOptions = {
gzip: {},
deflate: {},
br: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 4
}
}
}
// how we treat `Accept-Encoding: *`
Encodings.wildcardAcceptEncoding = ['gzip', 'deflate']
// our preferred encodings
Encodings.preferredEncodings = ['br', 'gzip', 'deflate']
Encodings.reDirective = /^\s*(gzip|compress|deflate|br|identity|\*)\s*(?:;\s*q\s*=\s*(\d(?:\.\d)?))?\s*$/
module.exports = Encodings

98
server/node_modules/koa-compress/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,98 @@
'use strict'
/**
* Module dependencies.
*/
const compressible = require('compressible')
const isJSON = require('koa-is-json')
const Stream = require('stream')
const bytes = require('bytes')
const Encodings = require('./encodings')
/**
* Regex to match no-transform directive in a cache-control header
*/
const NO_TRANSFORM_REGEX = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
/**
* empty body statues.
*/
const emptyBodyStatues = new Set([204, 205, 304])
/**
* Compress middleware.
*
* @param {Object} [options]
* @return {Function}
* @api public
*/
module.exports = (options = {}) => {
let { filter = compressible, threshold = 1024, defaultEncoding = 'identity' } = options
if (typeof threshold === 'string') threshold = bytes(threshold)
// `options.br = false` would remove it as a preferred encoding
const preferredEncodings = Encodings.preferredEncodings.filter((encoding) => options[encoding] !== false && options[encoding] !== null)
const encodingOptions = {}
preferredEncodings.forEach((encoding) => {
encodingOptions[encoding] = {
...Encodings.encodingMethodDefaultOptions[encoding],
...(options[encoding] || {})
}
})
Object.assign(compressMiddleware, {
preferredEncodings,
encodingOptions
})
return compressMiddleware
async function compressMiddleware (ctx, next) {
ctx.vary('Accept-Encoding')
await next()
let { body } = ctx
if (
// early exit if there's no content body or the body is already encoded
!body ||
ctx.res.headersSent || !ctx.writable ||
ctx.compress === false ||
ctx.request.method === 'HEAD' ||
emptyBodyStatues.has(+ctx.response.status) ||
ctx.response.get('Content-Encoding') ||
// forced compression or implied
!(ctx.compress === true || filter(ctx.response.type)) ||
// don't compress for Cache-Control: no-transform
// https://tools.ietf.org/html/rfc7234#section-5.2.1.6
NO_TRANSFORM_REGEX.test(ctx.response.get('Cache-Control')) ||
// don't compress if the current response is below the threshold
(threshold && ctx.response.length < threshold)
) return
// get the preferred content encoding
const encodings = new Encodings({ preferredEncodings })
encodings.parseAcceptEncoding(ctx.request.headers['accept-encoding'] || defaultEncoding)
const encoding = encodings.getPreferredContentEncoding()
// identity === no compression
if (encoding === 'identity') return
/** begin compression logic **/
// json
if (isJSON(body)) body = ctx.body = JSON.stringify(body)
ctx.set('Content-Encoding', encoding)
ctx.res.removeHeader('Content-Length')
const compress = Encodings.encodingMethods[encoding]
const stream = ctx.body = compress(encodingOptions[encoding])
if (body instanceof Stream) return body.pipe(stream)
stream.end(body)
}
}