forked from ppfun/pixelplanet
add functions to map uuids to ip and names to id
This commit is contained in:
parent
e9a7ea7262
commit
7ef311cdc7
|
@ -7,6 +7,8 @@
|
|||
import { createLogger, format, transports } from 'winston';
|
||||
import DailyRotateFile from 'winston-daily-rotate-file';
|
||||
|
||||
export const PIXELLOGGER_PREFIX = './log/pixels-';
|
||||
|
||||
const logger = createLogger({
|
||||
level: 'info',
|
||||
format: format.combine(
|
||||
|
@ -22,7 +24,7 @@ export const pixelLogger = createLogger({
|
|||
format: format.printf(({ message }) => message),
|
||||
transports: [
|
||||
new DailyRotateFile({
|
||||
filename: './log/pixels-%DATE%.log',
|
||||
filename: `${PIXELLOGGER_PREFIX}%DATE%.log`,
|
||||
maxFiles: '14d',
|
||||
utc: true,
|
||||
colorize: false,
|
||||
|
|
|
@ -87,4 +87,19 @@ const IPInfo = sequelize.define('IPInfo', {
|
|||
},
|
||||
});
|
||||
|
||||
export async function getIdsToIps(ips) {
|
||||
const result = IPInfo.findAll({
|
||||
attributes: ['ip', 'uuid'],
|
||||
where: {
|
||||
ip: ips,
|
||||
},
|
||||
raw: true,
|
||||
});
|
||||
const ipToIdMap = {};
|
||||
result.forEach((obj) => {
|
||||
ipToIdMap[obj.ip] = obj.uuid;
|
||||
});
|
||||
return ipToIdMap;
|
||||
}
|
||||
|
||||
export default IPInfo;
|
||||
|
|
|
@ -181,4 +181,19 @@ export async function findIdByNameOrId(searchString) {
|
|||
return null;
|
||||
}
|
||||
|
||||
export async function getNamesToIds(ids) {
|
||||
const result = RegUser.findAll({
|
||||
attributes: ['id', 'name'],
|
||||
where: {
|
||||
id: ids,
|
||||
},
|
||||
raw: true,
|
||||
});
|
||||
const idToNameMap = {};
|
||||
result.forEach((obj) => {
|
||||
idToNameMap[obj.id] = obj.name;
|
||||
});
|
||||
return idToNameMap;
|
||||
}
|
||||
|
||||
export default RegUser;
|
||||
|
|
Loading…
Reference in New Issue
Block a user