feat: 添加meilisearch endpoint

- 增添路由/meilisearch/collections用于获取所有可见集合
This commit is contained in:
2025-10-21 07:21:24 +00:00
parent b0d275037b
commit 7d05acdd23
3 changed files with 41 additions and 9 deletions

View 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);
})
}
});