mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 10:51:02 +01:00
feat(logging): add logging for regular expression updates and creation actions
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
import type { PCDCache } from '../../cache.ts';
|
||||
import { writeOperation, type OperationLayer } from '../../writer.ts';
|
||||
import type { RegularExpressionTableRow } from './types.ts';
|
||||
import { logger } from '$logger/logger.ts';
|
||||
|
||||
export interface UpdateRegularExpressionInput {
|
||||
name: string;
|
||||
@@ -97,6 +98,33 @@ export async function update(options: UpdateRegularExpressionOptions) {
|
||||
queries.push(linkTag);
|
||||
}
|
||||
|
||||
// Log what's being changed (before the write)
|
||||
const changes: Record<string, { from: unknown; to: unknown }> = {};
|
||||
|
||||
if (current.name !== input.name) {
|
||||
changes.name = { from: current.name, to: input.name };
|
||||
}
|
||||
if (current.pattern !== input.pattern) {
|
||||
changes.pattern = { from: current.pattern, to: input.pattern };
|
||||
}
|
||||
if (current.description !== input.description) {
|
||||
changes.description = { from: current.description, to: input.description };
|
||||
}
|
||||
if (current.regex101_id !== input.regex101Id) {
|
||||
changes.regex101Id = { from: current.regex101_id, to: input.regex101Id };
|
||||
}
|
||||
if (tagsToAdd.length > 0 || tagsToRemove.length > 0) {
|
||||
changes.tags = { from: currentTagNames, to: input.tags };
|
||||
}
|
||||
|
||||
await logger.info(`Save regular expression "${input.name}"`, {
|
||||
source: 'RegularExpression',
|
||||
meta: {
|
||||
id: current.id,
|
||||
changes
|
||||
}
|
||||
});
|
||||
|
||||
// Write the operation with metadata
|
||||
// Include previousName if this is a rename
|
||||
const isRename = input.name !== current.name;
|
||||
|
||||
@@ -4,6 +4,7 @@ import { pcdManager } from '$pcd/pcd.ts';
|
||||
import { canWriteToBase } from '$pcd/writer.ts';
|
||||
import * as regularExpressionQueries from '$pcd/queries/regularExpressions/index.ts';
|
||||
import type { OperationLayer } from '$pcd/writer.ts';
|
||||
import { logger } from '$logger/logger.ts';
|
||||
|
||||
export const load: ServerLoad = ({ params, url }) => {
|
||||
const { databaseId } = params;
|
||||
@@ -80,6 +81,15 @@ export const actions: Actions = {
|
||||
const layerFromForm = formData.get('layer');
|
||||
const layer = (layerFromForm as OperationLayer) || 'user';
|
||||
|
||||
await logger.debug('Create action received', {
|
||||
source: 'RegularExpressionCreate',
|
||||
meta: {
|
||||
regexName: name,
|
||||
layerFromForm,
|
||||
layerUsed: layer
|
||||
}
|
||||
});
|
||||
|
||||
// Validate
|
||||
if (!name?.trim()) {
|
||||
return fail(400, { error: 'Name is required' });
|
||||
|
||||
Reference in New Issue
Block a user