Skip to content

Commit ce32b64

Browse files
authored
Merge pull request #13 from deployment-helper/dev
Dev
2 parents 2209951 + 594dae4 commit ce32b64

25 files changed

+378
-513
lines changed

app-management/apps/app-management/src/app.module.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Module } from '@nestjs/common';
2-
import { ConfigModule } from '@nestjs/config';
2+
import { ConfigModule, ConfigService } from '@nestjs/config';
33

44
import { AppController } from './app.controller';
55
import { AppService } from './app.service';
@@ -13,10 +13,33 @@ import { OpenapiModule } from './openapi/openapi.module';
1313
import { WorkflowsController } from './workflows/workflows.controller';
1414
import { ChatgptService } from '@app/shared/openapi/chatgpt.service';
1515
import { FirestoreService } from '@app/shared/gcp/firestore.service';
16+
import { BatchController } from './batch.controller';
17+
import { BullModule } from '@nestjs/bull';
18+
import {
19+
REDIS_QUEUE_VIDEO_GENERATOR,
20+
REDIS_QUEUE_VIDEO_RECORDER,
21+
} from '@apps/batch-server/constants';
1622

1723
@Module({
1824
imports: [
1925
ConfigModule.forRoot({ isGlobal: true }),
26+
BullModule.forRootAsync({
27+
imports: [ConfigModule],
28+
inject: [ConfigService],
29+
useFactory: async (config: ConfigService) => ({
30+
redis: {
31+
host: config.getOrThrow('REDIS_HOST'),
32+
port: config.getOrThrow('REDIS_PORT'),
33+
password: config.getOrThrow('REDIS_PASS'),
34+
},
35+
}),
36+
}),
37+
BullModule.registerQueue({
38+
name: REDIS_QUEUE_VIDEO_RECORDER,
39+
}),
40+
BullModule.registerQueue({
41+
name: REDIS_QUEUE_VIDEO_GENERATOR,
42+
}),
2043
AuthModule,
2144
YoutubeModule,
2245
SlidesModule,
@@ -25,7 +48,7 @@ import { FirestoreService } from '@app/shared/gcp/firestore.service';
2548
AiModule,
2649
OpenapiModule,
2750
],
28-
controllers: [AppController, WorkflowsController],
51+
controllers: [AppController, WorkflowsController, BatchController],
2952
providers: [AppService, ChatgptService, FirestoreService],
3053
})
3154
export class AppModule {}

app-management/apps/app-management/src/aws/s3.service.spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { S3Service } from './s3.service';
3+
import { FsService } from '@app/shared/fs/fs.service';
4+
import { ConfigModule } from '@nestjs/config';
35

