Skip to content

Commit

Permalink
Rename public uploads to file uploads
Browse files Browse the repository at this point in the history
The name "public uploads" was not fitting since the uploads can also be used for "private" uploads in the Admin.
The feature was therefore renamed to "file uploads".

This requires the following changes:

-   Use `FilesUploadModule` instead of `PublicUploadModule`
-   Use `FileUpload` instead of `PublicUpload`
-   Use `FileUploadsService` instead of `PublicUploadsService`
-   Change the upload URL from `/public-upload/files/upload` to `/files-uploads/upload`
  • Loading branch information
johnnyomair committed Jul 25, 2024
1 parent 34ae666 commit 5211402
Show file tree
Hide file tree
Showing 32 changed files with 304 additions and 228 deletions.
7 changes: 7 additions & 0 deletions .changeset/beige-brooms-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/cms-api": major
---

Remove `download` helper

Use `createFileUploadInputFromUrl` instead.
7 changes: 7 additions & 0 deletions .changeset/bright-lobsters-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@comet/cms-api": major
---

Remove `FileUploadService`

Use `createFileUploadInputFromUrl` instead of `FileUploadService#createFileUploadInputFromUrl`.
15 changes: 15 additions & 0 deletions .changeset/nice-pigs-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@comet/cms-api": major
---

Rename public uploads to file uploads

The name "public uploads" was not fitting since the uploads can also be used for "private" uploads in the Admin.
The feature was therefore renamed to "file uploads".

This requires the following changes:

