Skip to content

Commit

Permalink
fixed prefix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonEntholzer committed Nov 9, 2024
1 parent fdc2501 commit bfac2f0
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,33 @@ export class AttachmentUnitComponent extends LectureUnitDirective<AttachmentUnit
getFileName(): string {
if (this.lectureUnit().attachment?.link) {
const link = this.lectureUnit().attachment!.link!;
return link.substring(link.lastIndexOf('/') + 1);
const filename = link.substring(link.lastIndexOf('/') + 1);
return this.replaceAttachmentPrefixAndUnderscores(filename);
}
return '';
}

/**
* Downloads the file
*/
handleDownload() {
this.logEvent();

if (this.lectureUnit().attachment?.link) {
const link = this.lectureUnit().attachment!.link!;
this.fileService.downloadFile(link);
this.fileService.downloadFile(this.replaceAttachmentPrefixAndUnderscores(link));
this.onCompletion.emit({ lectureUnit: this.lectureUnit(), completed: true });
}
}

/**
* Removes the prefix from the file name, and replaces underscore with spaces
* @param link
*/
private replaceAttachmentPrefixAndUnderscores(link: string): string {
return link.replace(/AttachmentUnit_\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}_/, '').replace(/_/g, ' ');
}

/**
* Returns the matching icon for the file extension of the attachment
*/
Expand Down

0 comments on commit bfac2f0

Please sign in to comment.