46
describe('S3Service', () => {
57
let service: S3Service;
68

79
beforeEach(async () => {
810
const module: TestingModule = await Test.createTestingModule({
9-
providers: [S3Service],
11+
providers: [S3Service, FsService],
12+
imports: [ConfigModule.forRoot({ isGlobal: true })],
1013
}).compile();
1114

1215
service = module.get<S3Service>(S3Service);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { BatchController } from './batch.controller';
3+
import { ConfigModule, ConfigService } from '@nestjs/config';
4+
import {
5+
REDIS_QUEUE_VIDEO_GENERATOR,
6+
REDIS_QUEUE_VIDEO_RECORDER,
7+
} from '../../batch-server/src/constants';
8+
import { BullModule } from '@nestjs/bull';
9+
import { Queue } from 'bull';
10+
11+
describe('BatchController', () => {
12+
let controller: BatchController;
13+
let recorderQueueMock: Queue;
14+
let generatorQueueMock: Queue;
15+
16+
beforeEach(async () => {
17+
recorderQueueMock = {
18+
add: jest.fn(),
19+
} as unknown as Queue;
20+
21+
generatorQueueMock = {
22+
add: jest.fn(),
23+
} as unknown as Queue;
24+
25+
const configServiceMock = {
26+
getOrThrow: jest.fn(), // Mock the get method
27+
} as unknown as ConfigService;
28+
29+
const module: TestingModule = await Test.createTestingModule({
30+
controllers: [BatchController],
31+
providers: [
32+
ConfigService,
33+
{
34+
provide: ConfigService,
35+
useValue: configServiceMock,
36+
},
37+
{
38+
provide: REDIS_QUEUE_VIDEO_RECORDER,
39+
useValue: recorderQueueMock,
40+
},
41+
{
42+
provide: REDIS_QUEUE_VIDEO_GENERATOR,
43+
useValue: generatorQueueMock,
44+
},
45+
],
46+
imports: [
47+
ConfigModule.forRoot({ isGlobal: true }),
48+
BullModule.registerQueue({
49+
name: REDIS_QUEUE_VIDEO_RECORDER,
50+
}),
51+
BullModule.registerQueue({
52+
name: REDIS_QUEUE_VIDEO_GENERATOR,
53+
}),
54+
],
55+
}).compile();
56+
57+
controller = module.get<BatchController>(BatchController);
58+
});
59+
60+
it('should be defined', () => {
61+
expect(controller).toBeDefined();
62+
});
63+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
2+
import { AuthGuard } from '@apps/app-management/auth/auth.guard';
3+
import { InjectQueue } from '@nestjs/bull';
4+
import {
5+
REDIS_QUEUE_VIDEO_GENERATOR,
6+
REDIS_QUEUE_VIDEO_RECORDER,
7+
} from '@app/shared/constants';
8+
9+
import { Queue } from 'bull';
10+
import { IGenerateVideoDto } from '@apps/batch-server/types';
11+
12+
@Controller('batch')
13+
@UseGuards(AuthGuard)
14+
export class BatchController {
15+
constructor(
16+
@InjectQueue(REDIS_QUEUE_VIDEO_RECORDER)
17+
private readonly recorderQueue: Queue,
18+
@InjectQueue(REDIS_QUEUE_VIDEO_GENERATOR)
19+
private readonly generatorQueue: Queue,
20+
) {}
21+
22+
@Post('generate/v2')
23+
async generateV2(@Body() p: IGenerateVideoDto) {
24+
const data = await this.generatorQueue.add(p);
25+
return data;
26+
}
27+
}

app-management/apps/app-management/src/constants.ts

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ export const DEFAULT_PROJECT_NAME = 'Dream';
44

55
// S3 File names
66
export const S3_VIDEO_META_DATA_FILE_NAME = 'videoMetaData.json';
7+
export const REDIS_QUEUE_VIDEO_RECORDER = 'video-recorder';
8+
export const REDIS_QUEUE_MP3_GENERATOR = 'mp3-generator';
9+
export const REDIS_QUEUE_VIDEO_GENERATOR = 'video-generator';

app-management/apps/app-management/src/models/user.model.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import {
77
import { GetCommand, PutCommand } from '@aws-sdk/lib-dynamodb';
88
import { USER_TABLE_NAME } from '@apps/app-management/constants';
99

10-
export class ProjectModel implements IProject {
11-
projectId: string;
10+
export class ProjectModel implements Partial<IProject> {
11+
id: string;
1212
projectName: string;
1313

1414
constructor(name: string) {
1515
this.projectName = name;
16-
this.projectId = uuid();
16+
this.id = uuid();
1717
}
1818

1919
toJson() {
2020
return {
21-
projectId: this.projectId,
21+
projectId: this.id,
2222
projectName: this.projectName,
2323
};
2424
}

app-management/apps/app-management/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export enum ProjectTypes {
1111
}
1212

1313
export interface IProject {
14-
projectId: string;
14+
id: string;
1515
projectName: string;
1616
userId: string;
1717
assets: string[];

app-management/apps/app-management/src/video/project.controller.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ import {
1010
} from '@nestjs/common';
1111
import { AuthGuard } from '@apps/app-management/auth/auth.guard';
1212
import { FirestoreService } from '@app/shared/gcp/firestore.service';
13-
import { filter } from 'rxjs';
1413

1514
@Controller('projects')
1615
@UseGuards(AuthGuard)
1716
export class ProjectController {
1817
constructor(private readonly firestoreService: FirestoreService) {}
19-
@Post()
18+
19+
@Get('/fix')
20+
async fixCollection() {
21+
await this.firestoreService.fixCreatedAtAndUpdatedAt('project');
22+
return 'done';
23+
}
24+
25+
@Post('/')
2026
// project_name: string
2127
createProject(
2228
@Body() data: { projectName: string; projectDesc: string },
@@ -28,7 +34,7 @@ export class ProjectController {
2834
});
2935
}
3036

31-
@Get()
37+
@Get('/')
3238
async getProjects(@Req() req: any) {
3339
return this.firestoreService.listByFields('project', [
3440
{ field: 'userId', value: req.user.sub },

app-management/apps/app-management/src/video/video.controller.ts

+34-7
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,30 @@ export class VideoController {
2525
private readonly gemini: GeminiService,
2626
) {}
2727

28+
@Get('/fix')
29+
async fixCollection() {
30+
await this.fireStore.fixCreatedAtAndUpdatedAt('video');
31+
return 'done';
32+
}
33+
2834
// create a video
2935
@Post('/')
3036
async createVideo(@Body() data: any, @Req() req: any) {
37+
// convert properties to object
38+
const obj = {};
39+
if (data.properties) {
40+
const pairs = data.properties.split('\n');
41+
42+
pairs.forEach((pair) => {
43+
const [key, value] = pair.split('=');
44+
obj[key] = value;
45+
});
46+
delete data.properties;
47+
}
48+
3149
const video = await this.fireStore.add('video', {
3250
...data,
51+
...obj,
3352
isDeleted: false,
3453
userId: req.user.sub,
3554
});
@@ -89,13 +108,21 @@ export class VideoController {
89108
@Query('addAfter') addAfter: boolean,
90109
@Body() data: any,
91110
) {
92-
return this.fireStore.updateScene(
93-
`video/${id}/scenes`,
94-
sceneId,
95-
data,
96-
sceneArrayIndex,
97-
addAfter,
98-
);
111+
if (data?.scenes && Array.isArray(data.scenes)) {
112+
return this.fireStore.updateScene(
113+
`video/${id}/scenes`,
114+
sceneId,
115+
data?.scenes,
116+
);
117+
} else {
118+
return this.fireStore.updateScene(
119+
`video/${id}/scenes`,
120+
sceneId,
121+
data,
122+
sceneArrayIndex,
123+
addAfter,
124+
);
125+
}
99126
}
100127

101128
// Delete a scene

app-management/apps/app-management/src/workflows/workflows.controller.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { WorkflowsController } from './workflows.controller';
3+
import { ConfigModule } from '@nestjs/config';
4+
import { ChatgptService } from '@app/shared/openapi/chatgpt.service';
5+
import { FirestoreService } from '@app/shared/gcp/firestore.service';
36

47
describe('WorkflowsController', () => {
58
let controller: WorkflowsController;
69

710
beforeEach(async () => {
811
const module: TestingModule = await Test.createTestingModule({
912
controllers: [WorkflowsController],
13+
providers: [ChatgptService, FirestoreService],
14+
imports: [ConfigModule.forRoot({ isGlobal: true })],
1015
}).compile();
1116

1217
controller = module.get<WorkflowsController>(WorkflowsController);

0 commit comments

Comments
 (0)