]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/requests/requests.ts
Introduce feed command
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / requests / requests.ts
index 8b5cddf4a339010699dfec911cf26d5402f840fb..8c26a3699f99b84dc6e9b6bd862692e3c5ea2573 100644 (file)
@@ -26,6 +26,7 @@ function makeGetRequest (options: {
   contentType?: string
   range?: string
   redirects?: number
+  accept?: string
 }) {
   if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400
   if (options.contentType === undefined) options.contentType = 'application/json'
@@ -36,6 +37,7 @@ function makeGetRequest (options: {
   if (options.token) req.set('Authorization', 'Bearer ' + options.token)
   if (options.query) req.query(options.query)
   if (options.range) req.set('Range', options.range)
+  if (options.accept) req.set('Accept', options.accept)
   if (options.redirects) req.redirects(options.redirects)
 
   return req.expect(options.statusCodeExpected)
@@ -180,6 +182,14 @@ function decodeQueryString (path: string) {
   return decode(path.split('?')[1])
 }
 
+function unwrapBody <T> (test: request.Test): Promise<T> {
+  return test.then(res => res.body)
+}
+
+function unwrapText (test: request.Test): Promise<string> {
+  return test.then(res => res.text)
+}
+
 // ---------------------------------------------------------------------------
 
 export {
@@ -192,5 +202,7 @@ export {
   makePutBodyRequest,
   makeDeleteRequest,
   makeRawRequest,
+  unwrapBody,
+  unwrapText,
   updateImageRequest
 }