Skip to content

Commit

Permalink
Server: Remove Dead code about settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthi-chaud committed Dec 22, 2024
1 parent 68229e5 commit de2cfc1
Show file tree
Hide file tree
Showing 28 changed files with 12 additions and 519 deletions.
2 changes: 0 additions & 2 deletions server/src/album/album.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
expectedAlbumResponse,
expectedArtistResponse,
} from "test/expected-responses";
import SettingsService from "src/settings/settings.service";
import { Genre, IllustrationType } from "@prisma/client";

jest.setTimeout(60000);
Expand Down Expand Up @@ -53,7 +52,6 @@ describe("Album Controller", () => {
app = await SetupApp(module);
dummyRepository = module.get(PrismaService);
await dummyRepository.onModuleInit();
module.get(SettingsService).loadFromFile();
});

afterAll(async () => {
Expand Down
2 changes: 0 additions & 2 deletions server/src/artist/artist.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { LyricsModule } from "src/lyrics/lyrics.module";
import FileModule from "src/file/file.module";
import { expectedArtistResponse } from "test/expected-responses";
import SettingsModule from "src/settings/settings.module";
import SettingsService from "src/settings/settings.service";
import { IllustrationType } from "@prisma/client";

describe("Artist Controller", () => {
Expand Down Expand Up @@ -61,7 +60,6 @@ describe("Artist Controller", () => {
app = await SetupApp(module);
dummyRepository = module.get(PrismaService);
await dummyRepository.onModuleInit();
module.get(SettingsService).loadFromFile();
});

afterAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions server/src/illustration/illustration.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ describe("Illustration Controller", () => {
});

const getDummyIllustrationStream = () =>
fs.createReadStream("test/assets/settings.json");
const dummyIllustrationBytes = fs.readFileSync("test/assets/settings.json");
fs.createReadStream("test/sequencer.ts");
const dummyIllustrationBytes = fs.readFileSync("test/sequencer.ts");

const illustrationUrlExample =
"https://sample-videos.com/img/Sample-jpg-image-50kb.jpg";
Expand Down
2 changes: 0 additions & 2 deletions server/src/playlist/playlist.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import TestPrismaService from "test/test-prisma.service";
import PlaylistModule from "./playlist.module";
import PlaylistService from "./playlist.service";
import SettingsModule from "src/settings/settings.module";
import SettingsService from "src/settings/settings.service";
import PrismaService from "src/prisma/prisma.service";
import Slug from "src/slug/slug";
import {
Expand All @@ -28,7 +27,6 @@ describe("Playlist Service", () => {
.compile();
dummyRepository = module.get(PrismaService);
playlistService = module.get(PlaylistService);
module.get(SettingsService).loadFromFile();
await dummyRepository.onModuleInit();
});

Expand Down
2 changes: 0 additions & 2 deletions server/src/search/search-history.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { INestApplication } from "@nestjs/common";
import SongModule from "src/song/song.module";
import TestPrismaService from "test/test-prisma.service";
import SetupApp from "test/setup-app";
import SettingsService from "src/settings/settings.service";
import * as Plugins from "../app.plugins";
import ArtistModule from "src/artist/artist.module";
import AlbumModule from "src/album/album.module";
Expand Down Expand Up @@ -45,7 +44,6 @@ describe("Search History Controller", () => {
app = await SetupApp(module);
dummyRepository = module.get(PrismaService);
const userService = module.get(UserService);
module.get(SettingsService).loadFromFile();
await dummyRepository.onModuleInit();
await userService.create({
name: "admin",
Expand Down
198 changes: 3 additions & 195 deletions server/src/settings/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,167 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { ApiHideProperty, ApiProperty } from "@nestjs/swagger";
import { Exclude, Type } from "class-transformer";
import {
ArrayNotEmpty,
IsBoolean,
IsDefined,
IsIn,
IsNotEmpty,
IsOptional,
IsString,
ValidateNested,
} from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
import { Exclude } from "class-transformer";
import { IsBoolean, IsString } from "class-validator";

export const metadataSourceValue = ["path", "embedded"] as const;
export const metadataOrderValue = ["only", "preferred"] as const;

class BaseProviderSettings {
@ApiProperty()
@IsOptional()
@IsBoolean()
@ApiProperty({ type: Boolean })
enabled = true;
}

//TODO Delete Provider Settings after Matcher Microservice

class AllMusicSettings extends BaseProviderSettings {}

class DiscogsSettings extends BaseProviderSettings {
@ApiHideProperty()
@IsDefined()
@IsString()
@Exclude({ toPlainOnly: true })
apiKey: string;
}

class GeniusSettings extends BaseProviderSettings {
@ApiHideProperty()
@IsDefined()
@IsString()
@Exclude({ toPlainOnly: true })
apiKey: string;
}
class MetacriticSettings extends BaseProviderSettings {}

class MusicBrainzSettings extends BaseProviderSettings {}

class WikipediaSettings extends BaseProviderSettings {}

/**
* Settings for the Providers
*/
export class ProvidersSettings {
/**
* Settings for the Genius provider
*/
@ApiProperty({
type: GeniusSettings,
required: false,
})
@Type(() => GeniusSettings)
@ValidateNested()
@IsOptional()
genius: GeniusSettings;

/**
* Settings for the Musicbrainz provider
*/
@ApiProperty({
type: MusicBrainzSettings,
required: false,
})
@Type(() => MusicBrainzSettings)
@ValidateNested()
@IsOptional()
musicbrainz: MusicBrainzSettings;

/**
* Settings for the Discogs provider
*/
@ApiProperty({
type: DiscogsSettings,
required: false,
})
@Type(() => DiscogsSettings)
@ValidateNested()
@IsOptional()
discogs: DiscogsSettings;

/**
* Settings for the Wikipedia provider
*/
@ApiProperty({
type: WikipediaSettings,
required: false,
})
@Type(() => WikipediaSettings)
@ValidateNested()
@IsOptional()
wikipedia: WikipediaSettings;

/**
* Settings for the Metacritic provider
*/
@ApiProperty({
type: MetacriticSettings,
required: false,
})
@Type(() => MetacriticSettings)
@ValidateNested()
@IsOptional()
metacritic: MetacriticSettings;

/**
* Settings for the AllMusic provider
*/
@ApiProperty({
type: AllMusicSettings,
required: false,
})
@Type(() => AllMusicSettings)
@ValidateNested()
@IsOptional()
allMusic: AllMusicSettings;
}

class CompilationSettings {
@ApiProperty()
@IsNotEmpty({ each: true })
@IsString({ each: true })
@IsOptional()
artists?: string[];

@ApiProperty()
@IsDefined()
@IsBoolean()
useID3CompTag: boolean;
}

class MetadataSettings {
/**
* Use the path or the embedded metadata as main metadata source
*/
@ApiProperty({ enum: metadataSourceValue })
@IsIn(metadataSourceValue)
source: typeof metadataSourceValue[number];

/**
* Exclude the other source, or use is as a fallback
*/
@ApiProperty({ enum: metadataOrderValue })
@IsIn(metadataOrderValue)
order: typeof metadataOrderValue[number];

/**
* Enable the use of genres from (enabled) external providers
*/
@ApiProperty()
@IsBoolean()
useExternalProviderGenres: boolean;
}
/**
* Global settings of the Meelo server
*/
Expand All @@ -202,42 +48,4 @@ export default class Settings {
@IsString()
@Exclude({ toPlainOnly: true })
dataFolder: string;

/**
* Array of RegExp string, used to match track files
*/
@ApiProperty()
@IsString({ each: true })
@ArrayNotEmpty()
trackRegex: string[];

/**
* Defines the metadata parsing policy
*/
@ApiProperty({
type: MetadataSettings,
})
@Type(() => MetadataSettings)
@ValidateNested()
@IsDefined()
metadata: MetadataSettings;

/**
* Settings for the providers
*/
@ApiProperty({
type: ProvidersSettings,
})
@Type(() => ProvidersSettings)
@ValidateNested()
@IsDefined()
providers: ProvidersSettings;

@ApiProperty({
type: CompilationSettings,
})
@Type(() => CompilationSettings)
@ValidateNested()
@IsDefined()
compilations: CompilationSettings;
}
15 changes: 0 additions & 15 deletions server/src/settings/settings.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe("Settings Controller", () => {
jest.spyOn(fileService, "getFileContent").mockImplementationOnce(() =>
fs.readFileSync("test/assets/settings.json").toString(),
);
controller.reload();
});

afterAll(async () => {
Expand All @@ -44,21 +43,7 @@ describe("Settings Controller", () => {
.get("/settings")
.expect(200)
.expect({
...JSON.parse(
fs.readFileSync("test/assets/settings.json").toString(),
),
allowAnonymous: false,
providers: {
genius: { enabled: true },
musicbrainz: { enabled: true },
},
});
});

it("/GET /settings/reload", () => {
jest.spyOn(fileService, "getFileContent").mockImplementation(() =>
fs.readFileSync("test/assets/settings2.json").toString(),
);
return request(app.getHttpServer()).get("/settings/reload").expect(302);
});
});
11 changes: 1 addition & 10 deletions server/src/settings/settings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Controller, Get, HttpStatus, Redirect } from "@nestjs/common";
import { Controller, Get } from "@nestjs/common";
import type Settings from "./models/settings";
import SettingsService from "./settings.service";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
Expand All @@ -35,13 +35,4 @@ export default class SettingsController {
getSettings(): Settings {
return this.settingsService.settingsValues;
}

@Get("reload")
@ApiOperation({
summary: "Reload settings",
})
@Redirect("/settings", HttpStatus.FOUND)
reload() {
this.settingsService.loadFromFile();
}
}
Loading

0 comments on commit de2cfc1

Please sign in to comment.