summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--package.json1
-rw-r--r--src/services/jobs.ts9
-rw-r--r--yarn.lock14
3 files changed, 22 insertions, 2 deletions
diff --git a/package.json b/package.json
index 8cf504a..2d7cc6e 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
14 "form-data": "^4.0.0", 14 "form-data": "^4.0.0",
15 "fp-ts": "^2.11.5", 15 "fp-ts": "^2.11.5",
16 "got": "^11.8.2", 16 "got": "^11.8.2",
17 "image-size": "^1.0.0",
17 "io-ts": "^2.2.16", 18 "io-ts": "^2.2.16",
18 "nanoid": "^3.1.30", 19 "nanoid": "^3.1.30",
19 "sharp": "^0.29.1", 20 "sharp": "^0.29.1",
diff --git a/src/services/jobs.ts b/src/services/jobs.ts
index 354c66d..878593b 100644
--- a/src/services/jobs.ts
+++ b/src/services/jobs.ts
@@ -1,6 +1,7 @@
1import * as e621 from "../api/e926"; 1import * as e621 from "../api/e926";
2import * as mastodon from "../api/mastodon"; 2import * as mastodon from "../api/mastodon";
3import config from "../config"; 3import config from "../config";
4import { imageSize } from "image-size";
4import Sharp from "sharp"; 5import Sharp from "sharp";
5 6
6export async function postSpecificPicture(id: number) { 7export async function postSpecificPicture(id: number) {
@@ -33,11 +34,15 @@ async function handlePost(post: e621.Post) {
33 34
34 let file = await e621.client.get(post.file.url).buffer(); 35 let file = await e621.client.get(post.file.url).buffer();
35 36
36 if (Buffer.byteLength(file) > 1024 * 1024 * 9) { 37 const dims = imageSize(file);
38 const width = dims.width ?? 0;
39 const height = dims.height ?? 0;
40
41 if (Buffer.byteLength(file) > 1024 * 1024 * 9 || width > 2000 || height > 2000) {
37 console.log(`Compressing...`); 42 console.log(`Compressing...`);
38 43
39 file = await Sharp(file) 44 file = await Sharp(file)
40 .resize(1800, 1800, { fit: "inside", withoutEnlargement: true }) 45 .resize(2000, 2000, { fit: "inside", withoutEnlargement: true })
41 .jpeg({ quality: 80, mozjpeg: true }) 46 .jpeg({ quality: 80, mozjpeg: true })
42 .toBuffer(); 47 .toBuffer();
43 } 48 }
diff --git a/yarn.lock b/yarn.lock
index 9ea15d5..709a413 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -492,6 +492,13 @@ ieee754@^1.1.13, ieee754@^1.2.1:
492 resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" 492 resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
493 integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== 493 integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==
494 494
495image-size@^1.0.0:
496 version "1.0.0"
497 resolved "https://registry.yarnpkg.com/image-size/-/image-size-1.0.0.tgz#58b31fe4743b1cec0a0ac26f5c914d3c5b2f0750"
498 integrity sha512-JLJ6OwBfO1KcA+TvJT+v8gbE6iWbj24LyDNFgFEN0lzegn6cC6a/p3NIDaepMsJjQjlUWqIC7wJv8lBFxPNjcw==
499 dependencies:
500 queue "6.0.2"
501
495inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3: 502inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3:
496 version "2.0.4" 503 version "2.0.4"
497 resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" 504 resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
@@ -701,6 +708,13 @@ pump@^3.0.0:
701 end-of-stream "^1.1.0" 708 end-of-stream "^1.1.0"
702 once "^1.3.1" 709 once "^1.3.1"
703 710
711queue@6.0.2:
712 version "6.0.2"
713 resolved "https://registry.yarnpkg.com/queue/-/queue-6.0.2.tgz#b91525283e2315c7553d2efa18d83e76432fed65"
714 integrity sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==
715 dependencies:
716 inherits "~2.0.3"
717
704quick-lru@^5.1.1: 718quick-lru@^5.1.1:
705 version "5.1.1" 719 version "5.1.1"
706 resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932" 720 resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932"