Adding dev endpoint to clear lock.

This commit is contained in:
mike12345567 2021-05-12 17:43:01 +01:00
parent 2021c59dd9
commit 3f75ebf853
2 changed files with 19 additions and 0 deletions

View File

@ -2,6 +2,8 @@ const fetch = require("node-fetch")
const env = require("../../environment")
const { checkSlashesInUrl } = require("../../utilities")
const { request } = require("../../utilities/workerRequests")
const { getGlobalIDFromUserMetadataID } = require("../../db/utils")
const { clearLock } = require("../../utilities/redis")
async function redirect(ctx, method) {
const { devPath } = ctx.params
@ -32,3 +34,16 @@ exports.redirectPost = async ctx => {
exports.redirectDelete = async ctx => {
await redirect(ctx, "DELETE")
}
exports.removeLock = async ctx => {
const { appId } = ctx.params
const globalUserId = getGlobalIDFromUserMetadataID(ctx.user._id)
try {
await clearLock(appId, globalUserId)
} catch (err) {
ctx.throw(400, "Unable to remove lock.")
}
ctx.body = {
message: "Lock removed successfully."
}
}

View File

@ -1,6 +1,8 @@
const Router = require("@koa/router")
const controller = require("../controllers/dev")
const env = require("../../environment")
const authorized = require("../../middleware/authorized")
const { BUILDER } = require("../../utilities/security/permissions")
const router = Router()
@ -11,4 +13,6 @@ if (env.isDev() || env.isTest()) {
.delete("/api/admin/:devPath(.*)", controller.redirectDelete)
}
router.delete("/api/dev/:appId/lock", authorized(BUILDER), controller.removeLock)
module.exports = router