const existingFiles = container.querySelector<HTMLElement>(".attachment__list__existingFiles");
if (existingFiles !== null) {
existingFiles.querySelectorAll("woltlab-core-file").forEach((file) => {
- upload(fileList, file, editorId);
+ upload(fileList!, file, editorId);
});
existingFiles.remove();
return resizedFile;
}
+function validateFile(element: WoltlabCoreFileUploadElement, file: File): boolean {
+ const fileExtensions = (element.dataset.fileExtensions || "*").split(",");
+ for (const fileExtension of fileExtensions) {
+ if (fileExtension === "*") {
+ return true;
+ } else if (file.name.endsWith(fileExtension)) {
+ return true;
+ }
+ }
+
+ // TODO: show an error message
+
+ return false;
+}
+
export function setup(): void {
wheneverFirstSeen("woltlab-core-file-upload", (element: WoltlabCoreFileUploadElement) => {
element.addEventListener("upload", (event: CustomEvent<File>) => {
clearPreviousErrors(element);
+ if (!validateFile(element, file)) {
+ return;
+ }
+
void resizeImage(element, file).then((resizedFile) => {
void upload(element, resizedFile);
});
}, file.name, fileType, resizeConfiguration.quality);
return resizedFile;
}
+ function validateFile(element, file) {
+ const fileExtensions = (element.dataset.fileExtensions || "*").split(",");
+ for (const fileExtension of fileExtensions) {
+ if (fileExtension === "*") {
+ return true;
+ }
+ else if (file.name.endsWith(fileExtension)) {
+ return true;
+ }
+ }
+ // TODO: show an error message
+ return false;
+ }
function setup() {
(0, Selector_1.wheneverFirstSeen)("woltlab-core-file-upload", (element) => {
element.addEventListener("upload", (event) => {
const file = event.detail;
clearPreviousErrors(element);
+ if (!validateFile(element, file)) {
+ return;
+ }
void resizeImage(element, file).then((resizedFile) => {
void upload(element, resizedFile);
});