Rewrite s3 uploader

Update user on upload/boot
This commit is contained in:
René Preuß
2023-03-04 00:07:51 +01:00
parent df803afe2b
commit 03a92e9d85
6 changed files with 152 additions and 82 deletions

View File

@@ -6,10 +6,11 @@ import koaCors from "koa-cors";
import bodyParser from "koa-bodyparser";
import axios, {AxiosInstance} from "axios";
import {app} from "electron"
import {Credentials, User} from "../../shared/schema";
import {Credentials} from "../../shared/schema";
import {SettingsRepository} from "./settings-repository";
import * as fs from "fs";
import {join} from "node:path";
import {resolveUser} from "../main/helpers";
export class InternalServer {
private readonly app: Application;
@@ -50,7 +51,7 @@ export class InternalServer {
expires_in: params.get('expires_in'),
expires_at: this.calculateExpiresAt(params.get('expires_in')),
state: params.get('state'),
user: await this.resolveUser(params.get('access_token'), params.get('token_type')),
user: await resolveUser(params.get('access_token'), params.get('token_type')),
}
console.log('credentials', credentials);
@@ -76,23 +77,6 @@ export class InternalServer {
});
}
private async resolveUser(accessToken: string, tokenType: string): Promise<User> {
const response = await this.axios.get('https://api.rerunmanager.com/v1/channels/me', {
headers: {
'Accept': 'application/json',
'Authorization': `${tokenType} ${accessToken}`,
}
});
return {
id: response.data.id,
name: response.data.name,
config: response.data.config,
avatar_url: response.data.avatar_url,
premium: response.data.premium,
}
}
private calculateExpiresAt(expiresIn: string) {
const now = new Date();
const expiresAt = new Date(now.getTime() + parseInt(expiresIn) * 1000);