mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 02:39:46 +02:00
New updates and modules
This commit is contained in:
parent
4d5d408898
commit
0abf0f90f6
959 changed files with 364301 additions and 17493 deletions
33
node_modules/fetch-cookie/node-fetch.js
generated
vendored
Normal file
33
node_modules/fetch-cookie/node-fetch.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
module.exports = function nodeFetchCookieDecorator (nodeFetch, jar) {
|
||||
const fetchCookie = require('./')(nodeFetch, jar)
|
||||
|
||||
return function nodeFetchCookie (url, userOptions = {}) {
|
||||
const opts = Object.assign({}, userOptions, { redirect: 'manual' })
|
||||
|
||||
// Forward identical options to wrapped node-fetch but tell to not handle redirection.
|
||||
return fetchCookie(url, opts)
|
||||
.then(res => {
|
||||
const isRedirect = (res.status === 303 || res.status === 301 || res.status === 302 || res.status === 307)
|
||||
|
||||
// Interpret the proprietary "redirect" option in the same way that node-fetch does.
|
||||
if (isRedirect && userOptions.redirect !== 'manual' && userOptions.follow !== 0) {
|
||||
const statusOpts = {
|
||||
// Since the "follow" flag is not relevant for node-fetch in this case,
|
||||
// we'll hijack it for our internal bookkeeping.
|
||||
follow: userOptions.follow !== undefined ? userOptions.follow - 1 : undefined
|
||||
}
|
||||
|
||||
if (res.status !== 307) {
|
||||
statusOpts.method = 'GET'
|
||||
statusOpts.body = null
|
||||
}
|
||||
|
||||
const redirectOpts = Object.assign({}, userOptions, statusOpts)
|
||||
|
||||
return nodeFetchCookie(res.headers.get('location'), redirectOpts)
|
||||
} else {
|
||||
return res
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue