mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat: isolated plugin system (#2742)
This commit is contained in:
@@ -19,6 +19,7 @@ definePlugin(
|
||||
},
|
||||
stage: ReleaseStage.NIGHTLY,
|
||||
version: '0.0.1',
|
||||
commands: ['com.blocksuite.bookmark-block.get-bookmark-data-by-link'],
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
@@ -28,5 +29,19 @@ definePlugin(
|
||||
import.meta.webpackHot.accept('./blocksuite', () =>
|
||||
onHot(import('./blocksuite/index'))
|
||||
),
|
||||
},
|
||||
{
|
||||
load: () =>
|
||||
import(
|
||||
/* webpackIgnore: true */
|
||||
'./server'
|
||||
),
|
||||
hotModuleReload: onHot =>
|
||||
onHot(
|
||||
import(
|
||||
/* webpackIgnore: true */
|
||||
'./server'
|
||||
)
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { ServerAdapter } from '@toeverything/plugin-infra/type';
|
||||
import { getLinkPreview } from 'link-preview-js';
|
||||
|
||||
type MetaData = {
|
||||
@@ -26,31 +27,41 @@ export interface PreviewType {
|
||||
favicons: string[];
|
||||
}
|
||||
|
||||
export default {
|
||||
getBookmarkDataByLink: async (_: unknown, url: string): Promise<MetaData> => {
|
||||
const previewData = (await getLinkPreview(url, {
|
||||
timeout: 6000,
|
||||
headers: {
|
||||
'user-agent': 'googlebot',
|
||||
},
|
||||
followRedirects: 'follow',
|
||||
}).catch(() => {
|
||||
return {
|
||||
title: '',
|
||||
siteName: '',
|
||||
description: '',
|
||||
images: [],
|
||||
videos: [],
|
||||
contentType: `text/html`,
|
||||
favicons: [],
|
||||
};
|
||||
})) as PreviewType;
|
||||
const adapter: ServerAdapter = affine => {
|
||||
affine.registerCommand(
|
||||
'com.blocksuite.bookmark-block.get-bookmark-data-by-link',
|
||||
async (url: string): Promise<MetaData> => {
|
||||
const previewData = (await getLinkPreview(url, {
|
||||
timeout: 6000,
|
||||
headers: {
|
||||
'user-agent': 'googlebot',
|
||||
},
|
||||
followRedirects: 'follow',
|
||||
}).catch(() => {
|
||||
return {
|
||||
title: '',
|
||||
siteName: '',
|
||||
description: '',
|
||||
images: [],
|
||||
videos: [],
|
||||
contentType: `text/html`,
|
||||
favicons: [],
|
||||
};
|
||||
})) as PreviewType;
|
||||
|
||||
return {
|
||||
title: previewData.title,
|
||||
description: previewData.description,
|
||||
icon: previewData.favicons[0],
|
||||
image: previewData.images[0],
|
||||
};
|
||||
},
|
||||
return {
|
||||
title: previewData.title,
|
||||
description: previewData.description,
|
||||
icon: previewData.favicons[0],
|
||||
image: previewData.images[0],
|
||||
};
|
||||
}
|
||||
);
|
||||
return () => {
|
||||
affine.unregisterCommand(
|
||||
'com.blocksuite.bookmark-block.get-bookmark-data-by-link'
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default adapter;
|
||||
|
||||
Reference in New Issue
Block a user