2020-09-28 18:04:08 +02:00
|
|
|
const fetch = require("node-fetch")
|
|
|
|
const {
|
|
|
|
downloadTemplate,
|
|
|
|
exportTemplateFromApp,
|
|
|
|
} = require("../../utilities/templates")
|
|
|
|
|
|
|
|
const DEFAULT_TEMPLATES_BUCKET =
|
|
|
|
"prod-budi-templates.s3-eu-west-1.amazonaws.com"
|
|
|
|
|
|
|
|
exports.fetch = async function(ctx) {
|
|
|
|
const { type = "app" } = ctx.query
|
|
|
|
|
|
|
|
const response = await fetch(
|
|
|
|
`https://${DEFAULT_TEMPLATES_BUCKET}/manifest.json`
|
|
|
|
)
|
|
|
|
const json = await response.json()
|
|
|
|
ctx.body = Object.values(json.templates[type])
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.downloadTemplate = async function(ctx) {
|
|
|
|
const { type, name } = ctx.params
|
|
|
|
|
|
|
|
await downloadTemplate(type, name)
|
|
|
|
|
|
|
|
ctx.body = {
|
|
|
|
message: `template ${type}:${name} downloaded successfully.`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.exportTemplateFromApp = async function(ctx) {
|
2020-10-29 11:28:27 +01:00
|
|
|
const { appId } = ctx.user
|
2020-09-28 18:04:08 +02:00
|
|
|
const { templateName } = ctx.request.body
|
|
|
|
|
|
|
|
await exportTemplateFromApp({
|
|
|
|
appId,
|
|
|
|
templateName,
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx.status = 200
|
|
|
|
ctx.body = {
|
|
|
|
message: `Created template: ${templateName}`,
|
|
|
|
}
|
|
|
|
}
|