-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add download functionality to DAM folders (#1230)
This PR adds the functionality to download folders recursively in the DAM as ZIP. --------- Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com> Co-authored-by: Thomas Dax <thomas.dax@vivid-planet.com>
- Loading branch information
1 parent
f243d69
commit 9d47b5b
Showing
9 changed files
with
137 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ lang/ | |
.pnp.* | ||
junit.xml | ||
.env.local | ||
**/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Controller, ForbiddenException, Get, Inject, NotFoundException, Param, Res } from "@nestjs/common"; | ||
import { Response } from "express"; | ||
|
||
import { CurrentUserInterface } from "../../auth/current-user/current-user"; | ||
import { GetCurrentUser } from "../../auth/decorators/get-current-user.decorator"; | ||
import { ACCESS_CONTROL_SERVICE } from "../../user-permissions/user-permissions.constants"; | ||
import { AccessControlServiceInterface } from "../../user-permissions/user-permissions.types"; | ||
import { FoldersService } from "./folders.service"; | ||
|
||
@Controller("dam/folders") | ||
export class FoldersController { | ||
constructor( | ||
private readonly foldersService: FoldersService, | ||
@Inject(ACCESS_CONTROL_SERVICE) private accessControlService: AccessControlServiceInterface, | ||
) {} | ||
|
||
@Get("/:folderId/zip") | ||
async createZip(@Param("folderId") folderId: string, @Res() res: Response, @GetCurrentUser() user: CurrentUserInterface): Promise<void> { | ||
const folder = await this.foldersService.findOneById(folderId); | ||
if (!folder) { | ||
throw new NotFoundException("Folder not found"); | ||
} | ||
|
||
if (folder.scope && !this.accessControlService.isAllowed(user, "dam", folder.scope)) { | ||
throw new ForbiddenException("The current user is not allowed to access this scope and download this folder."); | ||
} | ||
|
||
const zipStream = await this.foldersService.createZipStreamFromFolder(folderId); | ||
|
||
res.setHeader("Content-Disposition", `attachment; filename="${folder.name}.zip"`); | ||
res.setHeader("Content-Type", "application/zip"); | ||
zipStream.pipe(res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.