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