Started adding slash commands, doesn't work though

This commit is contained in:
ION606
2022-09-26 15:41:20 +00:00
parent b6495eb886
commit ec4c1200d5
2214 changed files with 159174 additions and 42761 deletions
+45 -2
View File
@@ -1,7 +1,7 @@
/*!
* raw-body
* Copyright(c) 2013-2014 Jonathan Ong
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* Copyright(c) 2014-2022 Douglas Christopher Wilson
* MIT Licensed
*/
@@ -12,6 +12,7 @@
* @private
*/
var asyncHooks = tryRequireAsyncHooks()
var bytes = require('bytes')
var createError = require('http-errors')
var iconv = require('iconv-lite')
@@ -105,7 +106,7 @@ function getRawBody (stream, options, callback) {
if (done) {
// classic callback style
return readStream(stream, encoding, length, limit, done)
return readStream(stream, encoding, length, limit, wrap(done))
}
return new Promise(function executor (resolve, reject) {
@@ -173,6 +174,12 @@ function readStream (stream, encoding, length, limit, callback) {
}))
}
if (typeof stream.readable !== 'undefined' && !stream.readable) {
return done(createError(500, 'stream is not readable', {
type: 'stream.not.readable'
}))
}
var received = 0
var decoder
@@ -284,3 +291,39 @@ function readStream (stream, encoding, length, limit, callback) {
stream.removeListener('close', cleanup)
}
}
/**
* Try to require async_hooks
* @private
*/
function tryRequireAsyncHooks () {
try {
return require('async_hooks')
} catch (e) {
return {}
}
}
/**
* Wrap function with async resource, if possible.
* AsyncResource.bind static method backported.
* @private
*/
function wrap (fn) {
var res
// create anonymous resource
if (asyncHooks.AsyncResource) {
res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn')
}
// incompatible node.js
if (!res || !res.runInAsyncScope) {
return fn
}
// return bound function
return res.runInAsyncScope.bind(res, fn, null)
}