Skip to content

Commit 4fea7fb

Browse files
authored
Merge pull request #194 from import-ai/feat/collect_video
feat(video): Support collect video
2 parents 9f3a758 + 2aa25df commit 4fea7fb

File tree

5 files changed

+66
-12
lines changed

5 files changed

+66
-12
lines changed

src/tasks/wizard-task.service.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ export class WizardTaskService {
6666
);
6767
}
6868

69+
async createGenerateVideoNoteTask(
70+
userId: string,
71+
namespaceId: string,
72+
resourceId: string,
73+
input: { html: string; url: string; title?: string },
74+
repo?: Repository<Task>,
75+
) {
76+
return this.create(
77+
{
78+
function: 'generate_video_note',
79+
input,
80+
namespaceId,
81+
payload: { resource_id: resourceId },
82+
userId,
83+
},
84+
repo,
85+
);
86+
}
87+
6988
async createExtractTagsTask(
7089
userId: string,
7190
resourceId: string,

src/wizard/processors/collect.processor.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('CollectProcessor', () => {
142142
'test-resource-id',
143143
{
144144
namespaceId: 'test-namespace',
145-
content: 'Processing failed',
145+
content: 'error',
146146
},
147147
);
148148
expect(result).toEqual({});

src/wizard/processors/collect.processor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class CollectProcessor extends Processor {
2626
resourceId,
2727
Object.assign(new UpdateResourceDto(), {
2828
namespaceId: task.namespaceId,
29-
content: task.exception.error,
29+
content: 'error',
3030
}),
3131
);
3232
return {};

src/wizard/processors/reader.processor.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ describe('ReaderProcessor', () => {
322322
'test-resource-id',
323323
{
324324
namespaceId: 'test-namespace',
325-
content: 'Processing failed',
325+
content: 'error',
326326
},
327327
);
328328
expect(result).toEqual({});

src/wizard/wizard.service.ts

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class WizardService {
3434
private readonly processors: Record<string, Processor>;
3535
readonly streamService: StreamService;
3636
readonly wizardApiService: WizardAPIService;
37+
private readonly videoPrefixes: string[];
3738

3839
private readonly gzipHtmlFolder: string = 'collect/html/gzip';
3940

@@ -60,6 +61,10 @@ export class WizardService {
6061
this.tagService,
6162
),
6263
generate_title: new GenerateTitleProcessor(namespaceResourcesService),
64+
generate_video_note: new CollectProcessor(
65+
this.namespaceResourcesService,
66+
this.tagService,
67+
),
6368
};
6469
const baseUrl = this.configService.get<string>('OBB_WIZARD_BASE_URL');
6570
if (!baseUrl) {
@@ -71,12 +76,30 @@ export class WizardService {
7176
this.namespaceResourcesService,
7277
);
7378
this.wizardApiService = new WizardAPIService(baseUrl);
79+
const videoPrefixes: string =
80+
this.configService.get<string>('OB_VIDEO_PREFIXES') || '';
81+
if (isEmpty(videoPrefixes)) {
82+
this.videoPrefixes = [];
83+
} else {
84+
this.videoPrefixes = videoPrefixes
85+
.split(',')
86+
.map((prefix) => prefix.trim());
87+
}
7488
}
7589

7690
async create(partialTask: Partial<Task>) {
7791
return await this.wizardTaskService.create(partialTask);
7892
}
7993

94+
isVideoUrl(url: string): boolean {
95+
for (const prefix of this.videoPrefixes) {
96+
if (url.startsWith(prefix)) {
97+
return true;
98+
}
99+
}
100+
return false;
101+
}
102+
80103
async collectZ(
81104
userId: string,
82105
data: CollectZRequestDto,
@@ -113,13 +136,23 @@ export class WizardService {
113136
},
114137
);
115138

116-
const task = await this.wizardTaskService.createCollectTask(
117-
userId,
118-
namespace_id,
119-
resource.id,
120-
{ html: [this.gzipHtmlFolder, id].join('/'), url, title },
121-
);
122-
return { task_id: task.id, resource_id: resource.id };
139+
if (this.isVideoUrl(url)) {
140+
const task = await this.wizardTaskService.createGenerateVideoNoteTask(
141+
userId,
142+
namespace_id,
143+
resource.id,
144+
{ html: [this.gzipHtmlFolder, id].join('/'), url, title },
145+
);
146+
return { task_id: task.id, resource_id: resource.id };
147+
} else {
148+
const task = await this.wizardTaskService.createCollectTask(
149+
userId,
150+
namespace_id,
151+
resource.id,
152+
{ html: [this.gzipHtmlFolder, id].join('/'), url, title },
153+
);
154+
return { task_id: task.id, resource_id: resource.id };
155+
}
123156
}
124157

125158
async collect(
@@ -194,7 +227,9 @@ export class WizardService {
194227

195228
// Trigger extract_tags after collect or file_reader tasks finish
196229
if (
197-
(task.function === 'collect' || task.function === 'file_reader') &&
230+
['collect', 'file_reader', 'generate_video_note'].includes(
231+
task.function,
232+
) &&
198233
!isEmpty(task.output?.markdown) &&
199234
isEmpty(result.tagIds)
200235
) {
@@ -360,7 +395,7 @@ export class WizardService {
360395
const newTask = await this.wizardTaskService.taskRepository.save(task);
361396
// Fetch HTML content from S3 for collect tasks
362397
if (
363-
newTask.function === 'collect' &&
398+
['collect', 'generate_video_note'].includes(newTask.function) &&
364399
newTask.input.html?.startsWith(this.gzipHtmlFolder) &&
365400
newTask.input.html?.length === this.gzipHtmlFolder.length + 36 // 1 + 32 + 3
366401
) {

0 commit comments

Comments
 (0)