File tree Expand file tree Collapse file tree 3 files changed +45
-9
lines changed Expand file tree Collapse file tree 3 files changed +45
-9
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import { FileInterceptor } from '@nestjs/platform-express';
1818import { UserId } from 'omniboxd/decorators/user-id.decorator' ;
1919import { OpenCreateResourceDto } from 'omniboxd/namespace-resources/dto/open.create-resource.dto' ;
2020import { ResourceType } from 'omniboxd/resources/entities/resource.entity' ;
21+ import { isEmpty } from 'omniboxd/utils/is-empty' ;
2122
2223@Controller ( 'open/api/v1/resources' )
2324export class OpenResourcesController {
@@ -59,13 +60,23 @@ export class OpenResourcesController {
5960 resourceData ,
6061 ) ;
6162
62- if ( ! newResource . name || newResource . name . trim ( ) === '' ) {
63- await this . wizardTaskService . createGenerateTitleTask (
64- userId ,
65- apiKey . namespaceId ,
66- { resource_id : newResource . id } ,
67- { text : data . content } ,
68- ) ;
63+ if ( ! isEmpty ( newResource . content ?. trim ( ) ) ) {
64+ if ( isEmpty ( newResource . name ?. trim ( ) ) ) {
65+ await this . wizardTaskService . createGenerateTitleTask (
66+ userId ,
67+ apiKey . namespaceId ,
68+ { resource_id : newResource . id } ,
69+ { text : data . content } ,
70+ ) ;
71+ }
72+ if ( isEmpty ( newResource . tagIds ) ) {
73+ await this . wizardTaskService . createExtractTagsTask (
74+ userId ,
75+ newResource . id ,
76+ apiKey . namespaceId ,
77+ newResource . content ,
78+ ) ;
79+ }
6980 }
7081
7182 return { id : newResource . id , name : newResource . name } ;
Original file line number Diff line number Diff line change @@ -66,7 +66,32 @@ export class WizardTaskService {
6666 ) ;
6767 }
6868
69- async createExtractTagsTask ( parentTask : Task , repo ?: Repository < Task > ) {
69+ async createExtractTagsTask (
70+ userId : string ,
71+ resourceId : string ,
72+ namespaceId : string ,
73+ text : string ,
74+ repo ?: Repository < Task > ,
75+ ) {
76+ const lang = await this . getUserLanguage ( userId ) ;
77+ return this . create (
78+ {
79+ function : 'extract_tags' ,
80+ input : { text, lang } ,
81+ namespaceId,
82+ payload : {
83+ resource_id : resourceId ,
84+ } ,
85+ userId,
86+ } ,
87+ repo ,
88+ ) ;
89+ }
90+
91+ async createExtractTagsTaskFromTask (
92+ parentTask : Task ,
93+ repo ?: Repository < Task > ,
94+ ) {
7095 const lang = await this . getUserLanguage ( parentTask . userId ) ;
7196 return this . create (
7297 {
Original file line number Diff line number Diff line change @@ -216,7 +216,7 @@ export class WizardService {
216216 private async triggerExtractTags ( parentTask : Task ) : Promise < void > {
217217 try {
218218 const extractTagsTask =
219- await this . wizardTaskService . createExtractTagsTask ( parentTask ) ;
219+ await this . wizardTaskService . createExtractTagsTaskFromTask ( parentTask ) ;
220220
221221 this . logger . debug (
222222 `Triggered extract_tags task ${ extractTagsTask . id } for parent task ${ parentTask . id } ` ,
You can’t perform that action at this time.
0 commit comments