feat: 添加meilisearch endpoint
- 增添路由/meilisearch/collections用于获取所有可见集合
This commit is contained in:
16
package-lock.json
generated
16
package-lock.json
generated
@ -12,7 +12,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@directus/extensions-sdk": "16.0.2",
|
"@directus/extensions-sdk": "16.0.2",
|
||||||
"@types/node": "^24.8.1",
|
"@types/node": "^24.9.1",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"vue": "^3.5.22"
|
"vue": "^3.5.22"
|
||||||
}
|
}
|
||||||
@ -1917,13 +1917,13 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "24.8.1",
|
"version": "24.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.9.1.tgz",
|
||||||
"integrity": "sha512-alv65KGRadQVfVcG69MuB4IzdYVpRwMG/mq8KWOaoOdyY617P5ivaDiMCGOFDWD2sAn5Q0mR3mRtUOgm99hL9Q==",
|
"integrity": "sha512-QoiaXANRkSXK6p0Duvt56W208du4P9Uye9hWLWgGMDTEoKPhuenzNcC4vGUmrNkiOKTlIrBoyNQYNpSwfEZXSg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~7.14.0"
|
"undici-types": "~7.16.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/nodemailer": {
|
"node_modules/@types/nodemailer": {
|
||||||
@ -5405,9 +5405,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici-types": {
|
"node_modules/undici-types": {
|
||||||
"version": "7.14.0",
|
"version": "7.16.0",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.14.0.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
||||||
"integrity": "sha512-QQiYxHuyZ9gQUIrmPo3IA+hUl4KYk8uSA7cHrcKd/l3p1OTpZcM0Tbp9x7FAtXdAYhlasd60ncPpgu6ihG6TOA==",
|
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -28,6 +28,11 @@
|
|||||||
"type": "hook",
|
"type": "hook",
|
||||||
"name": "meilisearch_hook",
|
"name": "meilisearch_hook",
|
||||||
"source": "src/meilisearch_hook/index.ts"
|
"source": "src/meilisearch_hook/index.ts"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "endpoint",
|
||||||
|
"name": "meilisearch_endpoint",
|
||||||
|
"source": "src/meilisearch_endpoint/index.ts"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"host": "^10.10.0"
|
"host": "^10.10.0"
|
||||||
@ -43,7 +48,7 @@
|
|||||||
"@directus/extensions-sdk": "16.0.2",
|
"@directus/extensions-sdk": "16.0.2",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"vue": "^3.5.22",
|
"vue": "^3.5.22",
|
||||||
"@types/node": "^24.8.1"
|
"@types/node": "^24.9.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"meilisearch": "^0.53.0"
|
"meilisearch": "^0.53.0"
|
||||||
|
|||||||
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