Skip to content

Commit

Permalink
only compress images larger than 50kb
Browse files Browse the repository at this point in the history
  • Loading branch information
RealFascinated committed Mar 4, 2025
1 parent aca5cca commit 82a78af
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/app/api/upload/sharex/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ export async function POST(
const fileId = randomString(env.FILE_ID_LENGTH);
let content = Buffer.from(file.content);

// Compression is enabled and file is an image
if (env.COMPRESS_IMAGES && file.type.startsWith("image/")) {
// Image compression
if (
env.COMPRESS_IMAGES && // Compression is enabled
file.type.startsWith("image/") && // Is an image
file.size > 51200 // Larger than 50kb
) {
const before = Date.now();
// Compress image
content = Buffer.from(
Expand Down

0 comments on commit 82a78af

Please sign in to comment.