mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2025-12-23 18:29:19 -05:00
refactor: improve display name sanitization in tag creation
This commit is contained in:
@@ -47,7 +47,9 @@ const migrationArrTags = async (settings: any): Promise<AllSettings> => {
|
|||||||
.normalize('NFD')
|
.normalize('NFD')
|
||||||
.replace(/[\u0300-\u036f]/g, '')
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
.replace(/\s+/g, '-')
|
.replace(/\s+/g, '-')
|
||||||
.replace(/[^a-z0-9-]/gi, ''),
|
.replace(/[^a-z0-9-]/gi, '')
|
||||||
|
.replace(/-+/g, '-')
|
||||||
|
.replace(/^-|-$/g, ''),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -87,7 +89,9 @@ const migrationArrTags = async (settings: any): Promise<AllSettings> => {
|
|||||||
.normalize('NFD')
|
.normalize('NFD')
|
||||||
.replace(/[\u0300-\u036f]/g, '')
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
.replace(/\s+/g, '-')
|
.replace(/\s+/g, '-')
|
||||||
.replace(/[^a-z0-9-]/gi, ''),
|
.replace(/[^a-z0-9-]/gi, '')
|
||||||
|
.replace(/-+/g, '-')
|
||||||
|
.replace(/^-|-$/g, ''),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -29,6 +29,16 @@ import type {
|
|||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { EventSubscriber } from 'typeorm';
|
import { EventSubscriber } from 'typeorm';
|
||||||
|
|
||||||
|
const sanitizeDisplayName = (displayName: string): string => {
|
||||||
|
return displayName
|
||||||
|
.normalize('NFD')
|
||||||
|
.replace(/[\u0300-\u036f]/g, '')
|
||||||
|
.replace(/\s+/g, '-')
|
||||||
|
.replace(/[^a-z0-9-]/gi, '')
|
||||||
|
.replace(/-+/g, '-')
|
||||||
|
.replace(/^-|-$/g, '');
|
||||||
|
};
|
||||||
|
|
||||||
@EventSubscriber()
|
@EventSubscriber()
|
||||||
export class MediaRequestSubscriber
|
export class MediaRequestSubscriber
|
||||||
implements EntitySubscriberInterface<MediaRequest>
|
implements EntitySubscriberInterface<MediaRequest>
|
||||||
@@ -312,21 +322,13 @@ export class MediaRequestSubscriber
|
|||||||
newTag:
|
newTag:
|
||||||
entity.requestedBy.id +
|
entity.requestedBy.id +
|
||||||
'-' +
|
'-' +
|
||||||
entity.requestedBy.displayName
|
sanitizeDisplayName(entity.requestedBy.displayName),
|
||||||
.normalize('NFD')
|
|
||||||
.replace(/[\u0300-\u036f]/g, '')
|
|
||||||
.replace(/\s+/g, '-')
|
|
||||||
.replace(/[^a-z0-9-]/gi, ''),
|
|
||||||
});
|
});
|
||||||
userTag = await radarr.createTag({
|
userTag = await radarr.createTag({
|
||||||
label:
|
label:
|
||||||
entity.requestedBy.id +
|
entity.requestedBy.id +
|
||||||
'-' +
|
'-' +
|
||||||
entity.requestedBy.displayName
|
sanitizeDisplayName(entity.requestedBy.displayName),
|
||||||
.normalize('NFD')
|
|
||||||
.replace(/[\u0300-\u036f]/g, '')
|
|
||||||
.replace(/\s+/g, '-')
|
|
||||||
.replace(/[^a-z0-9-]/gi, ''),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (userTag.id) {
|
if (userTag.id) {
|
||||||
@@ -645,21 +647,13 @@ export class MediaRequestSubscriber
|
|||||||
newTag:
|
newTag:
|
||||||
entity.requestedBy.id +
|
entity.requestedBy.id +
|
||||||
'-' +
|
'-' +
|
||||||
entity.requestedBy.displayName
|
sanitizeDisplayName(entity.requestedBy.displayName),
|
||||||
.normalize('NFD')
|
|
||||||
.replace(/[\u0300-\u036f]/g, '')
|
|
||||||
.replace(/\s+/g, '-')
|
|
||||||
.replace(/[^a-z0-9-]/gi, ''),
|
|
||||||
});
|
});
|
||||||
userTag = await sonarr.createTag({
|
userTag = await sonarr.createTag({
|
||||||
label:
|
label:
|
||||||
entity.requestedBy.id +
|
entity.requestedBy.id +
|
||||||
'-' +
|
'-' +
|
||||||
entity.requestedBy.displayName
|
sanitizeDisplayName(entity.requestedBy.displayName),
|
||||||
.normalize('NFD')
|
|
||||||
.replace(/[\u0300-\u036f]/g, '')
|
|
||||||
.replace(/\s+/g, '-')
|
|
||||||
.replace(/[^a-z0-9-]/gi, ''),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (userTag.id) {
|
if (userTag.id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user