Compare commits

..

2 Commits

Author SHA1 Message Date
Armored Dragon a603946868
Limit uploaded media resolution size for profile pictures.
Signed-off-by: Armored Dragon <publicmail@armoreddragon.com>
2024-07-12 13:46:48 -05:00
Armored Dragon 1e5202cd59
Move function from the text editor to the relevant file.
Signed-off-by: Armored Dragon <publicmail@armoreddragon.com>
2024-07-12 13:34:17 -05:00
4 changed files with 23 additions and 16 deletions

View File

@ -19,6 +19,8 @@ const md = require("markdown-it")()
}),
});
/* global Buffer */
let settings = {
SETUP_COMPLETE: false,
ACCOUNT_REGISTRATION: false,
@ -393,10 +395,10 @@ async function updateBiography({ requester_id, author_id, biography_content }) {
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;
const content_name = crypto.randomUUID();
let maximum_image_resolution = { width: 1920, height: 1080 };
let maximum_image_resolution = resolution_override || { width: 1920, height: 1080 };
// Images
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: Verification for image uploading
// 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) {
// TODO: Permissions for deleting image

View File

@ -82,3 +82,18 @@ function _readFile(file) {
reader.readAsDataURL(file);
});
}
async function updateBiography() {
let form_data = {
media: media,
content: qs("#post-content").value,
id: window.location.href.split("/")[4],
};
const post_response = await request("/api/web/biography", "PATCH", form_data);
if (post_response.body.success) {
window.location.href = `/post/${post_response.body.post_id}`;
}
}

View File

@ -86,16 +86,3 @@ function _readFile(file) {
});
}
async function updateBiography() {
let form_data = {
media: media,
content: qs("#post-content").value,
id: window.location.href.split("/")[4],
};
const post_response = await request("/api/web/biography", "PATCH", form_data);
if (post_response.body.success) {
window.location.href = `/post/${post_response.body.post_id}`;
}
}