aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-11-05 14:11:19 +0100
committerChocobozzz <me@florianbigard.com>2021-11-05 14:11:19 +0100
commitdedcd583b2461895f816c3dd67d56f05d3274f6b (patch)
tree058880eda468f4282cefce275451aa76567a15b8 /server/helpers
parent3233acdadf34045b51da91d42bcd6b3cbf3036f4 (diff)
downloadPeerTube-dedcd583b2461895f816c3dd67d56f05d3274f6b.tar.gz
PeerTube-dedcd583b2461895f816c3dd67d56f05d3274f6b.tar.zst
PeerTube-dedcd583b2461895f816c3dd67d56f05d3274f6b.zip
Fix remote interaction
When we fetch a ressource that is a redirection of another ressource
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/requests.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index 799034b90..57299eee1 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -184,6 +184,16 @@ function isBinaryResponse (result: Response<any>) {
184 return BINARY_CONTENT_TYPES.has(result.headers['content-type']) 184 return BINARY_CONTENT_TYPES.has(result.headers['content-type'])
185} 185}
186 186
187async function findLatestRedirection (url: string, options: PeerTubeRequestOptions, iteration = 1) {
188 if (iteration > 10) throw new Error('Too much iterations to find final URL ' + url)
189
190 const { headers } = await peertubeGot(url, { followRedirect: false, ...buildGotOptions(options) })
191
192 if (headers.location) return findLatestRedirection(headers.location, options, iteration + 1)
193
194 return url
195}
196
187// --------------------------------------------------------------------------- 197// ---------------------------------------------------------------------------
188 198
189export { 199export {
@@ -192,6 +202,7 @@ export {
192 doRequestAndSaveToFile, 202 doRequestAndSaveToFile,
193 isBinaryResponse, 203 isBinaryResponse,
194 downloadImage, 204 downloadImage,
205 findLatestRedirection,
195 peertubeGot 206 peertubeGot
196} 207}
197 208