Skip to content

Commit a1ca68d

Browse files
loivseniOvergaard
authored andcommitted
asterisks, forMimeType required
1 parent eef9c33 commit a1ca68d

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/packages/core/extension-registry/models/file-upload-preview.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import type { ManifestElement } from '@umbraco-cms/backoffice/extension-api';
33

44
export interface ManifestFileUploadPreview extends ManifestElement<UmbFileUploadPreviewElement> {
55
type: 'fileUploadPreview';
6-
forMimeTypes?: Array<string>;
6+
forMimeTypes: Array<string>;
77
}

src/packages/media/media/components/input-upload-field/input-upload-field.element.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
6363
private _extensions?: string[];
6464

6565
@state()
66-
private _previewAlias = '';
66+
private _previewAlias?: string;
6767

6868
@query('#dropzone')
6969
private _dropzone?: UUIFileDropzoneElement;
@@ -92,7 +92,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
9292

9393
#getPreviewElementAlias() {
9494
const previews = this.#previewers.getValue();
95-
const fallbackAlias = previews.find((preview) => !preview.forMimeTypes?.length)?.alias ?? '';
95+
const fallbackAlias = previews.find((preview) => preview.forMimeTypes.includes('*/*'))?.alias;
9696

9797
const mimeType = this.#getMimeTypeFromPath(this._src);
9898
if (!mimeType) return fallbackAlias;
@@ -101,7 +101,8 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
101101
return preview.forMimeTypes?.find((type) => {
102102
if (mimeType === type) preview.alias;
103103

104-
const snippet = type.replace('*', '');
104+
const snippet = type.replace(/\*/g, '');
105+
105106
if (mimeType.startsWith(snippet)) return preview.alias;
106107
if (mimeType.endsWith(snippet)) return preview.alias;
107108
return undefined;
@@ -174,7 +175,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
174175
`;
175176
}
176177

177-
#renderFile(src: string, previewAlias: string, file?: File) {
178+
#renderFile(src: string, previewAlias?: string, file?: File) {
178179
if (!previewAlias) return 'An error occurred. No previewer found for the file type.';
179180
return html`
180181
<div id="wrapper">

src/packages/media/media/components/input-upload-field/preview/manifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const previews: Array<ManifestFileUploadPreview> = [
1313
alias: 'Umb.FileUploadPreview.File',
1414
name: 'File File Upload Preview',
1515
element: () => import('./input-upload-field-file.element.js'),
16+
forMimeTypes: ['*/*'],
1617
},
1718
{
1819
type: 'fileUploadPreview',

0 commit comments

Comments
 (0)