[api-minor] Improve the FileSpec implementation

- Check that the `filename` is actually a string, before parsing it further.
 - Use proper "shadowing" in the `filename` getter.
 - Add a bit more validation of the data in `pickPlatformItem`.
 - Last, but not least, return both the original `filename` and the (path stripped) variant needed in the display-layer and viewer.
This commit is contained in:
Jonas Jenwald 2024-05-01 12:28:33 +02:00
parent 16dbf5dcfd
commit 2b69fb76ac
6 changed files with 47 additions and 46 deletions

View file

@ -37,7 +37,6 @@ import {
} from "../shared/util.js";
import {
DOMSVGFactory,
getFilenameFromUrl,
PDFDateString,
setLayerDimensions,
} from "./display_utils.js";
@ -2859,15 +2858,13 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
constructor(parameters) {
super(parameters, { isRenderable: true });
const { filename, content, description } = this.data.file;
this.filename = getFilenameFromUrl(filename, /* onlyStripPath = */ true);
this.content = content;
const { file } = this.data;
this.filename = file.filename;
this.content = file.content;
this.linkService.eventBus?.dispatch("fileattachmentannotation", {
source: this,
filename,
content,
description,
...file,
});
}