Files
AFFiNE-Mirror/blocksuite/affine/blocks/embed/src/embed-github-block/embed-github-service.ts
T
donteatfriedrice 0d518adc5b refactor(editor): add cache extension for link preview service (#12196)
Closes: [BS-2578](https://linear.app/affine-design/issue/BS-2578/优化-footnote-预览的逻辑:支持缓存结果,避免重复-loading)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Introduced a link preview caching mechanism, enabling faster and more efficient reuse of link preview data across the app.
  - Added a feature flag for enabling or disabling link preview cache, configurable through workspace experimental settings.
  - Enhanced localization with new entries describing the link preview cache feature.

- **Improvements**
  - Updated link preview service architecture for better extensibility and maintainability.
  - Improved integration of feature flags throughout chat and rendering components.

- **Bug Fixes**
  - Fixed tooltip formatting for footnote URLs.

- **Chores**
  - Updated dependencies and localization completeness tracking.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-13 05:11:34 +00:00

37 lines
1.1 KiB
TypeScript

import {
EmbedGithubBlockSchema,
type EmbedGithubModel,
EmbedGithubStyles,
} from '@blocksuite/affine-model';
import {
EmbedOptionConfig,
LinkPreviewServiceIdentifier,
} from '@blocksuite/affine-shared/services';
import { BlockService } from '@blocksuite/std';
import { githubUrlRegex } from './embed-github-model.js';
import { queryEmbedGithubApiData, queryEmbedGithubData } from './utils.js';
export class EmbedGithubBlockService extends BlockService {
static override readonly flavour = EmbedGithubBlockSchema.model.flavour;
queryApiData = (embedGithubModel: EmbedGithubModel, signal?: AbortSignal) => {
return queryEmbedGithubApiData(embedGithubModel, signal);
};
queryUrlData = (embedGithubModel: EmbedGithubModel, signal?: AbortSignal) => {
return queryEmbedGithubData(
embedGithubModel,
this.std.get(LinkPreviewServiceIdentifier),
signal
);
};
}
export const EmbedGithubBlockOptionConfig = EmbedOptionConfig({
flavour: EmbedGithubBlockSchema.model.flavour,
urlRegex: githubUrlRegex,
styles: EmbedGithubStyles,
viewType: 'card',
});