Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
digimezzo committed Nov 6, 2023
1 parent 26d7292 commit 1031300
Show file tree
Hide file tree
Showing 88 changed files with 261 additions and 313 deletions.
6 changes: 3 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { AppComponent } from './app.component';
import { FanartApi } from './common/api/fanart/fanart.api';
import { GitHubApi } from './common/api/git-hub/git-hub.api';
import { LastfmApi } from './common/api/lastfm/lastfm.api';
import { ContextMenuOpener } from './common/context-menu-opener';
import { AlbumKeyGenerator } from './data/album-key-generator';
import { DatabaseFactory } from './data/database-factory';
import { DatabaseMigrator } from './data/database-migrator';
Expand All @@ -44,7 +43,6 @@ import { FolderTrackRepository } from './data/repositories/folder-track-reposito
import { RemovedTrackRepository } from './data/repositories/removed-track-repository';
import { TrackRepository } from './data/repositories/track-repository';
import { DateTime } from './common/date-time';
import { FileValidator } from './common/file-validator';
import { GuidFactory } from './common/guid.factory';
import { Hacks } from './common/hacks';
import { ImageProcessor } from './common/image-processor';
Expand All @@ -65,7 +63,6 @@ import { NativeElementProxy } from './common/native-element-proxy';
import { ArtistOrdering } from './common/ordering/artist-ordering';
import { GenreOrdering } from './common/ordering/genre-ordering';
import { TrackOrdering } from './common/ordering/track-ordering';
import { PathValidator } from './common/path-validator';
import { Scheduler } from './common/scheduling/scheduler';
import { SemanticZoomHeaderAdder } from './common/semantic-zoom-header-adder';
import { SettingsBase } from './common/settings/settings.base';
Expand Down Expand Up @@ -306,6 +303,9 @@ import { DesktopBase } from './common/io/desktop.base';
import { FileAccessBase } from './common/io/file-access.base';
import { FileMetadataFactoryBase } from './common/metadata/file-metadata.factory.base';
import { SchedulerBase } from './common/scheduling/scheduler.base';
import { ContextMenuOpener } from './ui/components/context-menu-opener';
import { PathValidator } from './common/validation/path-validator';
import { FileValidator } from './common/validation/file-validator';

export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
Expand Down
4 changes: 2 additions & 2 deletions src/app/common/api/git-hub/git-hub.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Strings } from '../../strings';
import { StringUtils } from '../../utils/string-utils';

@Injectable()
export class GitHubApi {
Expand All @@ -26,7 +26,7 @@ export class GitHubApi {
}

if (latestRelease != undefined && latestRelease.tag_name != undefined) {
return Strings.replaceFirst(latestRelease.tag_name, 'v', '');
return StringUtils.replaceFirst(latestRelease.tag_name, 'v', '');
}

return '';
Expand Down
12 changes: 6 additions & 6 deletions src/app/common/api/lastfm/lastfm-album.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Strings } from '../../strings';
import { StringUtils } from '../../utils/string-utils';

export class LastfmAlbum {
public name: string;
Expand All @@ -11,23 +11,23 @@ export class LastfmAlbum {
public imageMega: string;

public largestImage(): string {
if (!Strings.isNullOrWhiteSpace(this.imageMega)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageMega)) {
return this.imageMega;
}

if (!Strings.isNullOrWhiteSpace(this.imageExtraLarge)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageExtraLarge)) {
return this.imageExtraLarge;
}

if (!Strings.isNullOrWhiteSpace(this.imageLarge)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageLarge)) {
return this.imageLarge;
}

if (!Strings.isNullOrWhiteSpace(this.imageMedium)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageMedium)) {
return this.imageMedium;
}

if (!Strings.isNullOrWhiteSpace(this.imageSmall)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageSmall)) {
return this.imageSmall;
}

Expand Down
12 changes: 6 additions & 6 deletions src/app/common/api/lastfm/lastfm-artist.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Strings } from '../../strings';
import { LastfmBiography } from './lastfm-biography';
import { StringUtils } from '../../utils/string-utils';

