Skip to content

Commit cbba67a

Browse files
fix(files): download files (#567)
1 parent 123ae09 commit cbba67a

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

src/app/features/files/pages/files/files.component.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -465,23 +465,15 @@ export class FilesComponent {
465465

466466
downloadFolder(): void {
467467
const resourceId = this.resourceId();
468-
const folderId = this.currentFolder()?.id ?? '';
469-
const isRootFolder = !this.currentFolder()?.relationships?.parentFolderLink;
470-
const storageLink = this.currentRootFolder()?.folder?.links?.download ?? '';
471468
const resourcePath = this.resourceMetadata()?.type ?? 'nodes';
472-
473-
if (resourceId && folderId) {
469+
const downloadLink = this.currentFolder()?.links.download ?? '';
470+
if (resourceId && downloadLink) {
474471
this.dataciteService
475472
.logFileDownload(resourceId, resourcePath)
476473
.pipe(takeUntilDestroyed(this.destroyRef))
477474
.subscribe();
478-
if (isRootFolder) {
479-
const link = this.filesService.getFolderDownloadLink(storageLink, '', true);
480-
window.open(link, '_blank')?.focus();
481-
} else {
482-
const link = this.filesService.getFolderDownloadLink(storageLink, folderId, false);
483-
window.open(link, '_blank')?.focus();
484-
}
475+
const link = this.filesService.getFolderDownloadLink(downloadLink);
476+
window.open(link, '_blank')?.focus();
485477
}
486478
}
487479

src/app/shared/components/files-tree/files-tree.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
361361

362362
downloadFolder(downloadLink: string): void {
363363
if (downloadLink) {
364-
const link = this.filesService.getFolderDownloadLink(downloadLink, '', false);
364+
const link = this.filesService.getFolderDownloadLink(downloadLink);
365365
window.open(link, '_blank')?.focus();
366366
}
367367
}

src/app/shared/services/files.service.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,10 @@ export class FilesService {
170170
);
171171
}
172172

173-
getFolderDownloadLink(storageLink: string, folderId: string, isRootFolder: boolean): string {
174-
const separator = storageLink.includes('?') ? '&' : '?';
173+
getFolderDownloadLink(link: string): string {
174+
const separator = link.includes('?') ? '&' : '?';
175175

176-
if (isRootFolder) {
177-
return `${storageLink}${separator}zip=`;
178-
}
179-
return `${storageLink}${folderId}/${separator}zip=`;
176+
return `${link}${separator}zip=`;
180177
}
181178

182179
getFileTarget(fileGuid: string): Observable<OsfFile> {

0 commit comments

Comments
 (0)