mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 05:47:09 +08:00
Closes: [BS-2707](https://linear.app/affine-design/issue/BS-2707/统一使用props获取和更新block-prop)
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { LinkPreviewerService } 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.doc.get(LinkPreviewerService);
|
|
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.doc.updateBlock(bookmarkElement.model, {
|
|
title,
|
|
description,
|
|
icon,
|
|
image,
|
|
});
|
|
} catch (error) {
|
|
if (signal?.aborted || isAbortError(error)) return;
|
|
throw error;
|
|
} finally {
|
|
bookmarkElement.loading = false;
|
|
}
|
|
}
|