[Server] Use logger for logging
This commit is contained in:
parent
d55277e57e
commit
278e43e9ba
3
src/remote/logger.ts
Normal file
3
src/remote/logger.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import Logger from "../misc/logger";
|
||||
|
||||
export const remoteLogger = new Logger('remote', 'blue');
|
@ -4,15 +4,15 @@ import webFinger from './webfinger';
|
||||
import config from '../config';
|
||||
import { createPerson, updatePerson } from './activitypub/models/person';
|
||||
import { URL } from 'url';
|
||||
import * as debug from 'debug';
|
||||
import { remoteLogger } from './logger';
|
||||
|
||||
const log = debug('misskey:remote:resolve-user');
|
||||
const logger = remoteLogger.createSubLogger('resolve-user');
|
||||
|
||||
export default async (username: string, _host: string, option?: any, resync?: boolean): Promise<IUser> => {
|
||||
const usernameLower = username.toLowerCase();
|
||||
|
||||
if (_host == null) {
|
||||
log(`return local user: ${usernameLower}`);
|
||||
logger.info(`return local user: ${usernameLower}`);
|
||||
return await User.findOne({ usernameLower, host: null });
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ export default async (username: string, _host: string, option?: any, resync?: bo
|
||||
const host = toUnicode(hostAscii);
|
||||
|
||||
if (configHost == host) {
|
||||
log(`return local user: ${usernameLower}`);
|
||||
logger.info(`return local user: ${usernameLower}`);
|
||||
return await User.findOne({ usernameLower, host: null });
|
||||
}
|
||||
|
||||
@ -34,18 +34,18 @@ export default async (username: string, _host: string, option?: any, resync?: bo
|
||||
if (user === null) {
|
||||
const self = await resolveSelf(acctLower);
|
||||
|
||||
log(`return new remote user: ${acctLower}`);
|
||||
logger.info(`return new remote user: ${acctLower}`);
|
||||
return await createPerson(self.href);
|
||||
}
|
||||
|
||||
if (resync) {
|
||||
log(`try resync: ${acctLower}`);
|
||||
logger.info(`try resync: ${acctLower}`);
|
||||
const self = await resolveSelf(acctLower);
|
||||
|
||||
if ((user as IRemoteUser).uri !== self.href) {
|
||||
// if uri mismatch, Fix (user@host <=> AP's Person id(IRemoteUser.uri)) mapping.
|
||||
log(`uri missmatch: ${acctLower}`);
|
||||
console.log(`recovery missmatch uri for (username=${username}, host=${host}) from ${(user as IRemoteUser).uri} to ${self.href}`);
|
||||
logger.info(`uri missmatch: ${acctLower}`);
|
||||
logger.info(`recovery missmatch uri for (username=${username}, host=${host}) from ${(user as IRemoteUser).uri} to ${self.href}`);
|
||||
|
||||
// validate uri
|
||||
const uri = new URL(self.href);
|
||||
@ -62,21 +62,21 @@ export default async (username: string, _host: string, option?: any, resync?: bo
|
||||
}
|
||||
});
|
||||
} else {
|
||||
log(`uri is fine: ${acctLower}`);
|
||||
logger.info(`uri is fine: ${acctLower}`);
|
||||
}
|
||||
|
||||
await updatePerson(self.href);
|
||||
|
||||
log(`return resynced remote user: ${acctLower}`);
|
||||
logger.info(`return resynced remote user: ${acctLower}`);
|
||||
return await User.findOne({ uri: self.href });
|
||||
}
|
||||
|
||||
log(`return existing remote user: ${acctLower}`);
|
||||
logger.info(`return existing remote user: ${acctLower}`);
|
||||
return user;
|
||||
};
|
||||
|
||||
async function resolveSelf(acctLower: string) {
|
||||
log(`WebFinger for ${acctLower}`);
|
||||
logger.info(`WebFinger for ${acctLower}`);
|
||||
const finger = await webFinger(acctLower);
|
||||
const self = finger.links.find(link => link.rel && link.rel.toLowerCase() === 'self');
|
||||
if (!self) {
|
||||
|
Loading…
Reference in New Issue
Block a user