Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(upload): use file extensions for valid file types instead of MIME types (DEV-1203) #808

Merged
merged 5 commits into from Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -128,7 +128,7 @@ export class DefaultResourceClasses {
},
{
iri: Constants.DocumentRepresentation,
label: 'Document (PDF, etc.)',
label: 'Document',
icons: [
'description',
'article',
Expand All @@ -143,7 +143,7 @@ export class DefaultResourceClasses {
},
{
iri: Constants.ArchiveRepresentation,
label: 'Archive (zip, x-tar, gzip)',
label: 'Archive',
icons: [
'archive',
'folder',
Expand Down
Expand Up @@ -82,7 +82,7 @@ export class ArchiveComponent implements OnInit, AfterViewInit {
document.body.removeChild(e);
}

openReplaceFileDialog(){
openReplaceFileDialog() {
const propId = this.parentResource.properties[Constants.HasArchiveFileValue][0].id;

const dialogConfig: MatDialogConfig = {
Expand All @@ -91,7 +91,7 @@ export class ArchiveComponent implements OnInit, AfterViewInit {
position: {
top: '112px'
},
data: { mode: 'replaceFile', title: 'Archive (zip, x-tar, gzip)', subtitle: 'Update the archive file of this resource' , representation: 'archive', id: propId },
data: { mode: 'replaceFile', title: 'Archive', subtitle: 'Update the archive file of this resource', representation: 'archive', id: propId },
disableClose: true
};
const dialogRef = this._dialog.open(
Expand Down
Expand Up @@ -9,13 +9,9 @@
<app-progress-indicator *ngIf="isLoading"></app-progress-indicator>
<p class="title">Upload file<br>
<span class="mat-body-1">The following file types are supported:<br>
<span *ngIf="representation !== 'audio' && representation !== 'text'">
<span *ngFor="let item of allowedFileTypes; let last = last">{{ item | split: '/':1 }}
<span *ngIf="!last">,&nbsp;</span>
</span>
<span *ngFor="let item of allowedFileTypes; let last = last">{{ item }}
<span *ngIf="!last">,&nbsp;</span>
</span>
<span *ngIf="representation === 'audio'">&nbsp;mp3</span>
<span *ngIf="representation === 'text'">&nbsp;csv, txt, xml</span>
</span>
</p>
<div class="bottom-line">
Expand Down Expand Up @@ -55,4 +51,4 @@
</div>
</ng-container>
</form>
</div>
</div>
Expand Up @@ -36,7 +36,7 @@ class TestHostComponent implements OnInit {
}

describe('UploadComponent', () => {
const mockFile = new File(['1'], 'testfile', { type: 'image/jpeg' });
const mockFile = new File(['1'], 'testfile.jpg', { type: 'image/jpeg' });

const fb = new FormBuilder();

Expand Down Expand Up @@ -122,16 +122,15 @@ describe('UploadComponent', () => {

describe('isFileTypeSupported', () => {
it('should return true for the supported image files', () => {
const fileTypes = ['image/jpeg', 'image/jp2', 'image/tiff', 'image/tiff-fx', 'image/png'];
const fileTypes = ['jpg', 'jpeg', 'jp2', 'tiff', 'tif', 'png'];

for (const type of fileTypes) {
expect(testHostComponent.uploadComp['_isFileTypeSupported'](type)).toBeTruthy();
}
});

it('should return false for unsupported image files', () => {
// --> TODO: add real unsupported filetypes?
const fileTypes = ['image/a', 'image/b', 'image/c', 'image/d', 'image/e'];
const fileTypes = ['gif', 'bmp', 'psd', 'raw', 'pdf', 'eps', 'ai', 'indd'];
for (const type of fileTypes) {
expect(testHostComponent.uploadComp['_isFileTypeSupported'](type)).toBeFalsy();
}
Expand Down
Expand Up @@ -46,13 +46,13 @@ export class UploadComponent implements OnInit {
thumbnailUrl: string | SafeUrl;

allowedFileTypes: string[];
// todo: maybe we can use this list to display which file format is allowed to
supportedImageTypes = ['image/jpeg', 'image/jp2', 'image/tiff', 'image/tiff-fx', 'image/png'];
supportedDocumentTypes = ['application/pdf'];
supportedAudioTypes = ['audio/mpeg'];
supportedVideoTypes = ['video/mp4'];
supportedArchiveTypes = ['application/zip', 'application/x-tar', 'application/gzip'];
supportedTextTypes = ['application/csv', 'application/xml', 'text/csv', 'text/plain', 'text/xml'];

supportedAudioTypes = ['mp3', 'wav'];
supportedArchiveTypes = ['zip', 'tar', 'gz', 'gzip', '7z', 'tgz', 'z'];
mdelez marked this conversation as resolved.
Show resolved Hide resolved
supportedDocumentTypes = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'];
supportedImageTypes = ['jp2', 'tif', 'tiff', 'png', 'jpeg', 'jpg'];
supportedTextTypes = ['xml', 'xsl', 'xsd', 'txt', 'csv'];
supportedVideoTypes = ['mp4'];

constructor(
private _fb: FormBuilder,
Expand Down Expand Up @@ -84,7 +84,7 @@ export class UploadComponent implements OnInit {
this.file = files[0];

// only certain filetypes are supported
if (!this._isFileTypeSupported(this.file.type)) {
if (!this._isFileTypeSupported(this.file.name.split('.').pop())) {
const error = 'ERROR: File type not supported';
this._notification.openSnackBar(error);
this.file = null;
Expand Down Expand Up @@ -240,7 +240,6 @@ export class UploadComponent implements OnInit {
break;

default:
// --> TODO for UPLOAD: expand with other representation file types
break;
}

Expand Down Expand Up @@ -292,11 +291,9 @@ export class UploadComponent implements OnInit {
break;

default:
// --> TODO for UPLOAD: expand with other representation file types
break;
}

// const fileValue = new UpdateStillImageFileValue();
fileValue.filename = filename;
fileValue.id = id;

Expand Down