mirror of https://github.com/Budibase/budibase.git
13 changed files with 342 additions and 177 deletions
@ -0,0 +1,46 @@ |
|||
const { MetadataTypes } = require("../../constants") |
|||
const CouchDB = require("../../db") |
|||
const { generateMetadataID } = require("../../db/utils") |
|||
const { saveEntityMetadata } = require("../../utilities") |
|||
|
|||
exports.getTypes = async ctx => { |
|||
ctx.body = { |
|||
types: MetadataTypes, |
|||
} |
|||
} |
|||
|
|||
exports.saveMetadata = async ctx => { |
|||
const { type, entityId } = ctx.params |
|||
if (type === MetadataTypes.AUTOMATION_TEST_HISTORY) { |
|||
ctx.throw(400, "Cannot save automation history type") |
|||
} |
|||
await saveEntityMetadata(ctx.appId, type, entityId, ctx.request.body) |
|||
} |
|||
|
|||
exports.deleteMetadata = async ctx => { |
|||
const { type, entityId } = ctx.params |
|||
const db = new CouchDB(ctx.appId) |
|||
const id = generateMetadataID(type, entityId) |
|||
let rev |
|||
try { |
|||
const metadata = await db.get(id) |
|||
if (metadata) { |
|||
rev = metadata._rev |
|||
} |
|||
} catch (err) { |
|||
// don't need to error if it doesn't exist
|
|||
} |
|||
if (id && rev) { |
|||
await db.remove(id, rev) |
|||
} |
|||
ctx.body = { |
|||
message: "Metadata deleted successfully.", |
|||
} |
|||
} |
|||
|
|||
exports.getMetadata = async ctx => { |
|||
const { type, entityId } = ctx.params |
|||
const db = new CouchDB(ctx.appId) |
|||
const id = generateMetadataID(type, entityId) |
|||
ctx.body = await db.get(id) |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
const Router = require("@koa/router") |
|||
const controller = require("../controllers/metadata") |
|||
const { |
|||
middleware: appInfoMiddleware, |
|||
AppType, |
|||
} = require("../../middleware/appInfo") |
|||
|
|||
const router = Router() |
|||
|
|||
router |
|||
.post( |
|||
"/api/metadata/:type/:entityId", |
|||
appInfoMiddleware({ appType: AppType.DEV }), |
|||
controller.saveMetadata |
|||
) |
|||
.delete( |
|||
"/api/metadata/:type/:entityId", |
|||
appInfoMiddleware({ appType: AppType.DEV }), |
|||
controller.deleteMetadata |
|||
) |
|||
.get( |
|||
"/api/metadata/type", |
|||
appInfoMiddleware({ appType: AppType.DEV }), |
|||
controller.getTypes |
|||
) |
|||
.get( |
|||
"/api/metadata/:type/:entityId", |
|||
appInfoMiddleware({ appType: AppType.DEV }), |
|||
controller.getMetadata |
|||
) |
|||
|
|||
module.exports = router |
|||
@ -1,12 +1,17 @@ |
|||
const triggers = require("./triggers") |
|||
const { processEvent } = require("./utils") |
|||
const { queue } = require("./bullboard") |
|||
|
|||
/** |
|||
* This module is built purely to kick off the worker farm and manage the inputs/outputs |
|||
*/ |
|||
exports.init = async function () { |
|||
// don't wait this promise, it'll never end
|
|||
triggers.automationQueue.process(async job => { |
|||
exports.init = function () { |
|||
// this promise will not complete
|
|||
return queue.process(async job => { |
|||
await processEvent(job) |
|||
}) |
|||
} |
|||
|
|||
exports.getQueues = () => { |
|||
return [queue] |
|||
} |
|||
exports.queue = queue |
|||
|
|||
@ -0,0 +1,19 @@ |
|||
const { isDevAppID, isProdAppID } = require("../db/utils") |
|||
|
|||
exports.AppType = { |
|||
DEV: "dev", |
|||
PROD: "prod", |
|||
} |
|||
|
|||
exports.middleware = |
|||
({ appType } = {}) => |
|||
(ctx, next) => { |
|||
const appId = ctx.appId |
|||
if (appType === exports.AppType.DEV && appId && !isDevAppID(appId)) { |
|||
ctx.throw(400, "Only apps in development support this endpoint") |
|||
} |
|||
if (appType === exports.AppType.PROD && appId && !isProdAppID(appId)) { |
|||
ctx.throw(400, "Only apps in production support this endpoint") |
|||
} |
|||
return next() |
|||
} |
|||
Loading…
Reference in new issue