frontend performance, rpc/rest jwt authentication

This commit is contained in:
2023-06-22 11:31:24 +02:00
parent 78c1559e84
commit d6c0646756
24 changed files with 691 additions and 360 deletions

View File

@@ -1,61 +0,0 @@
export class CliArguments {
private _extractAudio: boolean;
private _noMTime: boolean;
private _proxy: string;
constructor(extractAudio = false, noMTime = false) {
this._extractAudio = extractAudio;
this._noMTime = noMTime;
this._proxy = ""
}
public get extractAudio(): boolean {
return this._extractAudio;
}
public toggleExtractAudio() {
this._extractAudio = !this._extractAudio;
return this;
}
public disableExtractAudio() {
this._extractAudio = false;
return this;
}
public get noMTime(): boolean {
return this._noMTime;
}
public toggleNoMTime() {
this._noMTime = !this._noMTime;
return this;
}
public toString(): string {
let args = '';
if (this._extractAudio) {
args += '-x '
}
if (this._noMTime) {
args += '--no-mtime '
}
return args.trim();
}
public fromString(str: string): CliArguments {
if (str) {
if (str.includes('-x')) {
this._extractAudio = true;
}
if (str.includes('--no-mtime')) {
this._noMTime = true;
}
}
return this;
}
}

View File

@@ -1,10 +0,0 @@
export function on(eventType: string, listener: any) {
document.addEventListener(eventType, listener)
}
export const serverStates = {
PROC_DOWNLOAD: 'download',
PROC_MERGING: 'merging',
PROC_ABORT: 'abort',
PROG_DONE: 'status_done',
}

View File

@@ -1,28 +0,0 @@
// @ts-nocheck
import i18n from "../../assets/i18n.yaml"
export default class I18nBuilder {
private language: string
private textMap = i18n.languages
constructor(language: string) {
this.language = language
}
getLanguage(): string {
return this.language
}
setLanguage(language: string): void {
this.language = language
}
t(key: string): string {
const map = this.textMap[this.language]
if (map) {
const translation = map[key]
return translation ?? 'caption not defined'
}
return 'caption not defined'
}
}

View File

@@ -1,105 +0,0 @@
import type { DLMetadata, RPCRequest, RPCResponse } from '../../types'
import { webSocket } from 'rxjs/webSocket'
import { getHttpRPCEndpoint, getWebSocketEndpoint } from '../../utils'
export const socket$ = webSocket<any>(getWebSocketEndpoint())
export class RPCClient {
private seq: number
constructor() {
this.seq = 0
}
private incrementSeq() {
return String(this.seq++)
}
private send(req: RPCRequest) {
socket$.next({
...req,
id: this.incrementSeq(),
})
}
private async sendHTTP<T>(req: RPCRequest) {
const res = await fetch(getHttpRPCEndpoint(), {
method: 'POST',
body: JSON.stringify({
...req,
id: this.incrementSeq(),
})
})
const data: RPCResponse<T> = await res.json()
return data
}
public download(url: string, args: string, pathOverride = '', renameTo = '') {
if (url) {
this.send({
method: 'Service.Exec',
params: [{
URL: url.split("?list").at(0)!,
Params: args.split(" ").map(a => a.trim()),
Path: pathOverride,
Rename: renameTo,
}]
})
}
}
public formats(url: string) {
if (url) {
return this.sendHTTP<DLMetadata>({
method: 'Service.Formats',
params: [{
URL: url.split("?list").at(0)!,
}]
})
}
}
public running() {
this.send({
method: 'Service.Running',
params: [],
})
}
public kill(id: string) {
this.send({
method: 'Service.Kill',
params: [id],
})
}
public killAll() {
this.send({
method: 'Service.KillAll',
params: [],
})
}
public freeSpace() {
return this.sendHTTP<number>({
method: 'Service.FreeSpace',
params: [],
})
}
public directoryTree() {
return this.sendHTTP<string[]>({
method: 'Service.DirectoryTree',
params: [],
})
}
public updateExecutable() {
return this.sendHTTP({
method: 'Service.UpdateExecutable',
params: []
})
}
}