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 {
readonly domain_name: URL;
readonly domainName: URL;
readonly username: string;
readonly password: string;
constructor(readonly config: PeerTubeRequester.Config) {
this.domain_name = new URL("/", config.domain_name);
this.domainName = new URL("/", config.domainName);
this.username = config.username;
this.password = config.password;
}
private async requestAuthToken(): Promise<any> {
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) {
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 } = {
client_id,
client_secret,
grant_type: "password",
response_type: "code",
const clientInfo: { [key: string]: string } = {
clientId,
clientSecret,
grantType: "password",
responseType: "code",
username: this.username,
password: this.password,
};
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",
body: myParams,
});
@ -67,7 +68,7 @@ class PeerTubeRequester {
for (const key in message) myUploadForm.append(key, message[key]);
const response = await fetch(
new URL(`/api/v1/videos/imports`, this.domain_name),
new URL("/api/v1/videos/imports", this.domainName),
{
method: "post",
headers: myHeader,