2020-12-14 19:31:48 +01:00
|
|
|
const CouchDB = require("../../db")
|
|
|
|
const {
|
|
|
|
getHostingInfo,
|
2021-01-14 18:01:31 +01:00
|
|
|
getDeployedApps,
|
2020-12-14 19:31:48 +01:00
|
|
|
HostingTypes,
|
2020-12-18 13:54:20 +01:00
|
|
|
getAppUrl,
|
2020-12-14 19:31:48 +01:00
|
|
|
} = require("../../utilities/builder/hosting")
|
2021-03-22 17:39:11 +01:00
|
|
|
const { StaticDatabases } = require("../../db/utils")
|
2020-12-14 19:31:48 +01:00
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
exports.fetchInfo = async (ctx) => {
|
2020-12-14 19:31:48 +01:00
|
|
|
ctx.body = {
|
|
|
|
types: Object.values(HostingTypes),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
exports.save = async (ctx) => {
|
2021-03-22 17:39:11 +01:00
|
|
|
const db = new CouchDB(StaticDatabases.BUILDER_HOSTING.name)
|
2020-12-15 18:27:45 +01:00
|
|
|
const { type } = ctx.request.body
|
2021-01-06 17:58:29 +01:00
|
|
|
if (type === HostingTypes.CLOUD && ctx.request.body._rev) {
|
|
|
|
ctx.body = await db.remove({
|
|
|
|
...ctx.request.body,
|
2021-03-22 17:39:11 +01:00
|
|
|
_id: StaticDatabases.BUILDER_HOSTING.baseDoc,
|
2021-01-06 17:58:29 +01:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
ctx.body = await db.put({
|
|
|
|
...ctx.request.body,
|
2021-03-22 17:39:11 +01:00
|
|
|
_id: StaticDatabases.BUILDER_HOSTING.baseDoc,
|
2021-01-06 17:58:29 +01:00
|
|
|
})
|
2020-12-14 19:31:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
exports.fetch = async (ctx) => {
|
2020-12-14 19:31:48 +01:00
|
|
|
ctx.body = await getHostingInfo()
|
|
|
|
}
|
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
exports.fetchUrls = async (ctx) => {
|
2020-12-14 19:31:48 +01:00
|
|
|
ctx.body = {
|
2020-12-18 13:54:20 +01:00
|
|
|
app: await getAppUrl(ctx.appId),
|
2020-12-14 19:31:48 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-14 18:01:31 +01:00
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
exports.getDeployedApps = async (ctx) => {
|
2021-04-09 16:11:49 +02:00
|
|
|
ctx.body = await getDeployedApps(ctx)
|
2021-01-14 18:01:31 +01:00
|
|
|
}
|