Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/namespace-resources/dto/open.create-resource.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IsObject,
IsOptional,
IsNotEmpty,
IsBoolean,
} from 'class-validator';

export class OpenCreateResourceDto {
Expand All @@ -23,4 +24,8 @@ export class OpenCreateResourceDto {
@IsObject()
@IsOptional()
attrs?: Record<string, any>;

@IsBoolean()
@IsOptional()
skip_parsing_tags_from_content?: boolean;
}
29 changes: 15 additions & 14 deletions src/namespace-resources/open.resource.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ export class OpenResourcesController {
);
}

// Parse hashtags from content
const hashtagNames = parseHashtags(data.content);
let tagIds: string[] = data.tag_ids || [];

// If hashtags found, get or create tags and merge with provided tag_ids
if (hashtagNames.length > 0) {
const hashtagIds = await this.tagService.getOrCreateTagsByNames(
apiKey.namespaceId,
hashtagNames,
);
// Merge and deduplicate tag IDs
tagIds = Array.from(new Set([...tagIds, ...hashtagIds]));
// Optionally parse hashtags from content
let tagIds: string[] | undefined = data.tag_ids;
if (!data.skip_parsing_tags_from_content) {
const hashtagNames = parseHashtags(data.content);
// If hashtags found, get or create tags and merge with provided tag_ids
if (hashtagNames.length > 0) {
const hashtagIds = await this.tagService.getOrCreateTagsByNames(
apiKey.namespaceId,
hashtagNames,
);
// Merge and deduplicate tag IDs
tagIds = Array.from(new Set([...(tagIds || []), ...hashtagIds]));
}
}

const createResourceDto = {
Expand All @@ -95,8 +96,8 @@ export class OpenResourcesController {
{ text: data.content },
);
}
// Skip extract tags task if we already have tags from hashtags or user input
if (isEmpty(newResource.tagIds)) {
// Skip extract tags task if user requested or we already have tags
if (!data.skip_parsing_tags_from_content && isEmpty(newResource.tagIds)) {
await this.wizardTaskService.createExtractTagsTask(
userId,
newResource.id,
Expand Down