1
0
Fork 0
mirror of synced 2024-07-02 13:01:09 +12:00

Making attachments always a relative path on the way out.

This commit is contained in:
mike12345567 2021-04-09 13:41:39 +01:00
parent ed77135093
commit 75e0d82c8d
3 changed files with 23 additions and 894 deletions

File diff suppressed because it is too large Load diff

View file

@ -51,11 +51,11 @@ exports.prepareUpload = async function({ s3Key, bucket, metadata, file }) {
type: file.type,
})
// don't store a URL, work this out on the way out as the URL could change
return {
size: file.size,
name: file.name,
extension: [...file.name.split(".")].pop(),
url: response.Location,
key: response.Key,
}
}

View file

@ -1,8 +1,8 @@
const env = require("../environment")
const { OBJ_STORE_DIRECTORY } = require("../constants")
const { ObjectStoreBuckets } = require("../constants")
const linkRows = require("../db/linkedRows")
const { cloneDeep } = require("lodash/fp")
const { FieldTypes, AutoFieldSubTypes } = require("../constants")
const { checkSlashesInUrl } = require("./index")
const BASE_AUTO_ID = 1
@ -180,18 +180,17 @@ exports.outputProcessing = async (appId, table, rows) => {
rows
)
// update the attachments URL depending on hosting
if (env.isProd() && env.SELF_HOSTED) {
for (let [property, column] of Object.entries(table.schema)) {
if (column.type === FieldTypes.ATTACHMENT) {
for (let row of outputRows) {
if (row[property] == null || row[property].length === 0) {
continue
}
row[property].forEach(attachment => {
attachment.url = `${OBJ_STORE_DIRECTORY}/${appId}/${attachment.url}`
attachment.url = attachment.url.replace("//", "/")
})
for (let [property, column] of Object.entries(table.schema)) {
if (column.type === FieldTypes.ATTACHMENT) {
for (let row of outputRows) {
if (row[property] == null || row[property].length === 0) {
continue
}
row[property].forEach(attachment => {
attachment.url = checkSlashesInUrl(
`${ObjectStoreBuckets.APPS}/${attachment.key}`
)
})
}
}
}