return;
}
- // TODO: Add a proper error message, this is for development purposes only.
- markElementAsErroneous(element, JSON.stringify(file.validationError));
+ let errorMessage: string;
+ switch (file.validationError.param) {
+ case "preflight":
+ errorMessage = getPhrase(`wcf.upload.error.${file.validationError.code}`);
+ break;
+
+ default:
+ errorMessage = "Unrecognized error type: " + JSON.stringify(file.validationError);
+ break;
+ }
+
+ markElementAsErroneous(element, errorMessage);
}
function markElementAsErroneous(element: HTMLElement, errorMessage: string): void {
import ImageResizer from "WoltLabSuite/Core/Image/Resizer";
import { AttachmentData } from "../Ckeditor/Attachment";
import { innerError } from "WoltLabSuite/Core/Dom/Util";
+import { getPhrase } from "WoltLabSuite/Core/Language";
export type CkeditorDropEvent = {
file: File;
}
}
- innerError(element, `TODO: the file extension of '${file.name}' is not allowed`);
+ innerError(element, getPhrase("wcf.upload.error.fileExtensionNotPermitted", { filename: file.name }));
return false;
}
if (file.validationError === undefined) {
return;
}
- // TODO: Add a proper error message, this is for development purposes only.
- markElementAsErroneous(element, JSON.stringify(file.validationError));
+ let errorMessage;
+ switch (file.validationError.param) {
+ case "preflight":
+ errorMessage = (0, Language_1.getPhrase)(`wcf.upload.error.${file.validationError.code}`);
+ break;
+ default:
+ errorMessage = "Unrecognized error type: " + JSON.stringify(file.validationError);
+ break;
+ }
+ markElementAsErroneous(element, errorMessage);
}
function markElementAsErroneous(element, errorMessage) {
element.classList.add("attachment__item--error");
-define(["require", "exports", "tslib", "WoltLabSuite/Core/Helper/Selector", "WoltLabSuite/Core/Api/Files/Upload", "WoltLabSuite/Core/Api/Files/Chunk/Chunk", "WoltLabSuite/Core/Api/Files/GenerateThumbnails", "WoltLabSuite/Core/Image/Resizer", "WoltLabSuite/Core/Dom/Util"], function (require, exports, tslib_1, Selector_1, Upload_1, Chunk_1, GenerateThumbnails_1, Resizer_1, Util_1) {
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Helper/Selector", "WoltLabSuite/Core/Api/Files/Upload", "WoltLabSuite/Core/Api/Files/Chunk/Chunk", "WoltLabSuite/Core/Api/Files/GenerateThumbnails", "WoltLabSuite/Core/Image/Resizer", "WoltLabSuite/Core/Dom/Util", "WoltLabSuite/Core/Language"], function (require, exports, tslib_1, Selector_1, Upload_1, Chunk_1, GenerateThumbnails_1, Resizer_1, Util_1, Language_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setup = void 0;
return true;
}
}
- (0, Util_1.innerError)(element, `TODO: the file extension of '${file.name}' is not allowed`);
+ (0, Util_1.innerError)(element, (0, Language_1.getPhrase)("wcf.upload.error.fileExtensionNotPermitted", { filename: file.name }));
return false;
}
function setup() {
use wcf\http\Helper;
use wcf\system\endpoint\IController;
use wcf\system\endpoint\PostRequest;
+use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\SystemException;
use wcf\system\exception\UserInputException;
use wcf\system\file\processor\FileProcessor;
+use wcf\system\file\processor\FileProcessorPreflightResult;
use wcf\util\JSON;
#[PostRequest('/core/files/upload')]
$validationResult = $fileProcessor->acceptUpload($parameters->filename, $parameters->fileSize, $decodedContext);
if (!$validationResult->ok()) {
- throw new UserInputException('filename', $validationResult->toString());
+ match ($validationResult) {
+ FileProcessorPreflightResult::InsufficientPermissions => throw new PermissionDeniedException(),
+ FileProcessorPreflightResult::InvalidContext => throw new UserInputException('context', 'invalid'),
+ default => throw new UserInputException('preflight', $validationResult->toString()),
+ };
}
$numberOfChunks = FileTemporary::getNumberOfChunks($parameters->fileSize);
$event->preload('wcf.style.changeStyle');
+ $event->preload('wcf.upload.error.fileExtensionNotPermitted');
+ $event->preload('wcf.upload.error.fileSizeTooLarge');
+
$event->preload('wcf.user.activityPoint');
$event->preload('wcf.user.language');
$event->preload('wcf.user.panel.settings');
self::Passed => 'passed',
};
}
-
- public function toErrorMessage(): string
- {
- if ($this->ok()) {
- throw new \RuntimeException("Cannot invoke `toErrorMessage()` on a successful result.");
- }
-
- $phraseSuffix = $this->toString();
-
- return WCF::getLanguage()->get("wcf.file.preflight.error.{$phraseSuffix}");
- }
}
<item name="wcf.upload.error.noImage"><![CDATA[Die hochgeladene Datei ist kein Bild.]]></item>
<item name="wcf.upload.error.reachedRemainingLimit"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} zu viele Dateien ausgewählt. {if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} nur noch {#$maxFiles} weitere Datei{if $maxFiles != 1}en{/if} hochladen.]]></item>
<item name="wcf.upload.error.uploadFailed"><![CDATA[Beim Hochladen der Datei ist ein unbekannter Fehler aufgetreten.]]></item>
+
+ <item name="wcf.upload.error.fileExtensionNotPermitted"><![CDATA[Der Dateityp von „{$filename}“ ist unzulässig.]]></item>
+ <item name="wcf.upload.error.fileSizeTooLarge"><![CDATA[Die Datei ist zu groß.]]></item>
</category>
</import>
<delete>
<item name="wcf.upload.error.noImage"><![CDATA[The uploaded file is no image.]]></item>
<item name="wcf.upload.error.reachedRemainingLimit"><![CDATA[You have selected too many files. You can only upload {#$maxFiles} more file{if $maxFiles != 1}s{/if}.]]></item>
<item name="wcf.upload.error.uploadFailed"><![CDATA[An unknown error occurred during the upload.]]></item>
+
+ <item name="wcf.upload.error.invalidFileExtension"><![CDATA[The file type of “{$filename}” is not permitted.]]></item>
+ <item name="wcf.upload.error.fileSizeTooLarge"><![CDATA[The file is too large.]]></item>
</category>
</import>
<delete>