export class LastfmArtist {
public name: string;
Expand All @@ -14,23 +14,23 @@ export class LastfmArtist {
public biography: LastfmBiography | undefined;

public largestImage(): string {
if (!Strings.isNullOrWhiteSpace(this.imageMega)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageMega)) {
return this.imageMega;
}

if (!Strings.isNullOrWhiteSpace(this.imageExtraLarge)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageExtraLarge)) {
return this.imageExtraLarge;
}

if (!Strings.isNullOrWhiteSpace(this.imageLarge)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageLarge)) {
return this.imageLarge;
}

if (!Strings.isNullOrWhiteSpace(this.imageMedium)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageMedium)) {
return this.imageMedium;
}

if (!Strings.isNullOrWhiteSpace(this.imageSmall)) {
if (!StringUtils.isNullOrWhiteSpace(this.imageSmall)) {
return this.imageSmall;
}

Expand Down
12 changes: 6 additions & 6 deletions src/app/common/api/lastfm/lastfm.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { Md5 } from 'md5-typescript';
import fetch from 'node-fetch';
import { SensitiveInformation } from '../../application/sensitive-information';
import { DateTime } from '../../date-time';
import { Strings } from '../../strings';
import { LastfmAlbum } from './lastfm-album';
import { LastfmArtist } from './lastfm-artist';
import { LastfmBiography } from './lastfm-biography';
import {StringUtils} from "../../utils/string-utils";

@Injectable()
export class LastfmApi {
Expand Down Expand Up @@ -47,7 +47,7 @@ export class LastfmApi {
['api_key', SensitiveInformation.lastfmApiKey],
]);

if (!Strings.isNullOrWhiteSpace(languageCode)) {
if (!StringUtils.isNullOrWhiteSpace(languageCode)) {
parameters.set('lang', languageCode);
}

Expand Down Expand Up @@ -102,7 +102,7 @@ export class LastfmApi {
['api_key', SensitiveInformation.lastfmApiKey],
]);

if (!Strings.isNullOrWhiteSpace(languageCode)) {
if (!StringUtils.isNullOrWhiteSpace(languageCode)) {
parameters.set('lang', languageCode);
}

Expand All @@ -129,7 +129,7 @@ export class LastfmApi {
artist: string,
trackTitle: string,
albumTitle: string,
playbackStartTime: Date
playbackStartTime: Date,
): Promise<boolean> {
let isScrobbleSuccessful: boolean = false;

Expand All @@ -143,7 +143,7 @@ export class LastfmApi {
['sk', sessionKey],
]);

if (!Strings.isNullOrWhiteSpace(albumTitle)) {
if (!StringUtils.isNullOrWhiteSpace(albumTitle)) {
parameters.set('album', albumTitle);
}

Expand Down Expand Up @@ -171,7 +171,7 @@ export class LastfmApi {
['sk', sessionKey],
]);

if (!Strings.isNullOrWhiteSpace(albumTitle)) {
if (!StringUtils.isNullOrWhiteSpace(albumTitle)) {
parameters.set('album', albumTitle);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IWebSearchLyricsSource } from './i-web-search-lyrics-source';
import htmlParser from 'node-html-parser';
import { HTMLElement } from 'node-html-parser';
import { Strings } from '../../../../strings';
import { StringUtils } from '../../../../utils/string-utils';

export class AZLyricsSource implements IWebSearchLyricsSource {
public get name(): string {
Expand All @@ -20,10 +20,10 @@ export class AZLyricsSource implements IWebSearchLyricsSource {

const content: string | undefined = possibleContent?.textContent.trim();

if (Strings.isNullOrWhiteSpace(content)) {
if (StringUtils.isNullOrWhiteSpace(content)) {
return '';
}

return Strings.replaceAll(content!, '\n\n', '\n');
return StringUtils.replaceAll(content!, '\n\n', '\n');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { WebSearchResult } from './web-search-result';
import { WebSearchApi } from './web-search.api';
import { IWebSearchLyricsSource } from './sources/i-web-search-lyrics-source';
import { AZLyricsSource } from './sources/a-z-lyrics-source';
import { Strings } from '../../../strings';
import { HttpClient } from '@angular/common/http';
import { GeniusSource } from './sources/genius-source';
import { MusixmatchSource } from './sources/musixmatch-source';
import { LyricsSource } from './sources/lyrics-source';
import { Logger } from '../../../logger';
import { StringUtils } from '../../../utils/string-utils';

@Injectable()
export class WebSearchLyricsApi implements ILyricsApi {
Expand Down Expand Up @@ -43,13 +43,13 @@ export class WebSearchLyricsApi implements ILyricsApi {
webSearchResults.filter((x: WebSearchResult) => [...this.sources.keys()].includes(x.name)) || [];

for (const possibleSite of possibleSites) {
if (!Strings.isNullOrWhiteSpace(possibleSite.name)) {
if (!StringUtils.isNullOrWhiteSpace(possibleSite.name)) {
try {
const source: IWebSearchLyricsSource = this.sources.get(possibleSite.name)!;
const htmlString: string = await this.httpClient.get(possibleSite.fullUrl, { responseType: 'text' }).toPromise();
const lyricsText: string = source.parse(htmlString);

if (Strings.isNullOrWhiteSpace(lyricsText)) {
if (StringUtils.isNullOrWhiteSpace(lyricsText)) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/common/api/lyrics/web-search-lyrics/web-search.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Injectable } from '@angular/core';

import { HttpClient } from '@angular/common/http';
import { WebSearchResult } from './web-search-result';
import { Strings } from '../../../strings';
import { StringUtils } from '../../../utils/string-utils';

@Injectable()
export class WebSearchApi {
Expand All @@ -20,14 +20,14 @@ export class WebSearchApi {
public async webSearchAsync(query: string): Promise<WebSearchResult[]> {
const vqd: string = await this.getVqdAsync(query);

if (Strings.isNullOrWhiteSpace(vqd)) {
if (StringUtils.isNullOrWhiteSpace(vqd)) {
throw new Error(`Failed to get the VQD for query "${query}".`);
}

const requestUrl: string = `https://links.duckduckgo.com/d.js?${this.getSearchRequestParams(query, vqd).toString()}`;
const responseString: string = await this.performGetRequestAsync(requestUrl);

if (Strings.isNullOrWhiteSpace(responseString)) {
if (StringUtils.isNullOrWhiteSpace(responseString)) {
return [];
}

Expand All @@ -39,7 +39,7 @@ export class WebSearchApi {

const rawSearchResults: string = matches[1].replace(/\\t/g, ' ');

if (Strings.isNullOrWhiteSpace(rawSearchResults)) {
if (StringUtils.isNullOrWhiteSpace(rawSearchResults)) {
return [];
}

Expand Down
3 changes: 0 additions & 3 deletions src/app/common/collections.spec.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/app/common/file-validator.spec.ts

This file was deleted.

File renamed without changes.
38 changes: 0 additions & 38 deletions src/app/common/logger.js

This file was deleted.

1 change: 0 additions & 1 deletion src/app/common/logger.js.map

This file was deleted.

4 changes: 0 additions & 4 deletions src/app/common/native-element-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export class NativeElementProxy {
return 0;
}

// if (!(element.nativeElement instanceof HTMLElement)) {
// return 0;
// }

const htmlElement: HTMLElement = element.nativeElement;

if (htmlElement.offsetWidth == undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/common/semantic-zoomable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Constants } from './application/constants';
import { Strings } from './strings';
import { StringUtils } from './utils/string-utils';

export abstract class SemanticZoomable {
public abstract name: string;
Expand All @@ -8,7 +8,7 @@ export abstract class SemanticZoomable {
public isZoomHeader: boolean = false;

public get sortableName(): string {
return Strings.getSortableString(this.name, true);
return StringUtils.getSortableString(this.name, true);
}

public get zoomHeader(): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class Collections {
export class CollectionUtils {
public static groupBy<S, T>(list: T[], keyGetter: (T) => S): Map<S, T[]> {
const map: Map<S, T[]> = new Map();

Expand Down
Loading

0 comments on commit 1031300

Please sign in to comment.