mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-03-13 19:13:43 +00:00
Filter out non-image OBJE entries when displaying personal photos
This commit is contained in:
@@ -113,20 +113,32 @@ function sortChildren(gedcom: JsonGedcomData): JsonGedcomData {
|
||||
return Object.assign({}, gedcom, {fams: newFams});
|
||||
}
|
||||
|
||||
const IMAGE_EXTENSIONS = ['.jpg', '.png', '.gif'];
|
||||
|
||||
/** Returns true if the given file name has a known image extension. */
|
||||
function isImageFile(fileName: string): boolean {
|
||||
const lowerName = fileName.toLowerCase();
|
||||
return IMAGE_EXTENSIONS.some((ext) => lowerName.endsWith(ext));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes images that are not HTTP links.
|
||||
* Does not modify the input object.
|
||||
* Removes imageUrl fields that are not HTTP links or do not have known image
|
||||
* extensions. Does not modify the input object.
|
||||
*/
|
||||
function filterImage(indi: JsonIndi, images: Map<string, string>): JsonIndi {
|
||||
if (indi.imageUrl) {
|
||||
const fileName = indi.imageUrl.match(/[^/\\]*$/)![0];
|
||||
// If the image file has been loaded into memory, use it.
|
||||
if (images.has(fileName)) {
|
||||
const newIndi = Object.assign({}, indi);
|
||||
newIndi.imageUrl = images.get(fileName);
|
||||
return newIndi;
|
||||
}
|
||||
}
|
||||
if (!indi.imageUrl || indi.imageUrl.startsWith('http')) {
|
||||
if (
|
||||
!indi.imageUrl ||
|
||||
(indi.imageUrl.startsWith('http') && isImageFile(indi.imageUrl))
|
||||
) {
|
||||
return indi;
|
||||
}
|
||||
const newIndi = Object.assign({}, indi);
|
||||
|
||||
Reference in New Issue
Block a user