- Use `FilesUploadModule` instead of `PublicUploadModule`
- Use `FileUpload` instead of `PublicUpload`
- Use `FileUploadsService` instead of `PublicUploadsService`
- Change the upload URL from `/public-upload/files/upload` to `/files-uploads/upload`
34 changes: 17 additions & 17 deletions demo/api/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,6 @@ A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date
"""
scalar DateTime

type Dependency {
rootId: String!
rootGraphqlObjectType: String!
rootColumnName: String!
jsonPath: String!
visible: Boolean!
targetGraphqlObjectType: String!
targetId: String!
name: String
secondaryInformation: String
}

type PaginatedDependencies {
nodes: [Dependency!]!
totalCount: Int!
}

type ImageCropArea {
focalPoint: FocalPoint!
width: Float
Expand Down Expand Up @@ -107,6 +90,23 @@ enum LicenseType {
RIGHTS_MANAGED
}

type Dependency {
rootId: String!
rootGraphqlObjectType: String!
rootColumnName: String!
jsonPath: String!
visible: Boolean!
targetGraphqlObjectType: String!
targetId: String!
name: String
secondaryInformation: String
}

type PaginatedDependencies {
nodes: [Dependency!]!
totalCount: Int!
}

type BuildTemplate {
id: ID!
name: String!
Expand Down
8 changes: 4 additions & 4 deletions demo/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
CronJobsModule,
DamModule,
DependenciesModule,
FileUploadsModule,
KubernetesModule,
PageTreeModule,
PublicUploadModule,
RedirectsModule,
UserPermissionsModule,
} from "@comet/cms-api";
Expand Down Expand Up @@ -136,9 +136,9 @@ export class AppModule {
File: DamFile,
Folder: DamFolder,
}),
PublicUploadModule.register({
maxFileSize: config.publicUploads.maxFileSize,
directory: `${config.blob.storageDirectoryPrefix}-public-uploads`,
FileUploadsModule.register({
maxFileSize: config.fileUploads.maxFileSize,
directory: `${config.blob.storageDirectoryPrefix}-file-uploads`,
acceptedMimeTypes: ["application/pdf", "application/x-zip-compressed", "application/zip"],
}),
...(config.contentGeneration
Expand Down
2 changes: 1 addition & 1 deletion demo/api/src/comet-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"publicUploads": {
"fileUploads": {
"maxFileSize": 15
},
"imgproxy": {
Expand Down
6 changes: 3 additions & 3 deletions demo/api/src/db/fixtures/fixtures.console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import faker from "faker";
import { Command, Console } from "nestjs-console";
import slugify from "slugify";

import { FileUploadsFixtureService } from "./generators/file-uploads-fixture.service";
import { generateLinks } from "./generators/links.generator";
import { ManyImagesTestPageFixtureService } from "./generators/many-images-test-page-fixture.service";
import { PublicUploadsFixtureService } from "./generators/public-uploads-fixture.service";

export interface PageTreeNodesFixtures {
home?: PageTreeNodeInterface;
Expand Down Expand Up @@ -48,7 +48,7 @@ export class FixturesConsole {
@InjectRepository(Page) private readonly pagesRepository: EntityRepository<Page>,
@InjectRepository(Link) private readonly linksRepository: EntityRepository<Link>,
private readonly manyImagesTestPageFixtureService: ManyImagesTestPageFixtureService,
private readonly publicUploadsFixtureService: PublicUploadsFixtureService,
private readonly fileUploadsFixtureService: FileUploadsFixtureService,
) {}

@Command({
Expand Down Expand Up @@ -275,7 +275,7 @@ export class FixturesConsole {
console.log(`Generated ${pagesCount} lorem ipsum pages for ${domain}`);
}

await this.publicUploadsFixtureService.generatePublicUploads();
await this.fileUploadsFixtureService.generateFileUploads();

await this.orm.em.flush();
}
Expand Down
4 changes: 2 additions & 2 deletions demo/api/src/db/fixtures/fixtures.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { LinksModule } from "@src/links/links.module";
import { PagesModule } from "@src/pages/pages.module";
import { ConsoleModule } from "nestjs-console";

import { FileUploadsFixtureService } from "./generators/file-uploads-fixture.service";
import { ManyImagesTestPageFixtureService } from "./generators/many-images-test-page-fixture.service";
import { PublicUploadsFixtureService } from "./generators/public-uploads-fixture.service";
import { SvgImageFileFixtureService } from "./generators/svg-image-file-fixture.service";
import { UnsplashImageFileFixtureService } from "./generators/unsplash-image-file-fixture.service";

Expand All @@ -17,7 +17,7 @@ import { UnsplashImageFileFixtureService } from "./generators/unsplash-image-fil
ManyImagesTestPageFixtureService,
UnsplashImageFileFixtureService,
SvgImageFileFixtureService,
PublicUploadsFixtureService,
FileUploadsFixtureService,
],
})
export class FixturesModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createFileUploadInputFromUrl, FileUpload, FileUploadsService } from "@comet/cms-api";
import { Injectable } from "@nestjs/common";
import path from "path";

@Injectable()
export class FileUploadsFixtureService {
constructor(private readonly fileUploadsService: FileUploadsService) {}

async generateFileUploads(): Promise<FileUpload[]> {
console.log("Generating file uploads...");

const images = ["01.jpg", "02.jpg", "03.jpg", "04.jpg", "05.jpg"];
const fileUploads: FileUpload[] = [];

for (const image of images) {
const file = await createFileUploadInputFromUrl(path.resolve(`./src/db/fixtures/generators/images/${image}`));
fileUploads.push(await this.fileUploadsService.upload(file));
}

return fileUploads;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { FileInterface, FilesService, FileUploadService } from "@comet/cms-api";
import { createFileUploadInputFromUrl, FileInterface, FilesService } from "@comet/cms-api";
import { Injectable } from "@nestjs/common";
import { DamScope } from "@src/dam/dto/dam-scope";
import path from "path";

@Injectable()
export class SvgImageFileFixtureService {
constructor(private readonly filesService: FilesService, private readonly fileUploadService: FileUploadService) {}
constructor(private readonly filesService: FilesService) {}

async generateImage(scope: DamScope): Promise<FileInterface> {
const file = await this.fileUploadService.createFileUploadInputFromUrl(
path.resolve(`./src/db/fixtures/generators/images/comet-logo-claim.svg`),
);
const file = await createFileUploadInputFromUrl(path.resolve(`./src/db/fixtures/generators/images/comet-logo-claim.svg`));
// Convert to what the browser would send
file.mimetype = "image/svg+xml";
file.originalname = "comet-logo-claim.svg";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FileInterface, FilesService, FileUploadService } from "@comet/cms-api";
import { createFileUploadInputFromUrl, FileInterface, FilesService } from "@comet/cms-api";
import { Injectable } from "@nestjs/common";
import { DamScope } from "@src/dam/dto/dam-scope";
import faker from "faker";

@Injectable()
export class UnsplashImageFileFixtureService {
constructor(private readonly filesService: FilesService, private readonly fileUploadService: FileUploadService) {}
constructor(private readonly filesService: FilesService) {}

async generateImage(scope: DamScope): Promise<FileInterface> {
const width = faker.datatype.number({
Expand All @@ -19,7 +19,7 @@ export class UnsplashImageFileFixtureService {

const imageUrl = `https://source.unsplash.com/all/${width}x${height}`;
console.log(`Downloading ${imageUrl}.`);
const downloadedImage = await this.fileUploadService.createFileUploadInputFromUrl(imageUrl);
const downloadedImage = await createFileUploadInputFromUrl(imageUrl);
console.log(`Downloading ${imageUrl} done.`);
console.log(`Uploading ${downloadedImage.originalname}.`);
const file = await this.filesService.upload(downloadedImage, { scope });
Expand Down
63 changes: 63 additions & 0 deletions docs/docs/migration/migration-from-v6-to-v7.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,69 @@ Recommended enum values are (depending on the use case):
The `update{Entity}Visibility` mutation is also removed.
Use the generic `update{Entity}` mutation instead.

### Rename public uploads

The `PublicUploadModule` was renamed to `FileUploadsModule`.

:::warning

The public uploads module was unintentionally added to the Starter. If you don't use the feature in your application, remove the module instead.

:::

This requires the following changes:

- In `comet-config.json` rename `publicUploads` to `fileUploads`.

```diff
{
- "publicUploads": {
+ "fileUploads": {
"maxFileSize": 15
}
}
```

- In `app.module.ts` change the import from `PublicUploadModule` to `FileUploadsModule`.

```diff
- PublicUploadModule.register({
+ FileUploadsModule.register({
- maxFileSize: config.publicUploads.maxFileSize,
- directory: `${config.blob.storageDirectoryPrefix}-public-uploads`,
+ maxFileSize: config.fileUploads.maxFileSize,
+ directory: `${config.blob.storageDirectoryPrefix}-file-uploads`,
})
```

- Change all usages of the `PublicUpload` entity to `FileUpload`.
- Change all usages of the `PublicUploadsService` to `FileUploadsService`.
- In the site or the Admin change the upload URL from `/public-upload/files/upload` to `/files-uploads/upload`.

### Remove usages of `download` or `FileUploadService`

Use `createFileUploadInputFromUrl` instead:

```diff
- import { FileUploadService } from "@comet/cms-api";
+ import { createFileUploadInputFromUrl } from "@comet/cms-api";

@Injectable()
export class SvgImageFileFixtureService {
constructor(
private readonly filesService: FilesService,
- private readonly fileUploadService: FileUploadService,
) {}

async generateImage(scope: DamScope): Promise<FileInterface> {
- const file = await this.fileUploadService.createFileUploadInputFromUrl(
+ const file = await createFileUploadInputFromUrl(
path.resolve(`./src/db/fixtures/generators/images/comet-logo-claim.svg`),
);
}
}
```

## Admin

### Remove `axios` dependency
Expand Down
34 changes: 17 additions & 17 deletions packages/api/cms-api/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@ A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date
"""
scalar DateTime

