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) {
|
||||
const response = await fetch(
|
||||
`${process.env.DEPLOYMENT_CREDENTIALS_URL}/deploy/success`,
|
||||
{
|
||||
const DEPLOYMENT_SUCCESS_URL =
|
||||
process.env.DEPLOYMENT_CREDENTIALS_URL + "deploy/success"
|
||||
|
||||
console.log(DEPLOYMENT_SUCCESS_URL)
|
||||
const response = await fetch(DEPLOYMENT_SUCCESS_URL, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
apiKey: process.env.BUDIBASE_API_KEY,
|
||||
quota,
|
||||
}),
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
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()
|
||||
|
@ -163,8 +164,13 @@ exports.uploadAppAssets = async function({
|
|||
|
||||
// Upload file attachments
|
||||
const db = new PouchDB(instanceId)
|
||||
const fileUploads = await db.get("_local/fileuploads")
|
||||
if (fileUploads) {
|
||||
let fileUploads
|
||||
try {
|
||||
fileUploads = await db.get("_local/fileuploads")
|
||||
} catch (err) {
|
||||
fileUploads = { _id: "_local/fileuploads", uploads: [] }
|
||||
}
|
||||
|
||||
for (let file of fileUploads.uploads) {
|
||||
if (file.uploaded) continue
|
||||
|
||||
|
@ -182,11 +188,9 @@ exports.uploadAppAssets = async function({
|
|||
}
|
||||
|
||||
db.put(fileUploads)
|
||||
}
|
||||
|
||||
try {
|
||||
await Promise.all(uploads)
|
||||
// TODO: update dynamoDB with a synopsis of the app deployment for historical purposes
|
||||
await invalidateCDN(cfDistribution, appId)
|
||||
} catch (err) {
|
||||
console.error("Error uploading budibase app assets to s3", err)
|
||||
|
|
|
@ -5,13 +5,10 @@ const {
|
|||
verifyDeployment,
|
||||
updateDeploymentQuota,
|
||||
} = require("./aws")
|
||||
const { getRecordParams } = require("../../db/utils")
|
||||
|
||||
function replicate(local, remote) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const replication = local.sync(remote, {
|
||||
retry: true,
|
||||
})
|
||||
const replication = local.sync(remote)
|
||||
|
||||
replication.on("complete", () => resolve())
|
||||
replication.on("error", err => reject(err))
|
||||
|
@ -40,11 +37,10 @@ async function replicateCouch({ instanceId, clientId, credentials }) {
|
|||
|
||||
async function getCurrentInstanceQuota(instanceId) {
|
||||
const db = new PouchDB(instanceId)
|
||||
const records = await db.allDocs(
|
||||
getRecordParams("", null, {
|
||||
include_docs: true,
|
||||
const records = await db.allDocs({
|
||||
startkey: "record:",
|
||||
endkey: `record:\ufff0`,
|
||||
})
|
||||
)
|
||||
const existingRecords = records.rows.length
|
||||
|
||||
const designDoc = await db.get("_design/database")
|
||||
|
|
Loading…
Reference in New Issue