Skip to content

Commit

Permalink
Expose pixelImage fileUrl only in Admin (#1267)
Browse files Browse the repository at this point in the history
* Expose pixelImage fileUrl only in admin

Use the already existing context parameter includeInvisibleContent that is set in admin.

This avoids getting the fileUrl into site JSON which might be found by crawlers. We don't want the
original file to be cralwed.

* chore(changelog): add changeset for #1267

---------

Co-authored-by: Thomas Dax <thomas.dax@vivid-planet.com>
  • Loading branch information
nsams and thomasdax98 authored Sep 18, 2023
1 parent b948d10 commit cd07c10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-bees-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/cms-api": patch
---

Prevent the fileUrl from being exposed in the Site via the PixelImageBlock
6 changes: 4 additions & 2 deletions packages/api/cms-api/src/blocks/PixelImageBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PixelImageBlockData extends BlockData {

async transformToPlain(
{ filesService, imagesService }: { filesService: FilesService; imagesService: ImagesService },
{ previewDamUrls }: BlockContext,
{ previewDamUrls, includeInvisibleContent }: BlockContext,
): Promise<TraversableTransformResponse> {
if (!this.damFileId) {
return {};
Expand All @@ -43,6 +43,8 @@ class PixelImageBlockData extends BlockData {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { createdAt, updatedAt, folder, license, ...data } = file;

const fileUrl = includeInvisibleContent ? await filesService.createFileUrl(file, previewDamUrls) : undefined;

return {
damFile: {
...data,
Expand All @@ -54,7 +56,7 @@ class PixelImageBlockData extends BlockData {
dominantColor: file.image.dominantColor,
}
: undefined,
fileUrl: await filesService.createFileUrl(file, previewDamUrls),
fileUrl,
},
cropArea: this.cropArea ? { ...this.cropArea } : undefined,
urlTemplate: imagesService.createUrlTemplate({ file, cropArea: this.cropArea }, previewDamUrls),
Expand Down

0 comments on commit cd07c10

Please sign in to comment.