feat: 添加meilisearch endpoint
- 增添路由/meilisearch/collections用于获取所有可见集合
This commit is contained in:
27
src/meilisearch_endpoint/index.ts
Normal file
27
src/meilisearch_endpoint/index.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { defineEndpoint } from '@directus/extensions-sdk';
|
||||
|
||||
export default defineEndpoint({
|
||||
id: 'meilisearch',
|
||||
handler: (router, context) => {
|
||||
router.get('/', (_req, res) => res.send('Hello, World!'));
|
||||
router.get('/collections', async (_req, res) => {
|
||||
const { services, getSchema } = context;
|
||||
const { CollectionsService } = services;
|
||||
const schema = await getSchema();
|
||||
const collSvc = new CollectionsService({
|
||||
schema,
|
||||
})
|
||||
const collections = await collSvc.readByQuery();
|
||||
|
||||
const visible = collections.filter(col => !col.meta?.hidden && !col.meta?.system && col.schema);
|
||||
|
||||
const result = visible.map(col => ({
|
||||
collection: col.collection,
|
||||
note: col.meta?.note || '',
|
||||
icon: col.meta?.icon || '',
|
||||
}));
|
||||
|
||||
res.json(result);
|
||||
})
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user