Updating to make sure a relative URL is always used for attachments.

This commit is contained in:
mike12345567 2021-04-09 13:49:16 +01:00
parent d508b905be
commit 30a7303762
3 changed files with 11 additions and 5 deletions

View File

@ -5,6 +5,7 @@ const fetch = require("node-fetch")
const PouchDB = require("../../../db")
const CouchDB = require("pouchdb")
const { upload } = require("../../../utilities/fileSystem")
const { attachmentsRelativeURL } = require("../../../utilities")
// TODO: everything in this file is to be removed
@ -55,6 +56,7 @@ exports.prepareUpload = async function({ s3Key, bucket, metadata, file }) {
return {
size: file.size,
name: file.name,
url: attachmentsRelativeURL(response.Key),
extension: [...file.name.split(".")].pop(),
key: response.Key,
}

View File

@ -1,7 +1,7 @@
const env = require("../environment")
const { DocumentTypes, SEPARATOR } = require("../db/utils")
const CouchDB = require("../db")
const { OBJ_STORE_DIRECTORY } = require("../constants")
const { OBJ_STORE_DIRECTORY, ObjectStoreBuckets } = require("../constants")
const BB_CDN = "https://cdn.app.budi.live/assets"
const APP_PREFIX = DocumentTypes.APP + SEPARATOR
@ -157,3 +157,9 @@ exports.clientLibraryPath = appId => {
return `/api/assets/client`
}
}
exports.attachmentsRelativeURL = attachmentKey => {
return exports.checkSlashesInUrl(
`/${ObjectStoreBuckets.APPS}/${attachmentKey}`
)
}

View File

@ -2,7 +2,7 @@ const { ObjectStoreBuckets } = require("../constants")
const linkRows = require("../db/linkedRows")
const { cloneDeep } = require("lodash/fp")
const { FieldTypes, AutoFieldSubTypes } = require("../constants")
const { checkSlashesInUrl } = require("./index")
const { attachmentsRelativeURL } = require("./index")
const BASE_AUTO_ID = 1
@ -187,9 +187,7 @@ exports.outputProcessing = async (appId, table, rows) => {
continue
}
row[property].forEach(attachment => {
attachment.url = checkSlashesInUrl(
`${ObjectStoreBuckets.APPS}/${attachment.key}`
)
attachment.url = attachmentsRelativeURL(attachment.key)
})
}
}