Skip to content

Commit

Permalink
Fix conflicts and adjust DamFileDownloadLinkBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdax98 committed Jun 6, 2024
1 parent c2555c6 commit 1ba2c1c
Show file tree
Hide file tree
Showing 19 changed files with 1,126 additions and 1,024 deletions.
9 changes: 0 additions & 9 deletions demo/admin/src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import { createCometTheme } from "@comet/admin-theme";
import type {} from "@mui/lab/themeAugmentation";

<<<<<<< HEAD
export default createCometTheme();
=======
export const theme = createCometTheme();

declare module "@mui/styles/defaultTheme" {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DefaultTheme extends Theme {}
}
>>>>>>> main
2 changes: 1 addition & 1 deletion demo/api/block-meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@
{
"name": "youtubeIdentifier",
"kind": "String",
"nullable": false
"nullable": true
},
{
"name": "aspectRatio",
Expand Down
1 change: 0 additions & 1 deletion demo/site/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
14 changes: 1 addition & 13 deletions demo/site/src/blocks/LinkBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<<<<<<< HEAD
"use client";
import { ExternalLinkBlock, OneOfBlock, PropsWithData, SupportedBlocks, withPreview } from "@comet/cms-site";
=======
import {
DamFileDownloadLinkBlock,
ExternalLinkBlock,
InternalLinkBlock,
OneOfBlock,
PropsWithData,
SupportedBlocks,
withPreview,
} from "@comet/cms-site";
>>>>>>> main
import { DamFileDownloadLinkBlock, ExternalLinkBlock, OneOfBlock, PropsWithData, SupportedBlocks, withPreview } from "@comet/cms-site";
import { LinkBlockData } from "@src/blocks.generated";
import { NewsLinkBlock } from "@src/news/blocks/NewsLinkBlock";
import * as React from "react";
Expand Down
6 changes: 1 addition & 5 deletions docs/docs/dependencies/index.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<<<<<<< HEAD
---
title: Dependencies
title: Block Index / Dependencies
sidebar_position: 15
---

# Dependencies
=======
# Block Index / Dependencies
>>>>>>> main

Blocks can have references to entities.
But since block data is stored as JSON, there is no actual database relationship.
Expand Down
19 changes: 4 additions & 15 deletions packages/admin/admin-theme/src/createCometTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,21 @@ import { paletteOptions as cometPaletteOptions } from "./paletteOptions";
import { shadows } from "./shadows";
import { createTypographyOptions as createCometTypographyOptions } from "./typographyOptions";

<<<<<<< HEAD
export const createCometTheme = ({
palette: passedPaletteOptions = {},
typography: passedTypographyOptions = {},
spacing: passedSpacingOptions = 5,
components: passedComponentsOptions = {},
zIndex: passedZIndexOptions = {},
breakpoints: passedBreakpointsOptions = {},
...restPassedOptions
}: ThemeOptions | undefined = {}): Theme => {
const breakpointsOptions: BreakpointsOptions = deepmerge<BreakpointsOptions>(cometBreakpointsOptions, passedBreakpointsOptions);
const breakpoints = createBreakpoints(breakpointsOptions);

=======
export const createCometTheme = (
{
palette: passedPaletteOptions = {},
typography: passedTypographyOptions = {},
spacing: passedSpacingOptions = 5,
components: passedComponentsOptions = {},
zIndex: passedZIndexOptions = {},
breakpoints: passedBreakpointsOptions = {},
...restPassedOptions
}: ThemeOptions | undefined = {},
...args: object[]
): Theme => {
>>>>>>> main
const breakpointsOptions: BreakpointsOptions = deepmerge<BreakpointsOptions>(cometBreakpointsOptions, passedBreakpointsOptions);
const breakpoints = createBreakpoints(breakpointsOptions);

const paletteOptions: PaletteOptions = deepmerge<PaletteOptions>(cometPaletteOptions, passedPaletteOptions);
const palette = createPalette(paletteOptions);

Expand Down
13 changes: 2 additions & 11 deletions packages/admin/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@
"test:watch": "jest --watch"
},
"dependencies": {
<<<<<<< HEAD
"@comet/admin-icons": "workspace:^6.10.0",
"@mui/lab": "^5.0.0-alpha.76",
=======
"@comet/admin-icons": "workspace:^6.12.0",
>>>>>>> main
"@mui/lab": "^5.0.0-alpha.76",
"@mui/private-theming": "^5.0.0",
"clsx": "^1.1.1",
"exceljs": "^3.4.0",
Expand All @@ -51,14 +47,9 @@
"@apollo/client": "^3.7.0",
"@babel/cli": "^7.17.6",
"@babel/core": "^7.20.12",
<<<<<<< HEAD
"@comet/admin-babel-preset": "workspace:^6.10.0",
"@comet/admin-theme": "workspace:^6.10.0",
"@comet/eslint-config": "workspace:^6.10.0",
=======
"@comet/admin-babel-preset": "workspace:^6.12.0",
"@comet/admin-theme": "workspace:^6.12.0",
"@comet/eslint-config": "workspace:^6.12.0",
>>>>>>> main
"@emotion/react": "^11.5.0",
"@emotion/styled": "^11.3.0",
"@mui/icons-material": "^5.0.0",
Expand Down
4 changes: 0 additions & 4 deletions packages/admin/admin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ export { FinalFormSaveSplitButton } from "./FinalFormSaveSplitButton";
export { FinalFormAutocomplete, FinalFormAutocompleteProps } from "./form/Autocomplete";
export { FinalFormCheckbox, FinalFormCheckboxProps } from "./form/Checkbox";
export { Field, FieldProps } from "./form/Field";
<<<<<<< HEAD
export { FieldContainer, FieldContainerClassKey, FieldContainerProps } from "./form/FieldContainer";
=======
export { FieldContainer, FieldContainerClassKey, FieldContainerComponent, FieldContainerProps } from "./form/FieldContainer";
export { AsyncSelectField, AsyncSelectFieldProps } from "./form/fields/AsyncSelectField";
>>>>>>> main
export { CheckboxField, CheckboxFieldProps } from "./form/fields/CheckboxField";
export { SearchField, SearchFieldProps } from "./form/fields/SearchField";
export { SelectField, SelectFieldProps } from "./form/fields/SelectField";
Expand Down
8 changes: 1 addition & 7 deletions packages/admin/cms-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,10 @@
"@apollo/client": "^3.7.0",
"@babel/cli": "^7.17.6",
"@babel/core": "^7.20.12",
<<<<<<< HEAD
"@comet/admin-babel-preset": "workspace:^6.10.0",
"@comet/admin-theme": "workspace:^6.10.0",
"@comet/cli": "workspace:^6.10.0",
"@comet/eslint-config": "workspace:^6.10.0",
=======
"@comet/admin-babel-preset": "workspace:^6.12.0",
"@comet/admin-theme": "workspace:^6.12.0",
"@comet/cli": "workspace:^6.12.0",
"@comet/eslint-config": "workspace:^6.12.0",
>>>>>>> main
"@emotion/react": "^11.5.0",
"@emotion/styled": "^11.3.0",
"@graphql-codegen/cli": "^2.0.0",
Expand Down
13 changes: 2 additions & 11 deletions packages/api/cms-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@
"test:watch": "jest --watch"
},
"dependencies": {
<<<<<<< HEAD
"@aws-sdk/client-s3": "^3.256.0",
"@azure/storage-blob": "^12.17.0",
"@comet/blocks-api": "workspace:^6.10.0",
=======
"@aws-sdk/client-s3": "^3.591.0",
"@azure/storage-blob": "^12.23.0",
"@comet/blocks-api": "workspace:^6.12.0",
>>>>>>> main
"@fast-csv/parse": "^4.3.6",
"@golevelup/nestjs-discovery": "^3.0.0",
"@hapi/accept": "^5.0.2",
Expand Down Expand Up @@ -85,12 +81,7 @@
},
"devDependencies": {
"@aws-sdk/types": "^3.47.0",
<<<<<<< HEAD
"@comet/eslint-config": "workspace:^6.10.0",
=======
"@azure/storage-blob": "^12.0.0",
"@comet/eslint-config": "workspace:^6.12.0",
>>>>>>> main
"@golevelup/ts-jest": "^0.4.0",
"@kubernetes/client-node": "^0.18.1",
"@mikro-orm/core": "^5.7.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { BlockContext, BlockTransformerServiceInterface, TraversableTransformResponse } from "@comet/blocks-api";
import { Injectable } from "@nestjs/common";

import { FilesService } from "../files/files.service";
import { DamFileDownloadLinkBlockData } from "./dam-file-download-link.block";

type TransformResponse = {
damFile?: {
id: string;
name: string;
fileUrl: string;
};
};

@Injectable()
export class DamFileDownloadLinkBlockTransformerService implements BlockTransformerServiceInterface<DamFileDownloadLinkBlockData, TransformResponse> {
constructor(private readonly filesService: FilesService) {}

async transformToPlain(block: DamFileDownloadLinkBlockData, { includeInvisibleContent, previewDamUrls, relativeDamUrls }: BlockContext) {
const ret: TraversableTransformResponse = {
openFileType: block.openFileType,
};

if (block.fileId === undefined) {
return ret;
}

const file = await this.filesService.findOneById(block.fileId);

if (file && block.openFileType === "NewTab") {
ret.file = {
id: file.id,
name: file.name,
fileUrl: await this.filesService.createFileUrl(file, { previewDamUrls, relativeDamUrls }),
};
} else if (file && block.openFileType === "Download") {
ret.file = {
id: file.id,
name: file.name,
fileUrl: await this.filesService.createFileDownloadUrl(file, { previewDamUrls, relativeDamUrls }),
};
}

return ret;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
AnnotationBlockMeta,
BlockContext,
BlockData,
BlockField,
BlockIndexData,
Expand All @@ -9,54 +8,26 @@ import {
BlockMetaFieldKind,
createBlock,
inputToData,
TraversableTransformResponse,
} from "@comet/blocks-api";
import { IsEnum, IsUUID } from "class-validator";
import { FilesService } from "src/dam/files/files.service";

import { IsUndefinable } from "../../common/validators/is-undefinable";
import { FILE_ENTITY } from "../../dam/files/entities/file.entity";
import { FILE_ENTITY } from "../files/entities/file.entity";
import { DamFileDownloadLinkBlockTransformerService } from "./dam-file-download-link-block-transformer.service";

export enum OpenFileTypeMethod {
NewTab = "NewTab",
Download = "Download",
}

class DamFileDownloadLinkBlockData extends BlockData {
export class DamFileDownloadLinkBlockData extends BlockData {
fileId?: string;

@BlockField({ type: "enum", enum: OpenFileTypeMethod })
openFileType: OpenFileTypeMethod;

async transformToPlain(
{ filesService }: { filesService: FilesService },
{ previewDamUrls }: BlockContext,
): Promise<TraversableTransformResponse> {
const ret: TraversableTransformResponse = {
openFileType: this.openFileType,
};

if (this.fileId === undefined) {
return ret;
}

const file = await filesService.findOneById(this.fileId);

if (file && this.openFileType === "NewTab") {
ret.file = {
id: file.id,
name: file.name,
fileUrl: await filesService.createFileUrl(file, previewDamUrls),
};
} else if (file && this.openFileType === "Download") {
ret.file = {
id: file.id,
name: file.name,
fileUrl: await filesService.createFileDownloadUrl(file, previewDamUrls),
};
}

return ret;
async transformToPlain() {
return DamFileDownloadLinkBlockTransformerService;
}

indexData(): BlockIndexData {
Expand Down
2 changes: 2 additions & 0 deletions packages/api/cms-api/src/dam/dam.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DynamicModule, Global, Module, Type, ValueProvider } from "@nestjs/comm
import { TypeMetadataStorage } from "@nestjs/graphql";

import { BlobStorageModule, defaultDamAcceptedMimetypes, DependentsResolverFactory } from "..";
import { DamFileDownloadLinkBlockTransformerService } from "./blocks/dam-file-download-link-block-transformer.service";
import { DamVideoBlockTransformerService } from "./blocks/dam-video-block-transformer.service";
import { PixelImageBlockTransformerService } from "./blocks/pixel-image-block-transformer.service";
import { SvgImageBlockTransformerService } from "./blocks/svg-image-block-transformer.service";
Expand Down Expand Up @@ -128,6 +129,7 @@ export class DamModule {
PixelImageBlockTransformerService,
SvgImageBlockTransformerService,
DamVideoBlockTransformerService,
DamFileDownloadLinkBlockTransformerService,
],
controllers: [createFilesController({ Scope }), FoldersController, ImagesController],
exports: [
Expand Down
17 changes: 3 additions & 14 deletions packages/api/cms-api/src/dam/files/files.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ export function createFilesController({ Scope: PassedScope }: { Scope?: Type<Dam
return this.streamFile(file, res, { range, overrideHeaders: { "Cache-control": "private" } });
}

<<<<<<< HEAD
@DisableCometGuards()
=======
@Get(`/download/preview/${fileUrl}`)
async previewDownloadFile(
@Param() { fileId }: FileParams,
Expand All @@ -135,16 +132,9 @@ export function createFilesController({ Scope: PassedScope }: { Scope?: Type<Dam
return this.streamFile(file, res, { range, overrideHeaders: { "Cache-control": "private" } });
}

@DisableGlobalGuard()
@DisableCometGuards()
@Get(`/download/:hash/${fileUrl}`)
async downloadFile(
@Param() { hash, ...params }: HashFileParams,
@Res() res: Response,
@Headers(CDN_ORIGIN_CHECK_HEADER) cdnOriginCheck: string,
@Headers("range") range?: string,
): Promise<void> {
this.checkCdnOrigin(cdnOriginCheck);

async downloadFile(@Param() { hash, ...params }: HashFileParams, @Res() res: Response, @Headers("range") range?: string): Promise<void> {
if (!this.isValidHash(hash, params)) {
throw new NotFoundException();
}
Expand All @@ -159,8 +149,7 @@ export function createFilesController({ Scope: PassedScope }: { Scope?: Type<Dam
return this.streamFile(file, res, { range });
}

@DisableGlobalGuard()
>>>>>>> main
@DisableCometGuards()
@Get(`/:hash/${fileUrl}`)
async hashedFileUrl(@Param() { hash, ...params }: HashFileParams, @Res() res: Response, @Headers("range") range?: string): Promise<void> {
if (!this.isValidHash(hash, params)) {
Expand Down
10 changes: 5 additions & 5 deletions packages/api/cms-api/src/dam/files/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,13 @@ export class FilesService {
return [...baseUrl, file.id, filename].join("/");
}

async createFileDownloadUrl(file: FileInterface, previewDamUrls?: boolean): Promise<string> {
async createFileDownloadUrl(
file: FileInterface,
{ previewDamUrls = false, relativeDamUrls = false }: { previewDamUrls?: boolean; relativeDamUrls?: boolean },
): Promise<string> {
const filename = parse(file.name).name;

// Use CDN url only if available and not in preview as preview requires auth
const baseUrl = [
this.config.cdnEnabled && !previewDamUrls ? `${this.config.cdnDomain}/files/download` : `${this.config.filesBaseUrl}/download`,
];
const baseUrl = [`${relativeDamUrls ? "" : this.config.apiUrl}/dam/files/download`];

if (previewDamUrls) {
baseUrl.push("preview");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ export class UserPermissionsService {
...(await this.discoveryService.controllersWithMetaAtKey<RequiredPermissionMetadata>("requiredPermission")),
]
.flatMap((p) => p.meta.requiredPermission)
<<<<<<< HEAD
.concat(["prelogin"]) // Add permission to allow checking if a specific user has access to a site where preloginEnabled is true
=======
>>>>>>> main
.filter((p) => p !== DisablePermissionCheck)
.sort(),
),
Expand Down
Loading

0 comments on commit 1ba2c1c

Please sign in to comment.