Rename last few active API routes

This commit is contained in:
Tiger Oakes
2020-09-25 10:26:05 -07:00
parent 4d74c375f4
commit fe7a3075d6
7 changed files with 106 additions and 72 deletions

View File

@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { PostsService } from 'app/posts.services';
import { Router } from '@angular/router';
import type { FileType } from '../../../api-types';
@Component({
selector: 'app-recent-videos',
@@ -161,7 +162,7 @@ export class RecentVideosComponent implements OnInit {
// normal subscriptions
!new_tab ? this.router.navigate(['/player', {fileNames: file.id,
type: file.isAudio ? 'audio' : 'video', subscriptionName: sub.name,
subPlaylist: sub.isPlaylist}])
subPlaylist: sub.isPlaylist}])
: window.open(`/#/player;fileNames=${file.id};type=${file.isAudio ? 'audio' : 'video'};subscriptionName=${sub.name};subPlaylist=${sub.isPlaylist}`);
}
} else {
@@ -186,7 +187,7 @@ export class RecentVideosComponent implements OnInit {
}
downloadSubscriptionFile(file) {
const type = file.isAudio ? 'audio' : 'video';
const type = (file.isAudio ? 'audio' : 'video') as FileType;
const ext = type === 'audio' ? '.mp3' : '.mp4'
const sub = this.postsService.getSubscriptionByID(file.sub_id);
this.postsService.downloadFileFromServer(file.id, type, null, null, sub.name, sub.isPlaylist,
@@ -199,7 +200,7 @@ export class RecentVideosComponent implements OnInit {
}
downloadNormalFile(file) {
const type = file.isAudio ? 'audio' : 'video';
const type = (file.isAudio ? 'audio' : 'video') as FileType;
const ext = type === 'audio' ? '.mp3' : '.mp4'
const name = file.id;
this.downloading_content[type][name] = true;
@@ -276,7 +277,7 @@ export class RecentVideosComponent implements OnInit {
const result = b.registered - a.registered;
return result;
}
durationStringToNumber(dur_str) {
let num_sum = 0;
const dur_str_parts = dur_str.split(':');

View File

@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { PostsService } from 'app/posts.services';
import { MatSnackBar } from '@angular/material/snack-bar';
import type { UpdaterStatus } from '../../../api-types';
@Component({
selector: 'app-update-progress-dialog',
@@ -9,7 +10,7 @@ import { MatSnackBar } from '@angular/material/snack-bar';
})
export class UpdateProgressDialogComponent implements OnInit {
updateStatus = null;
updateStatus: UpdaterStatus = null;
updateInterval = 250;
errored = false;

View File

@@ -20,7 +20,7 @@ import { CreatePlaylistComponent } from 'app/create-playlist/create-playlist.com
import { Platform } from '@angular/cdk/platform';
import { v4 as uuid } from 'uuid';
import { ArgModifierDialogComponent } from 'app/dialogs/arg-modifier-dialog/arg-modifier-dialog.component';
import type { FileType } from 'api-types';
import type { FileType } from '../../api-types';
export let audioFilesMouseHovering = false;
export let videoFilesMouseHovering = false;
@@ -34,7 +34,7 @@ export interface Download {
percent_complete: number;
downloading: boolean;
is_playlist: boolean;
error: boolean | string;
error?: boolean | string;
fileNames?: string[];
complete?: boolean;
timestamp_start?: number;
@@ -740,7 +740,7 @@ export class MainComponent implements OnInit {
downloadAudioFile(name) {
this.downloading_content['audio'][name] = true;
this.postsService.downloadFileFromServer(name, 'audio').subscribe(res => {
this.postsService.downloadFileFromServer(name, 'audio' as FileType).subscribe(res => {
this.downloading_content['audio'][name] = false;
const blob: Blob = res;
saveAs(blob, decodeURIComponent(name) + '.mp3');
@@ -757,7 +757,7 @@ export class MainComponent implements OnInit {
downloadVideoFile(name) {
this.downloading_content['video'][name] = true;
this.postsService.downloadFileFromServer(name, 'video').subscribe(res => {
this.postsService.downloadFileFromServer(name, 'video' as FileType).subscribe(res => {
this.downloading_content['video'][name] = false;
const blob: Blob = res;
saveAs(blob, decodeURIComponent(name) + '.mp4');

View File

@@ -7,7 +7,7 @@ import { MatSnackBar } from '@angular/material/snack-bar';
import { InputDialogComponent } from 'app/input-dialog/input-dialog.component';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { ShareMediaDialogComponent } from '../dialogs/share-media-dialog/share-media-dialog.component';
import type { FileType } from 'api-types';
import type { FileType } from '../../api-types';
export interface IMedia {
title: string;
@@ -35,7 +35,7 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
// params
fileNames: string[];
type: string;
type: FileType;
id = null; // used for playlists (not subscription)
uid = null; // used for non-subscription files (audio, video, playlist)
subscriptionName = null;
@@ -74,7 +74,7 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
ngOnInit(): void {
this.innerWidth = window.innerWidth;
this.type = this.route.snapshot.paramMap.get('type');
this.type = this.route.snapshot.paramMap.get('type') as FileType;
this.id = this.route.snapshot.paramMap.get('id');
this.uid = this.route.snapshot.paramMap.get('uid');
this.subscriptionName = this.route.snapshot.paramMap.get('subscriptionName');
@@ -160,7 +160,7 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
if (!this.id) {
// regular video/audio file (not playlist)
this.fileNames = [this.db_file['id']];
this.type = this.db_file['isAudio'] ? 'audio' : 'video';
this.type = (this.db_file['isAudio'] ? 'audio' : 'video') as FileType;
if (!already_has_filenames) { this.parseFileNames(); }
}
}

View File

@@ -10,13 +10,19 @@ import { DOCUMENT } from '@angular/common';
import { BehaviorSubject } from 'rxjs';
import { MatSnackBar } from '@angular/material/snack-bar';
import * as Fingerprint2 from 'fingerprintjs2';
import {
import type {
ChangeRolePermissionsRequest,
ChangeUserPermissionsRequest,
ConfigResponse,
CreatePlaylistRequest,
CreatePlaylistResponse,
DeleteMp3Mp4Request,
DeletePlaylistRequest,
DeleteSubscriptionFileRequest,
DownloadArchiveRequest,
DownloadFileRequest,
FileType,
GenerateNewApiKeyResponse,
GetAllDownloadsResponse,
GetAllFilesResponse,
GetAllSubscriptionsResponse,
@@ -35,16 +41,21 @@ import {
Mp4DownloadRequest,
Mp4DownloadResponse,
Playlist,
SetConfigRequest,
SharingToggle,
SubscribeRequest,
SubscribeResponse,
SubscriptionRequestData,
SuccessObject,
UpdaterStatus,
UnsubscribeRequest,
UnsubscribeResponse,
UpdatePlaylistFilesRequest,
UpdatePlaylistRequest,
} from 'api-types';
UpdateServerRequest,
UserPermission,
YesNo,
} from '../api-types';
@Injectable()
export class PostsService implements CanActivate {
@@ -224,7 +235,7 @@ export class PostsService implements CanActivate {
if (isDevMode()) {
return this.http.get('./assets/default.json');
} else {
return this.http.get(this.path + 'config', this.httpOptions);
return this.http.get<ConfigResponse>(this.path + 'config', this.httpOptions);
}
}
@@ -233,7 +244,8 @@ export class PostsService implements CanActivate {
}
setConfig(config) {
return this.http.post(this.path + 'setConfig', {new_config_file: config}, this.httpOptions);
const body: SetConfigRequest = {new_config_file: config};
return this.http.post<SuccessObject>(this.path + 'setConfig', body, this.httpOptions);
}
deleteFile(uid: string, isAudio: boolean, blacklistMode = false) {
@@ -262,19 +274,19 @@ export class PostsService implements CanActivate {
return this.http.post<GetAllFilesResponse>(this.path + 'getAllFiles', {}, this.httpOptions);
}
downloadFileFromServer(fileName, type, outputName = null, fullPathProvided = null, subscriptionName = null, subPlaylist = null,
uid = null, uuid = null, id = null) {
return this.http.post(this.path + 'downloadFile', {fileNames: fileName,
type: type,
zip_mode: Array.isArray(fileName),
outputName: outputName,
fullPathProvided: fullPathProvided,
subscriptionName: subscriptionName,
subPlaylist: subPlaylist,
uuid: uuid,
uid: uid,
id: id
},
downloadFileFromServer(fileName: string | string[], type: FileType, outputName: string = null, fullPathProvided: boolean = null, subscriptionName: boolean = null, subPlaylist: boolean = null,
uid = null, uuid: string = null, id = null) {
const body: DownloadFileRequest = {fileNames: fileName,
type: type,
zip_mode: Array.isArray(fileName),
outputName: outputName,
fullPathProvided: fullPathProvided,
subscriptionName: subscriptionName,
subPlaylist: subPlaylist,
uuid: uuid,
id: id,
};
return this.http.post(this.path + 'downloadFile', body,
{responseType: 'blob', params: this.httpOptions.params});
}
@@ -283,7 +295,8 @@ export class PostsService implements CanActivate {
}
downloadArchive(sub) {
return this.http.post(this.path + 'downloadArchive', {sub: sub}, {responseType: 'blob', params: this.httpOptions.params});
const body: DownloadArchiveRequest = {sub: sub};
return this.http.post(this.path + 'downloadArchive', body, {responseType: 'blob', params: this.httpOptions.params});
}
getFileInfo(fileNames, type, urlMode) {
@@ -299,7 +312,7 @@ export class PostsService implements CanActivate {
}
generateNewAPIKey() {
return this.http.post(this.path + 'generateNewAPIKey', {}, this.httpOptions);
return this.http.post<GenerateNewApiKeyResponse>(this.path + 'generateNewAPIKey', {}, this.httpOptions);
}
enableSharing(uid: string, type: FileType, is_playlist: boolean) {
@@ -393,12 +406,13 @@ export class PostsService implements CanActivate {
}
// updates the server to the latest version
updateServer(tag) {
return this.http.post(this.path + 'updateServer', {tag: tag}, this.httpOptions);
updateServer(tag: string) {
const body: UpdateServerRequest = {tag: tag};
return this.http.post<SuccessObject>(this.path + 'updateServer', body, this.httpOptions);
}
getUpdaterStatus() {
return this.http.get(this.path + 'updaterStatus', this.httpOptions);
return this.http.get<UpdaterStatus>(this.path + 'updaterStatus', this.httpOptions);
}
// gets tag of the latest version of youtubedl-material
@@ -534,11 +548,11 @@ export class PostsService implements CanActivate {
}
changeUser(change_obj) {
return this.http.post(this.path + 'updateUser', {change_object: change_obj}, this.httpOptions);
return this.http.post<SuccessObject>(this.path + 'updateUser', {change_object: change_obj}, this.httpOptions);
}
deleteUser(uid) {
return this.http.post(this.path + 'deleteUser', {uid: uid}, this.httpOptions);
return this.http.post<SuccessObject>(this.path + 'deleteUser', {uid: uid}, this.httpOptions);
}
changeUserPassword(user_uid, new_password) {
@@ -553,13 +567,15 @@ export class PostsService implements CanActivate {
return this.http.post(this.path + 'getRoles', {}, this.httpOptions);
}
setUserPermission(user_uid, permission, new_value) {
return this.http.post(this.path + 'changeUserPermissions', {user_uid: user_uid, permission: permission, new_value: new_value},
setUserPermission(user_uid: string, permission: UserPermission, new_value: YesNo) {
const body: ChangeUserPermissionsRequest = {user_uid: user_uid, permission: permission, new_value: new_value};
return this.http.post<SuccessObject>(this.path + 'changeUserPermissions', body,
this.httpOptions);
}
setRolePermission(role_name, permission, new_value) {
return this.http.post(this.path + 'changeRolePermissions', {role: role_name, permission: permission, new_value: new_value},
setRolePermission(role_name: string, permission: UserPermission, new_value: YesNo) {
const body: ChangeRolePermissionsRequest = {role: role_name, permission: permission, new_value: new_value};
return this.http.post<SuccessObject>(this.path + 'changeRolePermissions', body,
this.httpOptions);
}

View File

@@ -3,6 +3,7 @@ import { PostsService } from 'app/posts.services';
import { ActivatedRoute, Router, ParamMap } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
import { EditSubscriptionDialogComponent } from 'app/dialogs/edit-subscription-dialog/edit-subscription-dialog.component';
import type { FileType } from '../../../api-types';
@Component({
selector: 'app-subscription',
@@ -151,7 +152,7 @@ export class SubscriptionComponent implements OnInit {
}
this.downloading = true;
this.postsService.downloadFileFromServer(fileNames, 'video', this.subscription.name, true).subscribe(res => {
this.postsService.downloadFileFromServer(fileNames, 'video' as FileType, this.subscription.name, true).subscribe(res => {
this.downloading = false;
const blob: Blob = res;
saveAs(blob, this.subscription.name + '.zip');