mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 02:35:58 +08:00
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 -->
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { LinkPreviewServiceIdentifier } from '@blocksuite/affine-shared/services';
|
|
import { isAbortError } from '@blocksuite/affine-shared/utils';
|
|
|
|
import type { BookmarkBlockComponent } from './bookmark-block.js';
|
|
|
|
export async function refreshBookmarkUrlData(
|
|
bookmarkElement: BookmarkBlockComponent,
|
|
signal?: AbortSignal
|
|
) {
|
|
let title = null,
|
|
description = null,
|
|
icon = null,
|
|
image = null;
|
|
|
|
try {
|
|
bookmarkElement.loading = true;
|
|
|
|
const linkPreviewer = bookmarkElement.std.get(LinkPreviewServiceIdentifier);
|
|
const bookmarkUrlData = await linkPreviewer.query(
|
|
bookmarkElement.model.props.url,
|
|
signal
|
|
);
|
|
|
|
title = bookmarkUrlData.title ?? null;
|
|
description = bookmarkUrlData.description ?? null;
|
|
icon = bookmarkUrlData.icon ?? null;
|
|
image = bookmarkUrlData.image ?? null;
|
|
|
|
if (!title && !description && !icon && !image) {
|
|
bookmarkElement.error = true;
|
|
}
|
|
|
|
if (signal?.aborted) return;
|
|
|
|
bookmarkElement.store.updateBlock(bookmarkElement.model, {
|
|
title,
|
|
description,
|
|
icon,
|
|
image,
|
|
});
|
|
} catch (error) {
|
|
if (signal?.aborted || isAbortError(error)) return;
|
|
throw error;
|
|
} finally {
|
|
bookmarkElement.loading = false;
|
|
}
|
|
}
|