mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 22:09:08 +08:00
refactor(editor): unify directories naming (#11516)
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import type {
|
||||
EmbedLoomBlockUrlData,
|
||||
EmbedLoomModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { isAbortError } from '@blocksuite/affine-shared/utils';
|
||||
|
||||
import type { EmbedLoomBlockComponent } from './embed-loom-block.js';
|
||||
|
||||
const LoomOEmbedEndpoint = 'https://www.loom.com/v1/oembed';
|
||||
|
||||
export async function queryEmbedLoomData(
|
||||
embedLoomModel: EmbedLoomModel,
|
||||
signal?: AbortSignal
|
||||
): Promise<Partial<EmbedLoomBlockUrlData>> {
|
||||
const url = embedLoomModel.props.url;
|
||||
|
||||
const loomEmbedData: Partial<EmbedLoomBlockUrlData> =
|
||||
await queryLoomOEmbedData(url, signal);
|
||||
|
||||
return loomEmbedData;
|
||||
}
|
||||
|
||||
export async function queryLoomOEmbedData(
|
||||
url: string,
|
||||
signal?: AbortSignal
|
||||
): Promise<Partial<EmbedLoomBlockUrlData>> {
|
||||
let loomOEmbedData: Partial<EmbedLoomBlockUrlData> = {};
|
||||
|
||||
const oEmbedUrl = `${LoomOEmbedEndpoint}?url=${url}`;
|
||||
|
||||
const oEmbedResponse = await fetch(oEmbedUrl, { signal }).catch(() => null);
|
||||
if (oEmbedResponse && oEmbedResponse.ok) {
|
||||
const oEmbedJson = await oEmbedResponse.json();
|
||||
const { title, description, thumbnail_url: image } = oEmbedJson;
|
||||
|
||||
loomOEmbedData = {
|
||||
title,
|
||||
description,
|
||||
image,
|
||||
};
|
||||
}
|
||||
|
||||
return loomOEmbedData;
|
||||
}
|
||||
|
||||
export async function refreshEmbedLoomUrlData(
|
||||
embedLoomElement: EmbedLoomBlockComponent,
|
||||
signal?: AbortSignal
|
||||
): Promise<void> {
|
||||
let title = null,
|
||||
description = null,
|
||||
image = null;
|
||||
|
||||
try {
|
||||
embedLoomElement.loading = true;
|
||||
|
||||
const queryUrlData = embedLoomElement.service?.queryUrlData;
|
||||
if (!queryUrlData) return;
|
||||
|
||||
const loomUrlData = await queryUrlData(embedLoomElement.model);
|
||||
({ title = null, description = null, image = null } = loomUrlData);
|
||||
|
||||
if (signal?.aborted) return;
|
||||
|
||||
embedLoomElement.doc.updateBlock(embedLoomElement.model, {
|
||||
title,
|
||||
description,
|
||||
image,
|
||||
});
|
||||
} catch (error) {
|
||||
if (signal?.aborted || isAbortError(error)) return;
|
||||
} finally {
|
||||
embedLoomElement.loading = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user