Browse Source

Merge pull request #774 from Budibase/replace-sharp

Replace sharp
pull/777/head
Andrew Kingston 6 years ago
committed by GitHub
parent
commit
9ed2b63a77
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/server/package.json
  2. 3
      packages/server/src/api/controllers/static.js
  3. 19
      packages/server/src/utilities/fileProcessor.js
  4. 934
      packages/server/yarn.lock

2
packages/server/package.json

@ -57,6 +57,7 @@
"electron-updater": "^4.3.1",
"fix-path": "^3.0.0",
"fs-extra": "^8.1.0",
"jimp": "^0.16.1",
"joi": "^17.2.1",
"jsonwebtoken": "^8.5.1",
"koa": "^2.7.0",
@ -74,7 +75,6 @@
"pouchdb-all-dbs": "^1.0.2",
"pouchdb-replication-stream": "^1.2.9",
"sanitize-s3-objectkey": "^0.0.1",
"sharp": "^0.26.0",
"squirrelly": "^7.5.0",
"tar-fs": "^2.1.0",
"uuid": "^3.3.2",

3
packages/server/src/api/controllers/static.js

@ -163,15 +163,14 @@ exports.serveApp = async function(ctx) {
exports.serveAttachment = async function(ctx) {
const appId = ctx.user.appId
const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments")
// Serve from CloudFront
if (process.env.CLOUD) {
const S3_URL = `https://cdn.app.budi.live/assets/${appId}/attachments/${ctx.file}`
const response = await fetch(S3_URL)
const body = await response.text()
ctx.set("Content-Type", response.headers.get("Content-Type"))
ctx.body = body
return
}

19
packages/server/src/utilities/fileProcessor.js

@ -1,24 +1,21 @@
const fs = require("fs")
const sharp = require("sharp")
const jimp = require("jimp")
const fsPromises = fs.promises
const FORMATS = {
IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"],
IMAGES: ["png", "jpg", "jpeg", "gif", "bmp", "tiff"],
}
async function processImage(file) {
const imgMeta = await sharp(file.path)
.resize(300)
.toFile(file.outputPath)
return {
...file,
...imgMeta,
}
function processImage(file) {
return jimp.read(file.path).then(img => {
return img.resize(300, jimp.AUTO).write(file.outputPath)
})
}
async function process(file) {
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
return await processImage(file)
await processImage(file)
return file
}
// No processing required

934
packages/server/yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save