feat(log): 将meilisearch_hook的日志输出由console改为consola
This commit is contained in:
@ -1,8 +1,11 @@
|
|||||||
import { defineHook } from '@directus/extensions-sdk';
|
import { defineHook } from '@directus/extensions-sdk';
|
||||||
|
import { createLogger } from '../logger';
|
||||||
|
|
||||||
|
const logger = createLogger('meilisearch_hook');
|
||||||
|
|
||||||
export default defineHook(async ({ init, filter, action }, { services, getSchema }) => {
|
export default defineHook(async ({ init, filter, action }, { services, getSchema }) => {
|
||||||
init('app.after', async () => {
|
init('app.after', async () => {
|
||||||
console.log('Directus App Started - MeiliSearch Hook Initialized');
|
logger.info('Directus App Started - MeiliSearch Hook Initialized');
|
||||||
const { CollectionsService } = services;
|
const { CollectionsService } = services;
|
||||||
const schema = await getSchema();
|
const schema = await getSchema();
|
||||||
const collectionsSvc = new CollectionsService({
|
const collectionsSvc = new CollectionsService({
|
||||||
@ -12,7 +15,7 @@ export default defineHook(async ({ init, filter, action }, { services, getSchema
|
|||||||
// 检查meili_search_config集合是否存在
|
// 检查meili_search_config集合是否存在
|
||||||
const meili_search_config_exists = await collectionsSvc.readOne('meili_search_config').then(() => true).catch(() => false);
|
const meili_search_config_exists = await collectionsSvc.readOne('meili_search_config').then(() => true).catch(() => false);
|
||||||
if (!meili_search_config_exists) {
|
if (!meili_search_config_exists) {
|
||||||
console.warn('collection meili_search_config does not exist, creating...');
|
logger.warn('collection meili_search_config does not exist, creating...');
|
||||||
await collectionsSvc.createOne({
|
await collectionsSvc.createOne({
|
||||||
collection: 'meili_search_config',
|
collection: 'meili_search_config',
|
||||||
meta: {
|
meta: {
|
||||||
@ -29,18 +32,18 @@ export default defineHook(async ({ init, filter, action }, { services, getSchema
|
|||||||
{ field: 'api_key', type: 'string', meta: { note: 'MeiliSearch API Key', interface: 'input' } },
|
{ field: 'api_key', type: 'string', meta: { note: 'MeiliSearch API Key', interface: 'input' } },
|
||||||
],
|
],
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log('meili_search_config collection created successfully.');
|
logger.info('meili_search_config collection created successfully.');
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error('Error creating meili_search_config collection:', e);
|
logger.error('Error creating meili_search_config collection:', e);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('meili_index_config collection already exists.');
|
logger.info('meili_index_config collection already exists.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查meili_index_configs集合是否存在
|
// 检查meili_index_configs集合是否存在
|
||||||
const meili_index_configs_exists = await collectionsSvc.readOne('meili_index_configs').then(() => true).catch(() => false);
|
const meili_index_configs_exists = await collectionsSvc.readOne('meili_index_configs').then(() => true).catch(() => false);
|
||||||
if (!meili_index_configs_exists) {
|
if (!meili_index_configs_exists) {
|
||||||
console.warn('collection meili_index_configs does not exist, creating...');
|
logger.warn('collection meili_index_configs does not exist, creating...');
|
||||||
await collectionsSvc.createOne({
|
await collectionsSvc.createOne({
|
||||||
collection: 'meili_index_configs',
|
collection: 'meili_index_configs',
|
||||||
meta: {
|
meta: {
|
||||||
@ -60,20 +63,20 @@ export default defineHook(async ({ init, filter, action }, { services, getSchema
|
|||||||
{ field: 'settings', type: 'json', meta: { note: 'MeiliSearch 索引设置', interface: 'code-editor' } },
|
{ field: 'settings', type: 'json', meta: { note: 'MeiliSearch 索引设置', interface: 'code-editor' } },
|
||||||
],
|
],
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log('meili_index_configs collection created successfully.');
|
logger.info('meili_index_configs collection created successfully.');
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error('Error creating meili_index_configs collection:', e);
|
logger.error('Error creating meili_index_configs collection:', e);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('meili_index_configs collection already exists.');
|
logger.info('meili_index_configs collection already exists.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
filter('items.create', () => {
|
filter('items.create', () => {
|
||||||
console.log('Creating Item!');
|
logger.info('Creating Item!');
|
||||||
});
|
});
|
||||||
|
|
||||||
action('items.create', () => {
|
action('items.create', () => {
|
||||||
console.log('Item created!');
|
logger.info('Item created!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user