refactor names inside peertubeRequester.ts

This commit is contained in:
Amaury 2021-07-28 14:20:55 +02:00
parent 82f4a3e6ec
commit 48b73a89bc

View File

@ -17,38 +17,39 @@ type UploadInstruction = {
}; };
class PeerTubeRequester { class PeerTubeRequester {
readonly domain_name: URL; readonly domainName: URL;
readonly username: string; readonly username: string;
readonly password: string; readonly password: string;
constructor(readonly config: PeerTubeRequester.Config) { constructor(readonly config: PeerTubeRequester.Config) {
this.domain_name = new URL("/", config.domain_name); this.domainName = new URL("/", config.domainName);
this.username = config.username; this.username = config.username;
this.password = config.password; this.password = config.password;
} }
private async requestAuthToken(): Promise<any> { private async requestAuthToken(): Promise<any> {
let response = await fetch( let response = await fetch(
new URL(`/api/v1/oauth-clients/local`, this.domain_name) new URL(`/api/v1/oauth-clients/local`, this.domainName)
); );
if (!response.ok) { if (!response.ok) {
throw new Error(response.statusText); // CRASH throw new Error(response.statusText); // CRASH
} }
const { client_id, client_secret } = await response.json(); const { client_id: clientId, client_secret: clientSecret } =
await response.json();
const client_info: { [key: string]: string } = { const clientInfo: { [key: string]: string } = {
client_id, clientId,
client_secret, clientSecret,
grant_type: "password", grantType: "password",
response_type: "code", responseType: "code",
username: this.username, username: this.username,
password: this.password, password: this.password,
}; };
let myParams = new URLSearchParams(); let myParams = new URLSearchParams();
for (const key in client_info) myParams.append(key, client_info[key]); for (const key in clientInfo) myParams.append(key, clientInfo[key]);
response = await fetch(new URL(`/api/v1/users/token`, this.domain_name), { response = await fetch(new URL(`/api/v1/users/token`, this.domainName), {
method: "post", method: "post",
body: myParams, body: myParams,
}); });
@ -67,7 +68,7 @@ class PeerTubeRequester {
for (const key in message) myUploadForm.append(key, message[key]); for (const key in message) myUploadForm.append(key, message[key]);
const response = await fetch( const response = await fetch(
new URL(`/api/v1/videos/imports`, this.domain_name), new URL("/api/v1/videos/imports", this.domainName),
{ {
method: "post", method: "post",
headers: myHeader, headers: myHeader,