chore: utils.gc -> cron.daily (#3543)

This commit is contained in:
Tom Moor
2022-05-16 12:44:22 -07:00
committed by GitHub
parent 4c15f27bb2
commit b8a02df7ba
3 changed files with 12 additions and 6 deletions

View File

@@ -8,9 +8,9 @@ const server = new TestServer(app.callback());
beforeEach(() => flushdb());
afterAll(() => server.close());
describe("#utils.gc", () => {
describe("#cron.daily", () => {
it("should require authentication", async () => {
const res = await server.post("/api/utils.gc");
const res = await server.post("/api/cron.daily");
expect(res.status).toEqual(401);
});
});

View File

@@ -1,3 +1,4 @@
import { Context } from "koa";
import Router from "koa-router";
import { AuthenticationError } from "@server/errors";
import CleanupDeletedDocumentsTask from "@server/queues/tasks/CleanupDeletedDocumentsTask";
@@ -7,8 +8,8 @@ import InviteReminderTask from "@server/queues/tasks/InviteReminderTask";
const router = new Router();
router.post("utils.gc", async (ctx) => {
const { token, limit = 500 } = ctx.body;
const cronHandler = async (ctx: Context) => {
const { token, limit = 500 } = ctx.body as { token?: string; limit: number };
if (process.env.UTILS_SECRET !== token) {
throw AuthenticationError("Invalid secret token");
@@ -25,6 +26,11 @@ router.post("utils.gc", async (ctx) => {
ctx.body = {
success: true,
};
});
};
router.post("cron.:period", cronHandler);
// For backwards compatibility
router.post("utils.gc", cronHandler);
export default router;

View File

@@ -9,6 +9,7 @@ import attachments from "./attachments";
import auth from "./auth";
import authenticationProviders from "./authenticationProviders";
import collections from "./collections";
import utils from "./cron";
import documents from "./documents";
import events from "./events";
import fileOperationsRoute from "./fileOperations";
@@ -25,7 +26,6 @@ import shares from "./shares";
import stars from "./stars";
import team from "./team";
import users from "./users";
import utils from "./utils";
import views from "./views";
const api = new Koa();