diff options
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r-- | server/helpers/requests.ts | 11 |
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 | ||
187 | async 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 | ||
189 | export { | 199 | export { |
@@ -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 | ||