Allow making archives permanent. Make archives permanent when attached to a case. Add log file metadata dynamically when served (instead of in the body directly). Add missing index on archives.expires_at.

This commit is contained in:
Dragory 2019-01-13 17:29:26 +02:00
parent 10d757f588
commit ab71481b8f
5 changed files with 59 additions and 13 deletions

View file

@ -2,6 +2,7 @@ import http, { ServerResponse } from "http";
import { GlobalPlugin } from "knub";
import { GuildArchives } from "../data/GuildArchives";
import { sleep } from "../utils";
import moment from "moment-timezone";
const DEFAULT_PORT = 9920;
const archivesRegex = /^\/(spam-logs|archives)\/([a-z0-9\-]+)\/?$/i;
@ -12,7 +13,7 @@ function notFound(res: ServerResponse) {
}
export class LogServerPlugin extends GlobalPlugin {
public static pluginName = 'log_server';
public static pluginName = "log_server";
protected archives: GuildArchives;
protected server: http.Server;
@ -36,8 +37,21 @@ export class LogServerPlugin extends GlobalPlugin {
const log = await this.archives.find(logId);
if (!log) return notFound(res);
let body = log.body;
// Add some metadata at the end of the log file (but only if it doesn't already have it directly in the body)
if (log.body.indexOf("Log file generated on") === -1) {
const createdAt = moment(log.created_at).format("YYYY-MM-DD [at] HH:mm:ss [(+00:00)]");
body += `\n\nLog file generated on ${createdAt}`;
if (log.expires_at !== null) {
const expiresAt = moment(log.expires_at).format("YYYY-MM-DD [at] HH:mm:ss [(+00:00)]");
body += `\nExpires at ${expiresAt}`;
}
}
res.setHeader("Content-Type", "text/plain; charset=UTF-8");
res.end(log.body);
res.end(body);
}
});