mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-10 15:05:19 +00:00
Log elapsed time for user delete
This commit is contained in:
@@ -17,7 +17,21 @@
|
||||
*/
|
||||
|
||||
import { route } from "@spacebar/api";
|
||||
import { Channel, ChannelDeleteEvent, ChannelRecipientRemoveEvent, emitEvent, Emoji, Guild, InstanceBan, Member, Recipient, Sticker, User, UserDeleteEvent } from "@spacebar/util";
|
||||
import {
|
||||
Channel,
|
||||
ChannelDeleteEvent,
|
||||
ChannelRecipientRemoveEvent,
|
||||
emitEvent,
|
||||
Emoji,
|
||||
Guild,
|
||||
InstanceBan,
|
||||
Member,
|
||||
Recipient,
|
||||
Sticker,
|
||||
Stopwatch,
|
||||
User,
|
||||
UserDeleteEvent,
|
||||
} from "@spacebar/util";
|
||||
import { Request, Response, Router } from "express";
|
||||
import { ChannelType, InstanceUserDeleteSchema, PrivateUserProjection } from "@spacebar/schemas";
|
||||
import { Not } from "typeorm";
|
||||
@@ -40,6 +54,7 @@ router.post(
|
||||
},
|
||||
}),
|
||||
async (req: Request, res: Response) => {
|
||||
const sw = Stopwatch.startNew();
|
||||
const body = req.body as InstanceUserDeleteSchema | undefined;
|
||||
const user = await User.findOneOrFail({
|
||||
where: { id: req.params.user_id },
|
||||
@@ -170,6 +185,7 @@ router.post(
|
||||
data: { user_id: req.params.user_id },
|
||||
} as UserDeleteEvent);
|
||||
|
||||
console.log(`[Instance ban] Deleted user ${user.id} from instance in ${sw.elapsed().toString()} ms`);
|
||||
res.sendStatus(204);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -68,4 +68,17 @@ export class ElapsedTime {
|
||||
get days(): number {
|
||||
return this.totalDays;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
// Format: "DD.HH:MM:SS.mmmuuuNNN", with days being optional
|
||||
const daysPart = this.days > 0 ? `${this.days}.` : "";
|
||||
const hoursPart = this.hours.toString().padStart(2, "0");
|
||||
const minutesPart = this.minutes.toString().padStart(2, "0");
|
||||
const secondsPart = this.seconds.toString().padStart(2, "0");
|
||||
const millisecondsPart = this.milliseconds.toString().padStart(3, "0");
|
||||
const microsecondsPart = this.microseconds.toString().padStart(3, "0");
|
||||
const nanosecondsPart = this.nanoseconds.toString().padStart(3, "0");
|
||||
|
||||
return `${daysPart}${hoursPart}:${minutesPart}:${secondsPart}.${millisecondsPart}${microsecondsPart}${nanosecondsPart}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user