chore: utils.gc -> cron.daily (#3543)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user