Skip to content
Snippets Groups Projects
Commit be8bf929 authored by Steinwender, Tamara's avatar Steinwender, Tamara
Browse files

Add a max-file-size to file-source

parent c1682fde
No related branches found
No related tags found
No related merge requests found
Pipeline #52175 passed
......@@ -65,6 +65,10 @@ files from a [Nextcloud](https://nextcloud.com/) instance or to a dbp-clipboard.
- example `<dbp-file-source allowed-mime-types='image/*'></dbp-file-source>` ... images (of all sub types) only
- example `<dbp-file-source allowed-mime-types='image/png,text/plain'></dbp-file-source>` ... PNGs or TXTs only
- example `<dbp-file-source allowed-mime-types='*/*'></dbp-file-source>` ... all file types (default)
- `max-file-size"` (optional): if set accepts only files with maximum of this size (in KB)
- example `<dbp-file-source max-file-size="32000"></dbp-file-source>` ... only files with a max size of
32 MB are allowed
- `enabled-targets` (optional, default: `local`): sets which sources are enabled
- you can use `local`, `nextcloud` and `clipboard`
- example `<dbp-file-source enabled-targets="local,nextcloud"></dbp-file-source>`
......
......@@ -11,6 +11,7 @@ import MicroModal from './micromodal.es';
import * as fileHandlingStyles from './styles';
import {Clipboard} from "@dbp-toolkit/file-handling/src/clipboard";
import DbpFileHandlingLitElement from "./dbp-file-handling-lit-element";
import {humanFileSize} from "@dbp-toolkit/common/i18next";
function mimeTypesToAccept(mimeTypes) {
// Some operating systems can't handle mime types and
......@@ -55,6 +56,7 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
this.isDialogOpen = false;
this.firstOpen = true;
this.nextcloudAuthInfo = '';
this.maxFileSize = '';
this.initialFileHandlingState = {target: '', path: ''};
}
......@@ -88,6 +90,7 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
decompressZip: { type: Boolean, attribute: 'decompress-zip' },
activeTarget: { type: String, attribute: 'active-target' },
isDialogOpen: { type: Boolean, attribute: 'dialog-open' },
maxFileSize: { type: Number, attribute: 'max-file-size'},
initialFileHandlingState: {type: Object, attribute: 'initial-file-handling-state'},
};
......@@ -214,6 +217,10 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
console.log('file \'' + file.name + '\' has size=0 and is denied!');
return;
}
if(!this.checkSize(file)) {
return;
}
// check if we want to decompress the zip and queue the contained files
if (this.decompressZip
&& (file.type === "application/zip" || file.type === "application/x-zip-compressed")) {
......@@ -228,7 +235,7 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
} else if (this.allowedMimeTypes && !this.checkFileType(file) ) {
return;
}
console.log("huiiii");
await this.sendFileEvent(file, fileCount);
});
......@@ -286,6 +293,23 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
return true;
}
checkSize(file) {
const i18n = this._i18n;
//TODO
console.log("file size", file.size);
if ( this.maxFileSize !== '' && (this.maxFileSize * 1000) <= file.size ) {
console.log(!"tooooo big file", humanFileSize(this.maxFileSize * 1000, true));
send({
"summary": i18n.t('file-source.too-big-file-title'),
"body": i18n.t('file-source.too-big-file-body', {size: humanFileSize(this.maxFileSize * 1000, true)}),
"type": "danger",
"timeout": 5,
});
return false;
}
return true;
}
hasEnabledSource(source) {
return this.enabledTargets.split(',').includes(source);
}
......
......@@ -19,7 +19,9 @@
"no-usable-files-hint": "Laden Sie eine ZIP Datei mit Dateien von folgendem Typ hoch: ",
"clipboard": "Zwischenablage",
"mime-type-title": "Nicht unterstützes Dateiformat",
"mime-type-body": "Das Dateiformat wird von dieser Applikation nicht unterstützt."
"mime-type-body": "Das Dateiformat wird von dieser Applikation nicht unterstützt.",
"too-big-file-title": "Datei ist zu groß!",
"too-big-file-body": "Die Datei darf maximal {{size}} haben."
},
"file-sink": {
"local-intro": "{{count}} Datei herunterladen",
......
......@@ -23,7 +23,9 @@
"clipboard-no-files": "There are currently no files in the clipboard.",
"clipboard": "Clipboard",
"mime-type-title": "Unsupported file format",
"mime-type-body": "The file format is not supported by this application."
"mime-type-body": "The file format is not supported by this application.",
"too-big-file-title": "The file is too big!",
"too-big-file-body": "The file can have a maximum of {{size}}."
},
"file-sink": {
"local-intro": "Download {{count}} file",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment