mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(core): readwise integration tags setting (#10946)
close AF-2307, AF-2262
This commit is contained in:
@@ -86,6 +86,7 @@ export class ReadwiseIntegration extends Entity<{ writer: IntegrationWriter }> {
|
||||
const updateStrategy = this.readwiseStore.getSetting('updateStrategy');
|
||||
const syncNewHighlights =
|
||||
this.readwiseStore.getSetting('syncNewHighlights');
|
||||
const tags = this.readwiseStore.getSetting('tags');
|
||||
const chunks = chunk(highlights, 2);
|
||||
const total = highlights.length;
|
||||
let finished = 0;
|
||||
@@ -120,6 +121,7 @@ export class ReadwiseIntegration extends Entity<{ writer: IntegrationWriter }> {
|
||||
updateStrategy,
|
||||
integrationId,
|
||||
userId,
|
||||
tags,
|
||||
});
|
||||
}
|
||||
finished++;
|
||||
@@ -144,15 +146,17 @@ export class ReadwiseIntegration extends Entity<{ writer: IntegrationWriter }> {
|
||||
integrationId: string;
|
||||
userId: string;
|
||||
updateStrategy?: ReadwiseConfig['updateStrategy'];
|
||||
tags?: string[];
|
||||
}
|
||||
) {
|
||||
const { updateStrategy, integrationId } = options;
|
||||
const { updateStrategy, integrationId, tags } = options;
|
||||
const { text, ...highlightWithoutText } = highlight;
|
||||
|
||||
const writtenDocId = await this.writer.writeDoc({
|
||||
content: text,
|
||||
title: book.title,
|
||||
docId,
|
||||
tags,
|
||||
comment: highlight.note,
|
||||
updateStrategy: updateStrategy ?? 'append',
|
||||
});
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { MarkdownTransformer } from '@blocksuite/affine/blocks/root';
|
||||
import { Entity } from '@toeverything/infra';
|
||||
|
||||
import type { TagService } from '../../tag';
|
||||
import {
|
||||
getAFFiNEWorkspaceSchema,
|
||||
type WorkspaceService,
|
||||
} from '../../workspace';
|
||||
|
||||
export class IntegrationWriter extends Entity {
|
||||
constructor(private readonly workspaceService: WorkspaceService) {
|
||||
constructor(
|
||||
private readonly workspaceService: WorkspaceService,
|
||||
private readonly tagService: TagService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -32,18 +36,24 @@ export class IntegrationWriter extends Entity {
|
||||
* Update strategy, default is `override`
|
||||
*/
|
||||
updateStrategy?: 'override' | 'append';
|
||||
/**
|
||||
* Tags to apply to the doc
|
||||
*/
|
||||
tags?: string[];
|
||||
}) {
|
||||
const {
|
||||
title,
|
||||
content,
|
||||
comment,
|
||||
docId,
|
||||
tags,
|
||||
updateStrategy = 'override',
|
||||
} = options;
|
||||
|
||||
const workspace = this.workspaceService.workspace;
|
||||
let markdown = comment ? `${content}\n---\n${comment}` : content;
|
||||
|
||||
let finalDocId: string;
|
||||
if (!docId) {
|
||||
const newDocId = await MarkdownTransformer.importMarkdownToDoc({
|
||||
collection: workspace.docCollection,
|
||||
@@ -52,7 +62,8 @@ export class IntegrationWriter extends Entity {
|
||||
fileName: title,
|
||||
});
|
||||
|
||||
return newDocId;
|
||||
if (!newDocId) throw new Error('Failed to create a new doc');
|
||||
finalDocId = newDocId;
|
||||
} else {
|
||||
const collection = workspace.docCollection;
|
||||
|
||||
@@ -88,7 +99,16 @@ export class IntegrationWriter extends Entity {
|
||||
} else {
|
||||
throw new Error('Invalid update strategy');
|
||||
}
|
||||
return doc.id;
|
||||
finalDocId = doc.id;
|
||||
}
|
||||
await this.applyTags(finalDocId, tags);
|
||||
return finalDocId;
|
||||
}
|
||||
|
||||
public async applyTags(docId: string, tags?: string[]) {
|
||||
if (!tags?.length) return;
|
||||
tags.forEach(tag => {
|
||||
this.tagService.tagList.tagByTagId$(tag).value?.tag(docId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { WorkspaceServerService } from '../cloud';
|
||||
import { WorkspaceDBService } from '../db';
|
||||
import { DocScope, DocService, DocsService } from '../doc';
|
||||
import { GlobalState } from '../storage';
|
||||
import { TagService } from '../tag';
|
||||
import { WorkspaceScope, WorkspaceService } from '../workspace';
|
||||
import { ReadwiseIntegration } from './entities/readwise';
|
||||
import { ReadwiseCrawler } from './entities/readwise-crawler';
|
||||
@@ -27,8 +28,8 @@ export function configureIntegrationModule(framework: Framework) {
|
||||
WorkspaceServerService,
|
||||
])
|
||||
.service(IntegrationService)
|
||||
.entity(IntegrationWriter, [WorkspaceService])
|
||||
.entity(ReadwiseCrawler, [ReadwiseStore])
|
||||
.entity(IntegrationWriter, [WorkspaceService, TagService])
|
||||
.entity(ReadwiseIntegration, [
|
||||
IntegrationRefStore,
|
||||
ReadwiseStore,
|
||||
|
||||
@@ -87,6 +87,10 @@ export interface ReadwiseConfig {
|
||||
* The update strategy
|
||||
*/
|
||||
updateStrategy?: 'override' | 'append';
|
||||
/**
|
||||
* Tag id list to be used when creating highlights
|
||||
*/
|
||||
tags?: string[];
|
||||
}
|
||||
// ===============================
|
||||
// Zotero
|
||||
|
||||
Reference in New Issue
Block a user