Improved efficiency of Dish title generation

This commit is contained in:
n1474335 2019-07-04 15:43:50 +01:00
parent e49974beaa
commit 2007cfd3a0
1 changed files with 9 additions and 11 deletions

View File

@ -166,29 +166,27 @@ class Dish {
*/ */
async getTitle(maxLength) { async getTitle(maxLength) {
let title = ""; let title = "";
const cloned = this.clone(); let cloned;
switch (this.type) { switch (this.type) {
case Dish.FILE: case Dish.FILE:
title = cloned.value.name; title = this.value.name;
break; break;
case Dish.LIST_FILE: case Dish.LIST_FILE:
title = `${cloned.value.length} file(s)`; title = `${this.value.length} file(s)`;
break; break;
case Dish.ARRAY_BUFFER: case Dish.ARRAY_BUFFER:
case Dish.BYTE_ARRAY: case Dish.BYTE_ARRAY:
title = await cloned.detectDishType(); title = await this.detectDishType();
if (title === null) { if (title !== null) break;
cloned.value = cloned.value.slice(0, 2048); // fall through if no mime type was detected
title = await cloned.get(Dish.STRING);
}
break;
default: default:
cloned = this.clone();
cloned.value = cloned.value.slice(0, 256);
title = await cloned.get(Dish.STRING); title = await cloned.get(Dish.STRING);
} }
title = title.slice(0, maxLength); return title.slice(0, maxLength);
return title;
} }