diff --git a/packages/server/src/api/controllers/deploy/utils.js b/packages/server/src/api/controllers/deploy/utils.js index 4c46f9c6d4..c5ac0641aa 100644 --- a/packages/server/src/api/controllers/deploy/utils.js +++ b/packages/server/src/api/controllers/deploy/utils.js @@ -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, } diff --git a/packages/server/src/utilities/index.js b/packages/server/src/utilities/index.js index 733afd2870..0c4e60ccc6 100644 --- a/packages/server/src/utilities/index.js +++ b/packages/server/src/utilities/index.js @@ -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}` + ) +} diff --git a/packages/server/src/utilities/rowProcessor.js b/packages/server/src/utilities/rowProcessor.js index 6727a8a323..74918d24d1 100644 --- a/packages/server/src/utilities/rowProcessor.js +++ b/packages/server/src/utilities/rowProcessor.js @@ -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) }) } }