Limit uploaded media resolution size for profile pictures.

Signed-off-by: Armored Dragon <publicmail@armoreddragon.com>
feature/profile
Armored Dragon 2024-07-12 13:46:48 -05:00
parent 1e5202cd59
commit a603946868
Signed by: ArmoredDragon
GPG Key ID: C7207ACC3382AD8B
2 changed files with 8 additions and 3 deletions

View File

@ -19,6 +19,8 @@ const md = require("markdown-it")()
}), }),
}); });
/* global Buffer */
let settings = { let settings = {
SETUP_COMPLETE: false, SETUP_COMPLETE: false,
ACCOUNT_REGISTRATION: false, ACCOUNT_REGISTRATION: false,
@ -393,10 +395,10 @@ async function updateBiography({ requester_id, author_id, biography_content }) {
return _r(true); return _r(true);
} }
async function uploadMedia({ parent_id, parent_type, file_buffer, content_type }) { async function uploadMedia({ parent_id, parent_type, file_buffer, content_type }, { resolution_override }) {
if (!use_s3_storage) return null; if (!use_s3_storage) return null;
const content_name = crypto.randomUUID(); const content_name = crypto.randomUUID();
let maximum_image_resolution = { width: 1920, height: 1080 }; let maximum_image_resolution = resolution_override || { width: 1920, height: 1080 };
// Images // Images
const compressed_image = await sharp(Buffer.from(file_buffer.split(",")[1], "base64"), { animated: true }) const compressed_image = await sharp(Buffer.from(file_buffer.split(",")[1], "base64"), { animated: true })

View File

@ -47,7 +47,10 @@ async function postImage(request, response) {
// TODO: Permissions for uploading images // TODO: Permissions for uploading images
// TODO: Verification for image uploading // TODO: Verification for image uploading
// FIXME: Naming // FIXME: Naming
return response.json(await core.uploadMedia({ parent_id: request.body.post_id || request.body.parent_id, parent_type: request.body.parent_type, file_buffer: request.body.buffer, content_type: request.body.content_type })); let resolution_override;
if (request.body.parent_type === "user") resolution_override = { width: 500, height: 500 };
return response.json(await core.uploadMedia({ parent_id: request.body.post_id || request.body.parent_id, parent_type: request.body.parent_type, file_buffer: request.body.buffer, content_type: request.body.content_type }, { resolution_override: resolution_override }));
} }
async function deleteImage(req, res) { async function deleteImage(req, res) {
// TODO: Permissions for deleting image // TODO: Permissions for deleting image