type Dependency {
rootId: String!
rootGraphqlObjectType: String!
rootColumnName: String!
jsonPath: String!
visible: Boolean!
targetGraphqlObjectType: String!
targetId: String!
name: String
secondaryInformation: String
}

type PaginatedDependencies {
nodes: [Dependency!]!
totalCount: Int!
}

type ImageCropArea {
focalPoint: FocalPoint!
width: Float
Expand Down Expand Up @@ -103,6 +86,23 @@ enum LicenseType {
RIGHTS_MANAGED
}

type Dependency {
rootId: String!
rootGraphqlObjectType: String!
rootColumnName: String!
jsonPath: String!
visible: Boolean!
targetGraphqlObjectType: String!
targetId: String!
name: String
secondaryInformation: String
}

type PaginatedDependencies {
nodes: [Dependency!]!
totalCount: Int!
}

type BuildTemplate {
id: ID!
name: String!
Expand Down
3 changes: 0 additions & 3 deletions packages/api/cms-api/src/dam/dam.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { DamFileImage } from "./files/entities/file-image.entity";
import { createFolderEntity, FolderInterface } from "./files/entities/folder.entity";
import { FileImagesResolver } from "./files/file-image.resolver";
import { FileLicensesResolver } from "./files/file-licenses.resolver";
import { FileUploadService } from "./files/file-upload.service";
import { FileValidationService } from "./files/file-validation.service";
import { createFilesController } from "./files/files.controller";
import { createFilesResolver } from "./files/files.resolver";
Expand Down Expand Up @@ -126,7 +125,6 @@ export class DamModule {
FileImagesResolver,
CalculateDominantImageColor,
FileValidationService,
FileUploadService,
PixelImageBlockTransformerService,
SvgImageBlockTransformerService,
DamVideoBlockTransformerService,
Expand All @@ -141,7 +139,6 @@ export class DamModule {
ImagesService,
ScaledImagesCacheService,
damConfigProvider,
FileUploadService,
PixelImageBlockTransformerService,
SvgImageBlockTransformerService,
DamVideoBlockTransformerService,
Expand Down
Loading

0 comments on commit 5211402

Please sign in to comment.