mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
4.6.4 (#588)
This commit is contained in:
15
packages/service/common/system/config/controller.ts
Normal file
15
packages/service/common/system/config/controller.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { SystemConfigsTypeEnum } from '@fastgpt/global/common/system/config/constants';
|
||||
import { MongoSystemConfigs } from './schema';
|
||||
import { FeConfigsType } from '@fastgpt/global/common/system/types';
|
||||
|
||||
export const getFastGPTFeConfig = async () => {
|
||||
const res = await MongoSystemConfigs.findOne({
|
||||
type: SystemConfigsTypeEnum.fastgpt
|
||||
}).sort({
|
||||
createTime: -1
|
||||
});
|
||||
|
||||
const config: FeConfigsType = res?.value?.FeConfig || {};
|
||||
|
||||
return config;
|
||||
};
|
@@ -19,14 +19,15 @@ const systemConfigSchema = new Schema({
|
||||
type: Date,
|
||||
default: () => new Date()
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
try {
|
||||
systemConfigSchema.index({ createTime: -1 }, { expireAfterSeconds: 90 * 24 * 60 * 60 });
|
||||
systemConfigSchema.index({ type: 1 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
export const MongoSystemConfigs: Model<SystemConfigsType>=
|
||||
export const MongoSystemConfigs: Model<SystemConfigsType> =
|
||||
models[collectionName] || model(collectionName, systemConfigSchema);
|
||||
MongoSystemConfigs.syncIndexes();
|
||||
MongoSystemConfigs.syncIndexes();
|
||||
|
66
packages/service/common/system/log.ts
Normal file
66
packages/service/common/system/log.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
/* add logger */
|
||||
export const addLog = {
|
||||
log(level: 'info' | 'warn' | 'error', msg: string, obj: Record<string, any> = {}) {
|
||||
console.log(
|
||||
`[${level.toLocaleUpperCase()}] ${dayjs().format(
|
||||
'YYYY-MM-DD HH:mm:ss'
|
||||
)} ${msg}: ${JSON.stringify(obj)}`
|
||||
);
|
||||
|
||||
const lokiUrl = process.env.LOKI_LOG_URL as string;
|
||||
if (!lokiUrl) return;
|
||||
|
||||
try {
|
||||
fetch(lokiUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
streams: [
|
||||
{
|
||||
stream: {
|
||||
level
|
||||
},
|
||||
values: [
|
||||
[
|
||||
`${Date.now() * 1000000}`,
|
||||
JSON.stringify({
|
||||
message: msg,
|
||||
...obj
|
||||
})
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
});
|
||||
} catch (error) {}
|
||||
},
|
||||
info(msg: string, obj?: Record<string, any>) {
|
||||
this.log('info', msg, obj);
|
||||
},
|
||||
warn(msg: string, obj?: Record<string, any>) {
|
||||
this.log('warn', msg, obj);
|
||||
},
|
||||
error(msg: string, error?: any) {
|
||||
this.log('error', msg, {
|
||||
stack: error?.stack,
|
||||
...(error?.config && {
|
||||
config: {
|
||||
headers: error.config.headers,
|
||||
url: error.config.url,
|
||||
data: error.config.data
|
||||
}
|
||||
}),
|
||||
...(error?.response && {
|
||||
response: {
|
||||
status: error.response.status,
|
||||
statusText: error.response.statusText
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user