tidy up
This commit is contained in:
parent
ee73c7f418
commit
3994816c69
|
@ -22,19 +22,20 @@ async function invalidateCDN(cfDistribution, appId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.updateDeploymentQuota = async function(quota) {
|
exports.updateDeploymentQuota = async function(quota) {
|
||||||
const response = await fetch(
|
const DEPLOYMENT_SUCCESS_URL =
|
||||||
`${process.env.DEPLOYMENT_CREDENTIALS_URL}/deploy/success`,
|
process.env.DEPLOYMENT_CREDENTIALS_URL + "deploy/success"
|
||||||
{
|
|
||||||
method: "POST",
|
console.log(DEPLOYMENT_SUCCESS_URL)
|
||||||
body: JSON.stringify({
|
const response = await fetch(DEPLOYMENT_SUCCESS_URL, {
|
||||||
apiKey: process.env.BUDIBASE_API_KEY,
|
method: "POST",
|
||||||
quota,
|
body: JSON.stringify({
|
||||||
}),
|
apiKey: process.env.BUDIBASE_API_KEY,
|
||||||
}
|
quota,
|
||||||
)
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw new Error(`Error updating deployment quota for app`)
|
throw new Error(`Error updating deployment quota for API Key`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
@ -163,30 +164,33 @@ exports.uploadAppAssets = async function({
|
||||||
|
|
||||||
// Upload file attachments
|
// Upload file attachments
|
||||||
const db = new PouchDB(instanceId)
|
const db = new PouchDB(instanceId)
|
||||||
const fileUploads = await db.get("_local/fileuploads")
|
let fileUploads
|
||||||
if (fileUploads) {
|
try {
|
||||||
for (let file of fileUploads.uploads) {
|
fileUploads = await db.get("_local/fileuploads")
|
||||||
if (file.uploaded) continue
|
} catch (err) {
|
||||||
|
fileUploads = { _id: "_local/fileuploads", uploads: [] }
|
||||||
const attachmentUpload = prepareUploadForS3({
|
|
||||||
file,
|
|
||||||
s3Key: `assets/${appId}/attachments/${file.processedFileName}`,
|
|
||||||
s3,
|
|
||||||
metadata: { accountId },
|
|
||||||
})
|
|
||||||
|
|
||||||
uploads.push(attachmentUpload)
|
|
||||||
|
|
||||||
// mark file as uploaded
|
|
||||||
file.uploaded = true
|
|
||||||
}
|
|
||||||
|
|
||||||
db.put(fileUploads)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let file of fileUploads.uploads) {
|
||||||
|
if (file.uploaded) continue
|
||||||
|
|
||||||
|
const attachmentUpload = prepareUploadForS3({
|
||||||
|
file,
|
||||||
|
s3Key: `assets/${appId}/attachments/${file.processedFileName}`,
|
||||||
|
s3,
|
||||||
|
metadata: { accountId },
|
||||||
|
})
|
||||||
|
|
||||||
|
uploads.push(attachmentUpload)
|
||||||
|
|
||||||
|
// mark file as uploaded
|
||||||
|
file.uploaded = true
|
||||||
|
}
|
||||||
|
|
||||||
|
db.put(fileUploads)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all(uploads)
|
await Promise.all(uploads)
|
||||||
// TODO: update dynamoDB with a synopsis of the app deployment for historical purposes
|
|
||||||
await invalidateCDN(cfDistribution, appId)
|
await invalidateCDN(cfDistribution, appId)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error uploading budibase app assets to s3", err)
|
console.error("Error uploading budibase app assets to s3", err)
|
||||||
|
|
|
@ -5,13 +5,10 @@ const {
|
||||||
verifyDeployment,
|
verifyDeployment,
|
||||||
updateDeploymentQuota,
|
updateDeploymentQuota,
|
||||||
} = require("./aws")
|
} = require("./aws")
|
||||||
const { getRecordParams } = require("../../db/utils")
|
|
||||||
|
|
||||||
function replicate(local, remote) {
|
function replicate(local, remote) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const replication = local.sync(remote, {
|
const replication = local.sync(remote)
|
||||||
retry: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
replication.on("complete", () => resolve())
|
replication.on("complete", () => resolve())
|
||||||
replication.on("error", err => reject(err))
|
replication.on("error", err => reject(err))
|
||||||
|
@ -40,11 +37,10 @@ async function replicateCouch({ instanceId, clientId, credentials }) {
|
||||||
|
|
||||||
async function getCurrentInstanceQuota(instanceId) {
|
async function getCurrentInstanceQuota(instanceId) {
|
||||||
const db = new PouchDB(instanceId)
|
const db = new PouchDB(instanceId)
|
||||||
const records = await db.allDocs(
|
const records = await db.allDocs({
|
||||||
getRecordParams("", null, {
|
startkey: "record:",
|
||||||
include_docs: true,
|
endkey: `record:\ufff0`,
|
||||||
})
|
})
|
||||||
)
|
|
||||||
const existingRecords = records.rows.length
|
const existingRecords = records.rows.length
|
||||||
|
|
||||||
const designDoc = await db.get("_design/database")
|
const designDoc = await db.get("_design/database")
|
||||||
|
|
Loading…
Reference in New Issue