Formatting
This commit is contained in:
parent
845dfc3838
commit
9894b203c9
4 changed files with 73 additions and 73 deletions
|
@ -18,62 +18,62 @@ const ev = new Xev();
|
||||||
* Init process
|
* Init process
|
||||||
*/
|
*/
|
||||||
export default async function() {
|
export default async function() {
|
||||||
process.title = `Calckey (${cluster.isPrimary ? 'master' : 'worker'})`;
|
process.title = `Calckey (${cluster.isPrimary ? 'master' : 'worker'})`;
|
||||||
|
|
||||||
if (cluster.isPrimary || envOption.disableClustering) {
|
if (cluster.isPrimary || envOption.disableClustering) {
|
||||||
await masterMain();
|
await masterMain();
|
||||||
|
|
||||||
if (cluster.isPrimary) {
|
if (cluster.isPrimary) {
|
||||||
ev.mount();
|
ev.mount();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cluster.isWorker || envOption.disableClustering) {
|
|
||||||
await workerMain();
|
|
||||||
}
|
|
||||||
|
|
||||||
// For when Calckey is started in a child process during unit testing.
|
|
||||||
// Otherwise, process.send cannot be used, so start it.
|
|
||||||
if (process.send) {
|
|
||||||
process.send('ok');
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cluster.isWorker || envOption.disableClustering) {
|
||||||
|
await workerMain();
|
||||||
|
}
|
||||||
|
|
||||||
|
// For when Calckey is started in a child process during unit testing.
|
||||||
|
// Otherwise, process.send cannot be used, so start it.
|
||||||
|
if (process.send) {
|
||||||
|
process.send('ok');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#region Events
|
//#region Events
|
||||||
|
|
||||||
// Listen new workers
|
// Listen new workers
|
||||||
cluster.on('fork', worker => {
|
cluster.on('fork', worker => {
|
||||||
clusterLogger.debug(`Process forked: [${worker.id}]`);
|
clusterLogger.debug(`Process forked: [${worker.id}]`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen online workers
|
// Listen online workers
|
||||||
cluster.on('online', worker => {
|
cluster.on('online', worker => {
|
||||||
clusterLogger.debug(`Process is now online: [${worker.id}]`);
|
clusterLogger.debug(`Process is now online: [${worker.id}]`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen for dying workers
|
// Listen for dying workers
|
||||||
cluster.on('exit', worker => {
|
cluster.on('exit', worker => {
|
||||||
// Replace the dead worker,
|
// Replace the dead worker,
|
||||||
// we're not sentimental
|
// we're not sentimental
|
||||||
clusterLogger.error(chalk.red(`[${worker.id}] died :(`));
|
clusterLogger.error(chalk.red(`[${worker.id}] died :(`));
|
||||||
cluster.fork();
|
cluster.fork();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Display detail of unhandled promise rejection
|
// Display detail of unhandled promise rejection
|
||||||
if (!envOption.quiet) {
|
if (!envOption.quiet) {
|
||||||
process.on('unhandledRejection', console.dir);
|
process.on('unhandledRejection', console.dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display detail of uncaught exception
|
// Display detail of uncaught exception
|
||||||
process.on('uncaughtException', err => {
|
process.on('uncaughtException', err => {
|
||||||
try {
|
try {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
} catch { }
|
} catch { }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Dying away...
|
// Dying away...
|
||||||
process.on('exit', code => {
|
process.on('exit', code => {
|
||||||
logger.info(`The process is going to exit with code ${code}`);
|
logger.info(`The process is going to exit with code ${code}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
|
@ -8,44 +8,44 @@ import { deleteActor } from './actor.js';
|
||||||
* Handle delete activity
|
* Handle delete activity
|
||||||
*/
|
*/
|
||||||
export default async (actor: CacheableRemoteUser, activity: IDelete): Promise<string> => {
|
export default async (actor: CacheableRemoteUser, activity: IDelete): Promise<string> => {
|
||||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||||
throw new Error('invalid actor');
|
throw new Error('invalid actor');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type of object to be deleted
|
// Type of object to be deleted
|
||||||
let formerType: string | undefined;
|
let formerType: string | undefined;
|
||||||
|
|
||||||
if (typeof activity.object === 'string') {
|
if (typeof activity.object === 'string') {
|
||||||
// The type is unknown, but it has disappeared
|
// The type is unknown, but it has disappeared
|
||||||
// anyway, so it does not remote resolve
|
// anyway, so it does not remote resolve
|
||||||
formerType = undefined;
|
formerType = undefined;
|
||||||
} else {
|
} else {
|
||||||
const object = activity.object as IObject;
|
const object = activity.object as IObject;
|
||||||
if (isTombstone(object)) {
|
if (isTombstone(object)) {
|
||||||
formerType = toSingle(object.formerType);
|
formerType = toSingle(object.formerType);
|
||||||
} else {
|
} else {
|
||||||
formerType = toSingle(object.type);
|
formerType = toSingle(object.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uri = getApId(activity.object);
|
const uri = getApId(activity.object);
|
||||||
|
|
||||||
// Even if type is unknown, if actor and object are the same,
|
// Even if type is unknown, if actor and object are the same,
|
||||||
// it must be `Person`.
|
// it must be `Person`.
|
||||||
if (!formerType && actor.uri === uri) {
|
if (!formerType && actor.uri === uri) {
|
||||||
formerType = 'Person';
|
formerType = 'Person';
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not, fallback to `Note`.
|
// If not, fallback to `Note`.
|
||||||
if (!formerType) {
|
if (!formerType) {
|
||||||
formerType = 'Note';
|
formerType = 'Note';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validPost.includes(formerType)) {
|
if (validPost.includes(formerType)) {
|
||||||
return await deleteNote(actor, uri);
|
return await deleteNote(actor, uri);
|
||||||
} else if (validActor.includes(formerType)) {
|
} else if (validActor.includes(formerType)) {
|
||||||
return await deleteActor(actor, uri);
|
return await deleteActor(actor, uri);
|
||||||
} else {
|
} else {
|
||||||
return `Unknown type ${formerType}`;
|
return `Unknown type ${formerType}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,11 +55,11 @@ export async function createImage(actor: CacheableRemoteUser, value: any): Promi
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve Image.
|
* Resolve Image.
|
||||||
*
|
*
|
||||||
* If the target Image is registered in Calckey, return it, otherwise
|
* If the target Image is registered in Calckey, return it, otherwise
|
||||||
* Fetch from remote server, register with Calckey and return it.
|
* Fetch from remote server, register with Calckey and return it.
|
||||||
*/
|
*/
|
||||||
export async function resolveImage(actor: CacheableRemoteUser, value: any): Promise<DriveFile> {
|
export async function resolveImage(actor: CacheableRemoteUser, value: any): Promise<DriveFile> {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
|
|
|
@ -53,10 +53,10 @@ export function validateNote(object: any, uri: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch Notes.
|
* Fetch Notes.
|
||||||
*
|
*
|
||||||
* If the target Note is registered in Calckey, it will be returned.
|
* If the target Note is registered in Calckey, it will be returned.
|
||||||
*/
|
*/
|
||||||
export async function fetchNote(object: string | IObject): Promise<Note | null> {
|
export async function fetchNote(object: string | IObject): Promise<Note | null> {
|
||||||
const dbResolver = new DbResolver();
|
const dbResolver = new DbResolver();
|
||||||
return await dbResolver.getNoteFromApId(object);
|
return await dbResolver.getNoteFromApId(object);
|
||||||
|
@ -265,11 +265,11 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve Note.
|
* Resolve Note.
|
||||||
*
|
*
|
||||||
* If the target Note is registered in Calckey, return it, otherwise
|
* If the target Note is registered in Calckey, return it, otherwise
|
||||||
* Fetch from remote server, register with Calckey and return it.
|
* Fetch from remote server, register with Calckey and return it.
|
||||||
*/
|
*/
|
||||||
export async function resolveNote(value: string | IObject, resolver?: Resolver): Promise<Note | null> {
|
export async function resolveNote(value: string | IObject, resolver?: Resolver): Promise<Note | null> {
|
||||||
const uri = typeof value === 'string' ? value : value.id;
|
const uri = typeof value === 'string' ? value : value.id;
|
||||||
if (uri == null) throw new Error('missing uri');
|
if (uri == null) throw new Error('missing uri');
|
||||||
|
|
Loading…
Reference in a new issue