Skip to content

Commit

Permalink
files: fix upload of files with special characters in filename
Browse files Browse the repository at this point in the history
Co-Authored-by: Valeria Granata <[email protected]>
  • Loading branch information
vgranata and vgranata committed Sep 26, 2022
1 parent 175182f commit 8926bc8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions projects/rero/ng-core/src/lib/record/files/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class RecordFilesComponent implements OnDestroy, OnInit {
this._spinner.hide();

return this._fileService
.delete(this.type, this.pid, file.key, file.version_id)
.delete(this.type, this.pid, encodeURIComponent(file.key), file.version_id)
.pipe(map(() => true));
}
return of(false);
Expand Down Expand Up @@ -353,8 +353,8 @@ export class RecordFilesComponent implements OnDestroy, OnInit {
reader.onload = () => {
// Update or create a new file
const fileName = this.currentFile
? this.currentFile.key
: this.fileKey;
? encodeURIComponent(this.currentFile.key)
: encodeURIComponent(this.fileKey);

this._fileService
.put(this.type, this.pid, fileName, file)
Expand Down Expand Up @@ -410,7 +410,7 @@ export class RecordFilesComponent implements OnDestroy, OnInit {
* @returns URL of the file.
*/
getFileUrl(file: RecordFile): string {
return this._fileService.getUrl(this.type, this.pid, file.key);
return this._fileService.getUrl(this.type, this.pid, encodeURIComponent(file.key));
}

/**
Expand Down Expand Up @@ -528,9 +528,20 @@ export class RecordFilesComponent implements OnDestroy, OnInit {

// Get metadata stored in record.
const metadata = this.record._files.filter(
(item: any) => fileKey === item.key
(item: any) => fileKey === item.key.normalize('NFD')
);

// Unicode normalization form of download and preview paths
const links = 'links';
if (metadata.length > 0 && metadata[0][links]) {
Object.keys(metadata[0][links]).forEach((key) => {
if (['download', 'preview'].includes(key)) {
if (metadata[0][links] && metadata[0][links][key]) {
metadata[0][links][key].normalize('NFD');
}
}
});
}
return metadata.length > 0 ? metadata[0] : null;
}
}

0 comments on commit 8926bc8

Please sign in to comment.