Ca marche pas trop mal
This commit is contained in:
		| @@ -1,13 +1,13 @@ | ||||
| // import { ImplementableApi } from './implementableApi'; | ||||
| // Api request lib | ||||
| import fetch, { FetchError, Headers } from "node-fetch"; | ||||
| import { URLSearchParams } from "url"; | ||||
| import { URL, URLSearchParams } from "url"; | ||||
| import FormData from "form-data"; | ||||
| // import dedent from "ts-dedent"; | ||||
|  | ||||
| namespace PeerTubeRequester { | ||||
|   export type Config = { | ||||
|     domain_name: string; | ||||
|     domain_name: string | URL; | ||||
|     username: string; | ||||
|     password: string; | ||||
|   }; | ||||
| @@ -36,19 +36,19 @@ type UserToken = { | ||||
| }; | ||||
|  | ||||
| class PeerTubeRequester { | ||||
|   readonly domain_name: string; | ||||
|   readonly domain_name: URL; | ||||
|   readonly username: string; | ||||
|   readonly password: string; | ||||
|  | ||||
|   constructor(readonly config: PeerTubeRequester.Config) { | ||||
|     this.domain_name = config.domain_name; | ||||
|     this.domain_name = new URL("/", config.domain_name); | ||||
|     this.username = config.username; | ||||
|     this.password = config.password; | ||||
|   } | ||||
|  | ||||
|   async apiRequest(message: UploadInstruction): Promise<void> { | ||||
|     let response = await fetch( | ||||
|       `${this.domain_name}/api/v1/oauth-clients/local` | ||||
|       new URL(`/api/v1/oauth-clients/local`, this.domain_name) | ||||
|     ); | ||||
|     if (!response.ok) { | ||||
|       throw new Error(response.statusText); // CRASH | ||||
| @@ -67,7 +67,7 @@ class PeerTubeRequester { | ||||
|     let myParams = new URLSearchParams(); | ||||
|     for (const key in client_info) myParams.append(key, client_info[key]); | ||||
|  | ||||
|     response = await fetch(`${this.domain_name}/api/v1/users/token`, { | ||||
|     response = await fetch(new URL(`/api/v1/users/token`, this.domain_name), { | ||||
|       method: "post", | ||||
|       body: myParams, | ||||
|     }); | ||||
| @@ -82,11 +82,14 @@ class PeerTubeRequester { | ||||
|     myHeader.append("Authorization", `Bearer ${access_token}`); | ||||
|     for (const key in message) myUploadForm.append(key, message[key]); | ||||
|  | ||||
|     response = await fetch(`${this.domain_name}/api/v1/videos/imports`, { | ||||
|       method: "post", | ||||
|       // headers: myHeader, | ||||
|       body: myUploadForm, | ||||
|     }); | ||||
|     response = await fetch( | ||||
|       new URL(`/api/v1/videos/imports`, this.domain_name), | ||||
|       { | ||||
|         method: "post", | ||||
|         headers: myHeader, | ||||
|         body: myUploadForm, | ||||
|       } | ||||
|     ); | ||||
|  | ||||
|     if (!response.ok) { | ||||
|       switch (response.status) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user