]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/utils/requests/requests.ts
Add ability to manually approves instance followers in REST API
[github/Chocobozzz/PeerTube.git] / shared / utils / requests / requests.ts
index 77e9f61645fd79630afde3533b295e6081fff6e7..3532fb429e75801a3c8a6fe840a54dcdfeb1849c 100644 (file)
@@ -1,24 +1,36 @@
 import * as request from 'supertest'
 import { buildAbsoluteFixturePath, root } from '../miscs/miscs'
 import { isAbsolute, join } from 'path'
+import { parse } from 'url'
+
+function get4KFileUrl () {
+  return 'https://download.cpy.re/peertube/4k_file.txt'
+}
+
+function makeRawRequest (url: string, statusCodeExpected?: number, range?: string) {
+  const { host, protocol, pathname } = parse(url)
+
+  return makeGetRequest({ url: `${protocol}//${host}`, path: pathname, statusCodeExpected, range })
+}
 
 function makeGetRequest (options: {
   url: string,
-  path: string,
+  path?: string,
   query?: any,
   token?: string,
   statusCodeExpected?: number,
-  contentType?: string
+  contentType?: string,
+  range?: string
 }) {
   if (!options.statusCodeExpected) options.statusCodeExpected = 400
   if (options.contentType === undefined) options.contentType = 'application/json'
 
-  const req = request(options.url)
-    .get(options.path)
+  const req = request(options.url).get(options.path)
 
   if (options.contentType) req.set('Accept', options.contentType)
   if (options.token) req.set('Authorization', 'Bearer ' + options.token)
   if (options.query) req.query(options.query)
+  if (options.range) req.set('Range', options.range)
 
   return req.expect(options.statusCodeExpected)
 }
@@ -65,6 +77,8 @@ function makeUploadRequest (options: {
   Object.keys(options.fields).forEach(field => {
     const value = options.fields[field]
 
+    if (value === undefined) return
+
     if (Array.isArray(value)) {
       for (let i = 0; i < value.length; i++) {
         req.field(field + '[' + i + ']', value[i])
@@ -158,11 +172,13 @@ function updateAvatarRequest (options: {
 // ---------------------------------------------------------------------------
 
 export {
+  get4KFileUrl,
   makeHTMLRequest,
   makeGetRequest,
   makeUploadRequest,
   makePostBodyRequest,
   makePutBodyRequest,
   makeDeleteRequest,
+  makeRawRequest,
   updateAvatarRequest
 }