commit
9ed2b63a77
|
@ -57,6 +57,7 @@
|
||||||
"electron-updater": "^4.3.1",
|
"electron-updater": "^4.3.1",
|
||||||
"fix-path": "^3.0.0",
|
"fix-path": "^3.0.0",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
|
"jimp": "^0.16.1",
|
||||||
"joi": "^17.2.1",
|
"joi": "^17.2.1",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"koa": "^2.7.0",
|
"koa": "^2.7.0",
|
||||||
|
@ -74,7 +75,6 @@
|
||||||
"pouchdb-all-dbs": "^1.0.2",
|
"pouchdb-all-dbs": "^1.0.2",
|
||||||
"pouchdb-replication-stream": "^1.2.9",
|
"pouchdb-replication-stream": "^1.2.9",
|
||||||
"sanitize-s3-objectkey": "^0.0.1",
|
"sanitize-s3-objectkey": "^0.0.1",
|
||||||
"sharp": "^0.26.0",
|
|
||||||
"squirrelly": "^7.5.0",
|
"squirrelly": "^7.5.0",
|
||||||
"tar-fs": "^2.1.0",
|
"tar-fs": "^2.1.0",
|
||||||
"uuid": "^3.3.2",
|
"uuid": "^3.3.2",
|
||||||
|
|
|
@ -163,15 +163,14 @@ exports.serveApp = async function(ctx) {
|
||||||
|
|
||||||
exports.serveAttachment = async function(ctx) {
|
exports.serveAttachment = async function(ctx) {
|
||||||
const appId = ctx.user.appId
|
const appId = ctx.user.appId
|
||||||
|
|
||||||
const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments")
|
const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments")
|
||||||
|
|
||||||
// Serve from CloudFront
|
// Serve from CloudFront
|
||||||
if (process.env.CLOUD) {
|
if (process.env.CLOUD) {
|
||||||
const S3_URL = `https://cdn.app.budi.live/assets/${appId}/attachments/${ctx.file}`
|
const S3_URL = `https://cdn.app.budi.live/assets/${appId}/attachments/${ctx.file}`
|
||||||
|
|
||||||
const response = await fetch(S3_URL)
|
const response = await fetch(S3_URL)
|
||||||
const body = await response.text()
|
const body = await response.text()
|
||||||
|
ctx.set("Content-Type", response.headers.get("Content-Type"))
|
||||||
ctx.body = body
|
ctx.body = body
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,21 @@
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const sharp = require("sharp")
|
const jimp = require("jimp")
|
||||||
const fsPromises = fs.promises
|
const fsPromises = fs.promises
|
||||||
|
|
||||||
const FORMATS = {
|
const FORMATS = {
|
||||||
IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"],
|
IMAGES: ["png", "jpg", "jpeg", "gif", "bmp", "tiff"],
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processImage(file) {
|
function processImage(file) {
|
||||||
const imgMeta = await sharp(file.path)
|
return jimp.read(file.path).then(img => {
|
||||||
.resize(300)
|
return img.resize(300, jimp.AUTO).write(file.outputPath)
|
||||||
.toFile(file.outputPath)
|
})
|
||||||
return {
|
|
||||||
...file,
|
|
||||||
...imgMeta,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function process(file) {
|
async function process(file) {
|
||||||
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
|
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
|
||||||
return await processImage(file)
|
await processImage(file)
|
||||||
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
// No processing required
|
// No processing required
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue