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

16
package-lock.json generated
View File

@ -12,7 +12,7 @@
},
"devDependencies": {
"@directus/extensions-sdk": "16.0.2",
"@types/node": "^24.8.1",
"@types/node": "^24.9.1",
"typescript": "^5.9.3",
"vue": "^3.5.22"
}
@ -1917,13 +1917,13 @@
"license": "MIT"
},
"node_modules/@types/node": {
"version": "24.8.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.8.1.tgz",
"integrity": "sha512-alv65KGRadQVfVcG69MuB4IzdYVpRwMG/mq8KWOaoOdyY617P5ivaDiMCGOFDWD2sAn5Q0mR3mRtUOgm99hL9Q==",
"version": "24.9.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.9.1.tgz",
"integrity": "sha512-QoiaXANRkSXK6p0Duvt56W208du4P9Uye9hWLWgGMDTEoKPhuenzNcC4vGUmrNkiOKTlIrBoyNQYNpSwfEZXSg==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~7.14.0"
"undici-types": "~7.16.0"
}
},
"node_modules/@types/nodemailer": {
@ -5405,9 +5405,9 @@
}
},
"node_modules/undici-types": {
"version": "7.14.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.14.0.tgz",
"integrity": "sha512-QQiYxHuyZ9gQUIrmPo3IA+hUl4KYk8uSA7cHrcKd/l3p1OTpZcM0Tbp9x7FAtXdAYhlasd60ncPpgu6ihG6TOA==",
"version": "7.16.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
"dev": true,
"license": "MIT"
},

View File

@ -28,6 +28,11 @@
"type": "hook",
"name": "meilisearch_hook",
"source": "src/meilisearch_hook/index.ts"
},
{
"type": "endpoint",
"name": "meilisearch_endpoint",
"source": "src/meilisearch_endpoint/index.ts"
}
],
"host": "^10.10.0"
@ -43,7 +48,7 @@
"@directus/extensions-sdk": "16.0.2",
"typescript": "^5.9.3",
"vue": "^3.5.22",
"@types/node": "^24.8.1"
"@types/node": "^24.9.1"
},
"dependencies": {
"meilisearch": "^0.53.0"

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