} & UploadCompleted);
export type UploadCompleted = {
+ endpointThumbnails: string;
fileID: string;
typeName: string;
data: Record<string, unknown>;
const event = new CustomEvent<UploadCompleted>("uploadCompleted", {
detail: {
data: response.data,
+ endpointThumbnails: response.endpointThumbnails,
fileID: response.fileID,
typeName: response.typeName,
},
});
element.dispatchEvent(event);
+
+ if (response.endpointThumbnails !== "") {
+ // TODO: Dispatch the request to generate thumbnails.
+ }
}
} catch (e) {
// TODO: Handle errors
$processor->adopt($file, $context);
+ $endpointThumbnails = '';
+ if ($file->isImage()) {
+ $thumbnailFormats = $processor->getThumbnailFormats();
+ if ($thumbnailFormats !== []) {
+ // TODO: Endpoint to generate thumbnails.
+ $endpointThumbnails = '';
+ }
+ }
+
// TODO: This is just debug code.
return new JsonResponse([
'completed' => true,
+ 'endpointThumbnails' => $endpointThumbnails,
'fileID' => $file->fileID,
'typeName' => $file->typeName,
'data' => $processor->getUploadResponse($file),
use wcf\system\file\processor\FileProcessor;
use wcf\system\file\processor\IFileProcessor;
use wcf\system\request\LinkHandler;
+use wcf\util\FileUtil;
/**
* @author Alexander Ebert
{
return FileProcessor::getInstance()->forTypeName($this->typeName);
}
+
+ public function isImage(): bool
+ {
+ $mimeType = FileUtil::getMimeType($this->getPath() . $this->getSourceFilename());
+
+ return match ($mimeType) {
+ 'image/gif' => true,
+ 'image/jpg', 'image/jpeg' => true,
+ 'image/png' => true,
+ 'image/webp' => true,
+ default => false,
+ };
+ }
}
*/
final class AttachmentFileProcessor implements IFileProcessor
{
+ #[\Override]
public function getTypeName(): string
{
return 'com.woltlab.wcf.attachment';
}
+ #[\Override]
public function getAllowedFileExtensions(array $context): array
{
// TODO: Properly validate the shape of `$context`.
return $attachmentHandler->getAllowedExtensions();
}
+ #[\Override]
public function adopt(File $file, array $context): void
{
// TODO: Properly validate the shape of `$context`.
]);
}
+ #[\Override]
public function acceptUpload(string $filename, int $fileSize, array $context): FileProcessorPreflightResult
{
// TODO: Properly validate the shape of `$context`.
return FileProcessorPreflightResult::Passed;
}
+ #[\Override]
public function canDownload(File $file): bool
{
$attachment = Attachment::findByFileID($file->fileID);
return $attachment->canDownload();
}
+ #[\Override]
public function getUploadResponse(File $file): array
{
$attachment = Attachment::findByFileID($file->fileID);
];
}
+ #[\Override]
public function toHtmlElement(string $objectType, int $objectID, string $tmpHash, int $parentObjectID): string
{
return FileProcessor::getInstance()->getHtmlElement(
],
);
}
+
+ #[\Override]
+ public function getThumbnailFormats(): array
+ {
+ return [
+ new ThumbnailFormat(
+ 'tiny',
+ 144,
+ 144,
+ false,
+ ),
+ new ThumbnailFormat(
+ 'default',
+ \ATTACHMENT_THUMBNAIL_HEIGHT,
+ \ATTACHMENT_THUMBNAIL_WIDTH,
+ !!\ATTACHMENT_RETAIN_DIMENSIONS,
+ ),
+ ];
+ }
}
public function getTypeName(): string;
public function getUploadResponse(File $file): array;
+
+ /**
+ * @return ThumbnailFormat[]
+ */
+ public function getThumbnailFormats(): array;
}
--- /dev/null
+<?php
+
+namespace wcf\system\file\processor;
+
+final class ThumbnailFormat
+{
+ public function __construct(
+ public readonly string $identifier,
+ public readonly int $height,
+ public readonly int $width,
+ public readonly bool $retainDimensions,
+ ) {
+ }
+}