Code cleanup

pull/657/head
Isaac Abadi 3 years ago
parent 0951e445ac
commit 4c6c15d3a3

@ -594,7 +594,6 @@ export class MainComponent implements OnInit {
if (simulated_args) { if (simulated_args) {
// hide password if needed // hide password if needed
const passwordIndex = simulated_args.indexOf('--password'); const passwordIndex = simulated_args.indexOf('--password');
console.log(passwordIndex);
if (passwordIndex !== -1 && passwordIndex !== simulated_args.length - 1) { if (passwordIndex !== -1 && passwordIndex !== simulated_args.length - 1) {
simulated_args[passwordIndex + 1] = simulated_args[passwordIndex + 1].replace(/./g, '*'); simulated_args[passwordIndex + 1] = simulated_args[passwordIndex + 1].replace(/./g, '*');
} }

@ -13,6 +13,7 @@ import { moveItemInArray, CdkDragDrop } from '@angular/cdk/drag-drop';
import { InputDialogComponent } from 'app/input-dialog/input-dialog.component'; import { InputDialogComponent } from 'app/input-dialog/input-dialog.component';
import { EditCategoryDialogComponent } from 'app/dialogs/edit-category-dialog/edit-category-dialog.component'; import { EditCategoryDialogComponent } from 'app/dialogs/edit-category-dialog/edit-category-dialog.component';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { Category } from 'api-types';
@Component({ @Component({
selector: 'app-settings', selector: 'app-settings',
@ -62,7 +63,7 @@ export class SettingsComponent implements OnInit {
Object.keys(this.INDEX_TO_TAB).forEach(key => { this.TAB_TO_INDEX[this.INDEX_TO_TAB[key]] = key; }); Object.keys(this.INDEX_TO_TAB).forEach(key => { this.TAB_TO_INDEX[this.INDEX_TO_TAB[key]] = key; });
} }
ngOnInit() { ngOnInit(): void {
if (this.postsService.initialized) { if (this.postsService.initialized) {
this.getConfig(); this.getConfig();
this.getDBInfo(); this.getDBInfo();
@ -90,16 +91,16 @@ export class SettingsComponent implements OnInit {
}); });
} }
getConfig() { getConfig(): void {
this.initial_config = this.postsService.config; this.initial_config = this.postsService.config;
this.new_config = JSON.parse(JSON.stringify(this.initial_config)); this.new_config = JSON.parse(JSON.stringify(this.initial_config));
} }
settingsSame() { settingsSame(): boolean {
return JSON.stringify(this.new_config) === JSON.stringify(this.initial_config); return JSON.stringify(this.new_config) === JSON.stringify(this.initial_config);
} }
saveSettings() { saveSettings(): void {
const settingsToSave = {'YoutubeDLMaterial': this.new_config}; const settingsToSave = {'YoutubeDLMaterial': this.new_config};
this.postsService.setConfig(settingsToSave).subscribe(res => { this.postsService.setConfig(settingsToSave).subscribe(res => {
if (res['success']) { if (res['success']) {
@ -111,31 +112,31 @@ export class SettingsComponent implements OnInit {
this.initial_config = JSON.parse(JSON.stringify(this.new_config)); this.initial_config = JSON.parse(JSON.stringify(this.new_config));
this.postsService.reload_config.next(true); this.postsService.reload_config.next(true);
} }
}, err => { }, () => {
console.error('Failed to save config!'); console.error('Failed to save config!');
}) })
} }
cancelSettings() { cancelSettings(): void {
this.new_config = JSON.parse(JSON.stringify(this.initial_config)); this.new_config = JSON.parse(JSON.stringify(this.initial_config));
} }
tabChanged(event) { tabChanged(event): void {
const index = event['index']; const index = event['index'];
this.router.navigate(['/settings', {tab: this.INDEX_TO_TAB[index]}]); this.router.navigate(['/settings', {tab: this.INDEX_TO_TAB[index]}]);
} }
dropCategory(event: CdkDragDrop<string[]>) { dropCategory(event: CdkDragDrop<string[]>): void {
moveItemInArray(this.postsService.categories, event.previousIndex, event.currentIndex); moveItemInArray(this.postsService.categories, event.previousIndex, event.currentIndex);
this.postsService.updateCategories(this.postsService.categories).subscribe(res => { this.postsService.updateCategories(this.postsService.categories).subscribe(res => {
}, err => { }, () => {
this.postsService.openSnackBar('Failed to update categories!'); this.postsService.openSnackBar('Failed to update categories!');
}); });
} }
openAddCategoryDialog() { openAddCategoryDialog(): void {
const done = new EventEmitter<any>(); const done = new EventEmitter<boolean>();
const dialogRef = this.dialog.open(InputDialogComponent, { const dialogRef = this.dialog.open(InputDialogComponent, {
width: '300px', width: '300px',
data: { data: {
@ -162,7 +163,7 @@ export class SettingsComponent implements OnInit {
}); });
} }
deleteCategory(category) { deleteCategory(category: Category): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, { const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: { data: {
dialogTitle: 'Delete category', dialogTitle: 'Delete category',
@ -178,14 +179,14 @@ export class SettingsComponent implements OnInit {
this.postsService.openSnackBar(`Successfully deleted ${category['name']}!`); this.postsService.openSnackBar(`Successfully deleted ${category['name']}!`);
this.postsService.reloadCategories(); this.postsService.reloadCategories();
} }
}, err => { }, () => {
this.postsService.openSnackBar(`Failed to delete ${category['name']}!`); this.postsService.openSnackBar(`Failed to delete ${category['name']}!`);
}); });
} }
}); });
} }
openEditCategoryDialog(category) { openEditCategoryDialog(category: Category): void {
this.dialog.open(EditCategoryDialogComponent, { this.dialog.open(EditCategoryDialogComponent, {
data: { data: {
category: category category: category
@ -193,7 +194,7 @@ export class SettingsComponent implements OnInit {
}); });
} }
generateAPIKey() { generateAPIKey(): void {
this.postsService.generateNewAPIKey().subscribe(res => { this.postsService.generateNewAPIKey().subscribe(res => {
if (res['new_api_key']) { if (res['new_api_key']) {
this.initial_config.API.API_key = res['new_api_key']; this.initial_config.API.API_key = res['new_api_key'];
@ -202,16 +203,16 @@ export class SettingsComponent implements OnInit {
}); });
} }
localeSelectChanged(new_val) { localeSelectChanged(new_val: string): void {
localStorage.setItem('locale', new_val); localStorage.setItem('locale', new_val);
this.openSnackBar('Language successfully changed! Reload to update the page.') this.postsService.openSnackBar('Language successfully changed! Reload to update the page.')
} }
generateBookmarklet() { generateBookmarklet(): void {
this.bookmarksite('YTDL-Material', this.generated_bookmarklet_code); this.bookmarksite('YTDL-Material', this.generated_bookmarklet_code);
} }
generateBookmarkletCode() { generateBookmarkletCode(): string {
const currentURL = window.location.href.split('#')[0]; const currentURL = window.location.href.split('#')[0];
const homePageWithArgsURL = currentURL + '#/home;url='; const homePageWithArgsURL = currentURL + '#/home;url=';
const audioOnly = this.bookmarkletAudioOnly; const audioOnly = this.bookmarkletAudioOnly;
@ -226,13 +227,13 @@ export class SettingsComponent implements OnInit {
} }
// not currently functioning on most platforms. hence not in use // not currently functioning on most platforms. hence not in use
bookmarksite(title, url) { bookmarksite(title: string, url: string): void {
// Internet Explorer // Internet Explorer
if (document.all) { if (document.all) {
window['external']['AddFavorite'](url, title); window['external']['AddFavorite'](url, title);
} else if (window['chrome']) { } else if (window['chrome']) {
// Google Chrome // Google Chrome
this.openSnackBar('Chrome users must drag the \'Alternate URL\' link to your bookmarks.'); this.postsService.openSnackBar('Chrome users must drag the \'Alternate URL\' link to your bookmarks.');
} else if (window['sidebar']) { } else if (window['sidebar']) {
// Firefox // Firefox
window['sidebar'].addPanel(title, url, ''); window['sidebar'].addPanel(title, url, '');
@ -246,7 +247,7 @@ export class SettingsComponent implements OnInit {
} }
} }
openArgsModifierDialog() { openArgsModifierDialog(): void {
const dialogRef = this.dialog.open(ArgModifierDialogComponent, { const dialogRef = this.dialog.open(ArgModifierDialogComponent, {
data: { data: {
initial_args: this.new_config['Downloader']['custom_args'] initial_args: this.new_config['Downloader']['custom_args']
@ -259,20 +260,20 @@ export class SettingsComponent implements OnInit {
}); });
} }
getLatestGithubRelease() { getLatestGithubRelease(): void {
this.postsService.getLatestGithubRelease().subscribe(res => { this.postsService.getLatestGithubRelease().subscribe(res => {
this.latestGithubRelease = res; this.latestGithubRelease = res;
}); });
} }
openCookiesUploaderDialog() { openCookiesUploaderDialog(): void {
this.dialog.open(CookiesUploaderDialogComponent, { this.dialog.open(CookiesUploaderDialogComponent, {
width: '65vw' width: '65vw'
}); });
} }
killAllDownloads() { killAllDownloads(): void {
const done = new EventEmitter<any>(); const done = new EventEmitter<boolean>();
const dialogRef = this.dialog.open(ConfirmDialogComponent, { const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: { data: {
dialogTitle: 'Kill downloads', dialogTitle: 'Kill downloads',
@ -292,7 +293,7 @@ export class SettingsComponent implements OnInit {
dialogRef.close(); dialogRef.close();
this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.'); this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.');
} }
}, err => { }, () => {
dialogRef.close(); dialogRef.close();
this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.'); this.postsService.openSnackBar('Failed to kill all downloads! Check logs for details.');
}); });
@ -300,21 +301,21 @@ export class SettingsComponent implements OnInit {
}); });
} }
restartServer() { restartServer(): void {
this.postsService.restartServer().subscribe(res => { this.postsService.restartServer().subscribe(() => {
this.postsService.openSnackBar('Restarting!'); this.postsService.openSnackBar('Restarting!');
}, err => { }, () => {
this.postsService.openSnackBar('Failed to restart the server.'); this.postsService.openSnackBar('Failed to restart the server.');
}); });
} }
getDBInfo() { getDBInfo(): void {
this.postsService.getDBInfo().subscribe(res => { this.postsService.getDBInfo().subscribe(res => {
this.db_info = res['db_info']; this.db_info = res['db_info'];
}); });
} }
transferDB() { transferDB(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, { const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: { data: {
dialogTitle: 'Transfer DB', dialogTitle: 'Transfer DB',
@ -329,25 +330,25 @@ export class SettingsComponent implements OnInit {
}); });
} }
_transferDB() { _transferDB(): void {
this.db_transferring = true; this.db_transferring = true;
this.postsService.transferDB(this.db_info['using_local_db']).subscribe(res => { this.postsService.transferDB(this.db_info['using_local_db']).subscribe(res => {
this.db_transferring = false; this.db_transferring = false;
const success = res['success']; const success = res['success'];
if (success) { if (success) {
this.openSnackBar('Successfully transfered DB! Reloading info...'); this.postsService.openSnackBar('Successfully transfered DB! Reloading info...');
this.getDBInfo(); this.getDBInfo();
} else { } else {
this.openSnackBar('Failed to transfer DB -- transfer was aborted. Error: ' + res['error']); this.postsService.openSnackBar('Failed to transfer DB -- transfer was aborted. Error: ' + res['error']);
} }
}, err => { }, err => {
this.db_transferring = false; this.db_transferring = false;
this.openSnackBar('Failed to transfer DB -- API call failed. See browser logs for details.'); this.postsService.openSnackBar('Failed to transfer DB -- API call failed. See browser logs for details.');
console.error(err); console.error(err);
}); });
} }
testConnectionString(connection_string) { testConnectionString(connection_string: string): void {
this.testing_connection_string = true; this.testing_connection_string = true;
this.postsService.testConnectionString(connection_string).subscribe(res => { this.postsService.testConnectionString(connection_string).subscribe(res => {
this.testing_connection_string = false; this.testing_connection_string = false;
@ -356,17 +357,9 @@ export class SettingsComponent implements OnInit {
} else { } else {
this.postsService.openSnackBar('Connection failed! Error: ' + res['error']); this.postsService.openSnackBar('Connection failed! Error: ' + res['error']);
} }
}, err => { }, () => {
this.testing_connection_string = false; this.testing_connection_string = false;
this.postsService.openSnackBar('Connection failed! Error: Server error. See logs for more info.'); this.postsService.openSnackBar('Connection failed! Error: Server error. See logs for more info.');
}); });
} }
// snackbar helper
public openSnackBar(message: string, action: string = '') {
this.snackBar.open(message, action, {
duration: 2000,
});
}
} }

Loading…
Cancel
Save