mirror of
https://github.com/FoxxMD/multi-scrobbler.git
synced 2026-09-02 21:03:09 +03:00
Id logging and schema cleanup
* Guard against undefined name when logging component disabled * Add id/name hint to config location * inherit name/id field from common schema
This commit is contained in:
@@ -166,15 +166,6 @@ export type CommonClientOptions = z.infer<typeof commonClientOptionsSchema>;
|
||||
|
||||
export const commonClientConfigSchema = z.object({
|
||||
...commonConfigSchema.shape,
|
||||
/**
|
||||
* Vanity name for this client
|
||||
*
|
||||
* @examples ["MyConfig"]
|
||||
* */
|
||||
name: z.string().meta({
|
||||
description: "Vanity name for this client.",
|
||||
examples: ["Foxx's Cool Client"]
|
||||
}),
|
||||
/**
|
||||
* Specific data required to configure this client
|
||||
* */
|
||||
|
||||
@@ -19,7 +19,15 @@ export const commonDataSchema = z.record(z.string(), z.any()); // keyOmit<{ [key
|
||||
export type CommonData = z.infer<typeof commonDataSchema>;
|
||||
|
||||
export const commonConfigSchema = z.object({
|
||||
name: z.string().optional(),
|
||||
/**
|
||||
* Vanity name for this Source/Client
|
||||
*
|
||||
* @examples ["My Cool Component"]
|
||||
* */
|
||||
name: z.string().optional().meta({
|
||||
description: "Vanity name for this Source/Client",
|
||||
examples: ["Foxx's Cool Client"]
|
||||
}),
|
||||
/** A UNIQUE identifier for this Source/Client
|
||||
*
|
||||
* It should be unique for the given Source/Client type. No other Source/Client of the same type should have this ID. This ID will be used to register this Source/Client in the database so that it can be identified even if you change the name of the component.
|
||||
@@ -150,13 +158,23 @@ export type MonitorOptions = z.infer<typeof monitorOptionsSchema>;
|
||||
export type UnparsedConfig<T extends (SourceType | ClientType)> = {config: object, type: T, source?: 'file' | 'aio' | 'env', pos: string};
|
||||
|
||||
export const generateConfigLocation = (configType: string, config: UnparsedConfig<any>): string => {
|
||||
const identifiers: string[] = [];
|
||||
if(config.config !== undefined) {
|
||||
if('id' in config.config) {
|
||||
identifiers.push(`ID ${config.config.id}`);
|
||||
}
|
||||
if('name' in config.config) {
|
||||
identifiers.push(`Name ${config.config.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
if(config.source === 'file') {
|
||||
return `${capitalize(configType)} #${config.pos} in ${config.type}.json`;
|
||||
return `${capitalize(configType)} #${config.pos}${identifiers.length > 0 ? ` (${identifiers.join(',')})` : ''} in ${config.type}.json`;
|
||||
}
|
||||
if(config.source === 'aio') {
|
||||
return `${capitalize(configType)} ${config.type} #${config.pos} in config.json`;
|
||||
return `${capitalize(configType)} ${config.type} #${config.pos}${identifiers.length > 0 ? ` (${identifiers.join(',')})` : ''} in config.json`;
|
||||
}
|
||||
return `${capitalize(configType)} ${config.type} from ENV`;
|
||||
return `${capitalize(configType)} ${config.type}${identifiers.length > 0 ? ` (${identifiers.join(',')})` : ''} from ENV`;
|
||||
}
|
||||
|
||||
export const transformPresetEnv = <T extends CommonClientOptions = CommonClientOptions>(prefix: string, existing: T = undefined): undefined | T => {
|
||||
|
||||
@@ -186,20 +186,13 @@ export type CommonSourceData = {};
|
||||
export const commonSourceConfigSchema = z.object({
|
||||
...commonConfigSchema.shape,
|
||||
/**
|
||||
* Vanity anme for this source.
|
||||
* */
|
||||
name: z.string().optional().meta({
|
||||
description: "Vanity Name for this source.",
|
||||
examples: ["Foxx's Cool Source"]
|
||||
}),
|
||||
/**
|
||||
* Restrict scrobbling tracks played from this source to Clients with names from this list. If list is empty is not present Source scrobbles to all configured Clients.
|
||||
* Restrict scrobbling tracks played from this source to Clients with IDs from this list. If list is empty is not present Source scrobbles to all configured Clients.
|
||||
*
|
||||
* @examples [["MyMalojaConfigName","MyLastFMConfigName"]]
|
||||
* */
|
||||
clients: z.array(z.string()).optional().meta({
|
||||
description: "Restrict scrobbling tracks played from this source to Clients with names from this list.",
|
||||
examples: [["MyMalojaConfigName","MyLastFMConfigName"]]
|
||||
description: "Restrict scrobbling tracks played from this Source to Clients with IDs from this list.",
|
||||
examples: [["MyMalojaConfigId","MyLastFMConfigId"]]
|
||||
}),
|
||||
data: commonSourceDataSchema.optional(),
|
||||
options: commonSourceOptionsSchema.optional(),
|
||||
|
||||
@@ -239,7 +239,7 @@ export default class ScrobbleClients {
|
||||
}
|
||||
|
||||
if (parsedConfig.enable === false) {
|
||||
this.logger.debug(`Not using Config ${parsedConfig.id} (${parsedConfig.name}) because it was marked as not enabled.`);
|
||||
this.logger.debug(`Not using Config ${parsedConfig.id}${parsedConfig.name !== undefined ? ` (${parsedConfig.name}) ` :''} because it was marked as not enabled.`);
|
||||
} else {
|
||||
strongConfigs.push(parsedConfig);
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ export default class ScrobbleSources {
|
||||
}
|
||||
|
||||
if (parsedConfig.enable === false) {
|
||||
this.logger.debug(`Not using Config ${parsedConfig.id} (${parsedConfig.name}) because it was marked as not enabled.`);
|
||||
this.logger.debug(`Not using Config ${parsedConfig.id}${parsedConfig.name !== undefined ? ` (${parsedConfig.name}) ` :''} because it was marked as not enabled.`);
|
||||
} else {
|
||||
strongConfigs.push(parsedConfig);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user