2021-04-15 16:57:55 +02:00
|
|
|
const fetch = require("node-fetch")
|
|
|
|
const env = require("../../environment")
|
|
|
|
const { checkSlashesInUrl } = require("../../utilities")
|
|
|
|
const { request } = require("../../utilities/workerRequests")
|
2021-05-12 18:43:01 +02:00
|
|
|
const { getGlobalIDFromUserMetadataID } = require("../../db/utils")
|
|
|
|
const { clearLock } = require("../../utilities/redis")
|
2021-04-15 16:57:55 +02:00
|
|
|
|
|
|
|
async function redirect(ctx, method) {
|
2021-04-21 12:33:12 +02:00
|
|
|
const { devPath } = ctx.params
|
2021-04-15 16:57:55 +02:00
|
|
|
const response = await fetch(
|
2021-04-21 12:33:12 +02:00
|
|
|
checkSlashesInUrl(`${env.WORKER_URL}/api/admin/${devPath}`),
|
2021-04-15 16:57:55 +02:00
|
|
|
request(ctx, {
|
|
|
|
method,
|
|
|
|
body: ctx.request.body,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
ctx.body = await response.json()
|
|
|
|
const cookie = response.headers.get("set-cookie")
|
|
|
|
if (cookie) {
|
|
|
|
ctx.set("set-cookie", cookie)
|
|
|
|
}
|
|
|
|
ctx.status = response.status
|
|
|
|
ctx.cookies
|
|
|
|
}
|
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
exports.redirectGet = async ctx => {
|
2021-04-15 16:57:55 +02:00
|
|
|
await redirect(ctx, "GET")
|
|
|
|
}
|
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
exports.redirectPost = async ctx => {
|
2021-04-15 16:57:55 +02:00
|
|
|
await redirect(ctx, "POST")
|
|
|
|
}
|
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
exports.redirectDelete = async ctx => {
|
2021-04-15 16:57:55 +02:00
|
|
|
await redirect(ctx, "DELETE")
|
|
|
|
}
|
2021-05-12 18:43:01 +02:00
|
|
|
|
|
|
|
exports.removeLock = async ctx => {
|
|
|
|
const { appId } = ctx.params
|
|
|
|
try {
|
2021-05-13 13:16:09 +02:00
|
|
|
await clearLock(appId, ctx.user)
|
2021-05-12 18:43:01 +02:00
|
|
|
} catch (err) {
|
|
|
|
ctx.throw(400, "Unable to remove lock.")
|
|
|
|
}
|
|
|
|
ctx.body = {
|
2021-05-12 18:43:29 +02:00
|
|
|
message: "Lock removed successfully.",
|
2021-05-12 18:43:01 +02:00
|
|
|
}
|
|
|
|
}
|