Skip to content

Commit 9fa543b

Browse files
authored
Merge pull request #214 from import-ai/chore/tags
chore(tags): Support skip parsing tags from content in open api
2 parents 3f91ee6 + ba56331 commit 9fa543b

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/namespace-resources/dto/open.create-resource.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
IsObject,
55
IsOptional,
66
IsNotEmpty,
7+
IsBoolean,
78
} from 'class-validator';
89

910
export class OpenCreateResourceDto {
@@ -23,4 +24,8 @@ export class OpenCreateResourceDto {
2324
@IsObject()
2425
@IsOptional()
2526
attrs?: Record<string, any>;
27+
28+
@IsBoolean()
29+
@IsOptional()
30+
skip_parsing_tags_from_content?: boolean;
2631
}

src/namespace-resources/open.resource.controller.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,19 @@ export class OpenResourcesController {
5757
);
5858
}
5959

60-
// Parse hashtags from content
61-
const hashtagNames = parseHashtags(data.content);
62-
let tagIds: string[] = data.tag_ids || [];
63-
64-
// If hashtags found, get or create tags and merge with provided tag_ids
65-
if (hashtagNames.length > 0) {
66-
const hashtagIds = await this.tagService.getOrCreateTagsByNames(
67-
apiKey.namespaceId,
68-
hashtagNames,
69-
);
70-
// Merge and deduplicate tag IDs
71-
tagIds = Array.from(new Set([...tagIds, ...hashtagIds]));
60+
// Optionally parse hashtags from content
61+
let tagIds: string[] | undefined = data.tag_ids;
62+
if (!data.skip_parsing_tags_from_content) {
63+
const hashtagNames = parseHashtags(data.content);
64+
// If hashtags found, get or create tags and merge with provided tag_ids
65+
if (hashtagNames.length > 0) {
66+
const hashtagIds = await this.tagService.getOrCreateTagsByNames(
67+
apiKey.namespaceId,
68+
hashtagNames,
69+
);
70+
// Merge and deduplicate tag IDs
71+
tagIds = Array.from(new Set([...(tagIds || []), ...hashtagIds]));
72+
}
7273
}
7374

7475
const createResourceDto = {
@@ -95,8 +96,8 @@ export class OpenResourcesController {
9596
{ text: data.content },
9697
);
9798
}
98-
// Skip extract tags task if we already have tags from hashtags or user input
99-
if (isEmpty(newResource.tagIds)) {
99+
// Skip extract tags task if user requested or we already have tags
100+
if (!data.skip_parsing_tags_from_content && isEmpty(newResource.tagIds)) {
100101
await this.wizardTaskService.createExtractTagsTask(
101102
userId,
102103
newResource.id,

0 commit comments

Comments
 (0)