fix: ignore displaying undefined template error in file name
This commit is contained in:
parent
22482f5bbd
commit
45b14dfd75
2 changed files with 7 additions and 6 deletions
|
|
@ -65,7 +65,8 @@ export class MediaTypeManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileName(mediaTypeModel: MediaTypeModel): string {
|
getFileName(mediaTypeModel: MediaTypeModel): string {
|
||||||
return replaceTags(this.mediaFileNameTemplateMap.get(mediaTypeModel.getMediaType()), mediaTypeModel);
|
// Ignore undefined tags since some search APIs do not return all properties in the model and produce clean file names even if errors occur
|
||||||
|
return replaceTags(this.mediaFileNameTemplateMap.get(mediaTypeModel.getMediaType()), mediaTypeModel, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTemplate(mediaTypeModel: MediaTypeModel, app: App): Promise<string> {
|
async getTemplate(mediaTypeModel: MediaTypeModel, app: App): Promise<string> {
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,11 @@ export function replaceIllegalFileNameCharactersInString(string: string): string
|
||||||
return string.replace(/[\\,#%&{}/*<>$"@.?]*/g, '').replace(/:+/g, ' -');
|
return string.replace(/[\\,#%&{}/*<>$"@.?]*/g, '').replace(/:+/g, ' -');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function replaceTags(template: string, mediaTypeModel: MediaTypeModel): string {
|
export function replaceTags(template: string, mediaTypeModel: MediaTypeModel, ignoreUndefined: boolean = false): string {
|
||||||
return template.replace(new RegExp('{{.*?}}', 'g'), (match: string) => replaceTag(match, mediaTypeModel));
|
return template.replace(new RegExp('{{.*?}}', 'g'), (match: string) => replaceTag(match, mediaTypeModel, ignoreUndefined));
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceTag(match: string, mediaTypeModel: MediaTypeModel): string {
|
function replaceTag(match: string, mediaTypeModel: MediaTypeModel, ignoreUndefined: boolean): string {
|
||||||
let tag = match;
|
let tag = match;
|
||||||
tag = tag.substring(2);
|
tag = tag.substring(2);
|
||||||
tag = tag.substring(0, tag.length - 2);
|
tag = tag.substring(0, tag.length - 2);
|
||||||
|
|
@ -39,7 +39,7 @@ function replaceTag(match: string, mediaTypeModel: MediaTypeModel): string {
|
||||||
const obj = traverseMetaData(path, mediaTypeModel);
|
const obj = traverseMetaData(path, mediaTypeModel);
|
||||||
|
|
||||||
if (obj === undefined) {
|
if (obj === undefined) {
|
||||||
return '{{ INVALID TEMPLATE TAG - object undefined }}';
|
return ignoreUndefined ? '' : '{{ INVALID TEMPLATE TAG - object undefined }}';
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
|
@ -51,7 +51,7 @@ function replaceTag(match: string, mediaTypeModel: MediaTypeModel): string {
|
||||||
const obj = traverseMetaData(path, mediaTypeModel);
|
const obj = traverseMetaData(path, mediaTypeModel);
|
||||||
|
|
||||||
if (obj === undefined) {
|
if (obj === undefined) {
|
||||||
return '{{ INVALID TEMPLATE TAG - object undefined }}';
|
return ignoreUndefined ? '' : '{{ INVALID TEMPLATE TAG - object undefined }}';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operator === 'LIST') {
|
if (operator === 'LIST') {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue