add: uploads in post quotes

This commit is contained in:
trisua 2025-09-07 11:06:03 -04:00
parent abd23e0ccc
commit 6e4fd3da36
6 changed files with 84 additions and 16 deletions

4
Cargo.lock generated
View file

@ -3452,7 +3452,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"tera", "tera",
"tetratto-core 16.0.2", "tetratto-core 16.0.3",
"tetratto-l10n 12.0.0", "tetratto-l10n 12.0.0",
"tetratto-shared 12.0.6", "tetratto-shared 12.0.6",
"tokio", "tokio",
@ -3489,7 +3489,7 @@ dependencies = [
[[package]] [[package]]
name = "tetratto-core" name = "tetratto-core"
version = "16.0.2" version = "16.0.3"
dependencies = [ dependencies = [
"async-recursion", "async-recursion",
"base16ct", "base16ct",

View file

@ -361,6 +361,7 @@
false, false,
document.getElementById(\"community_to_post_to\") document.getElementById(\"community_to_post_to\")
.selectedOptions[0].getAttribute(\"is_stack\") === \"true\", .selectedOptions[0].getAttribute(\"is_stack\") === \"true\",
e.target.file_picker ? e.target.file_picker.files : [],
]); ]);
// update settings // update settings

View file

@ -1494,7 +1494,7 @@
(text "{% macro create_post_options() -%}") (text "{% macro create_post_options() -%}")
(div (div
("class" "flex gap_2 flex_wrap") ("class" "flex gap_2 flex_wrap")
(text "{{ components::emoji_picker(element_id=\"content\", render_dialog=true) }} {% if not quoting -%} {% if is_supporter -%} {{ components::file_picker(files_list_id=\"files_list\") }} {%- endif %} {%- endif %}") (text "{{ components::emoji_picker(element_id=\"content\", render_dialog=true) }} {% if is_supporter -%} {{ components::file_picker(files_list_id=\"files_list\") }} {%- endif %}")
(button (button
("class" "small square lowered") ("class" "small square lowered")

View file

@ -311,19 +311,30 @@
community, community,
do_not_redirect = false, do_not_redirect = false,
is_stack = false, is_stack = false,
uploads = [],
) => { ) => {
await trigger("atto::debounce", ["posts::create"]); await trigger("atto::debounce", ["posts::create"]);
return new Promise((resolve, _) => { return new Promise((resolve, _) => {
fetch(`/api/v1/posts/${id}/repost`, { // create body
method: "POST", const body = new FormData();
headers: {
"Content-Type": "application/json", for (const file of uploads) {
}, body.append(file.name, file);
body: JSON.stringify({ }
body.append(
"body",
JSON.stringify({
content, content,
community: !is_stack ? community : "0", community: !is_stack ? community : "0",
stack: is_stack ? community : "0", stack: is_stack ? community : "0",
}), }),
);
// send
fetch(`/api/v1/posts/${id}/repost`, {
method: "POST",
body,
}) })
.then((res) => res.json()) .then((res) => res.json())
.then((res) => { .then((res) => {

View file

@ -241,7 +241,7 @@ pub async fn create_repost_request(
jar: CookieJar, jar: CookieJar,
Extension(data): Extension<State>, Extension(data): Extension<State>,
Path(id): Path<usize>, Path(id): Path<usize>,
Json(req): Json<CreateRepost>, JsonMultipart(images, req): JsonMultipart<CreateRepost>,
) -> impl IntoResponse { ) -> impl IntoResponse {
let data = &(data.read().await).0; let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserCreatePosts) { let user = match get_user_from_token!(jar, data, oauth::AppScope::UserCreatePosts) {
@ -264,13 +264,69 @@ pub async fn create_repost_request(
Err(e) => return Json(Error::MiscError(e.to_string()).into()), Err(e) => return Json(Error::MiscError(e.to_string()).into()),
}; };
// check sizes
for img in &images {
if img.len() > MAXIMUM_FILE_SIZE {
return Json(Error::FileTooLarge.into());
}
}
// create uploads
for _ in 0..images.len() {
props.uploads.push(
match data
.2
.create_upload(MediaUpload::new(
MediaType::Webp,
props.owner,
"post_media".to_string(),
))
.await
{
Ok(u) => u.id,
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
},
);
}
// ... // ...
let uploads = props.uploads.clone();
match data.create_post(props).await { match data.create_post(props).await {
Ok(id) => Json(ApiReturn { Ok(id) => {
// write to uploads
for (i, upload_id) in uploads.iter().enumerate() {
let image = match images.get(i) {
Some(img) => img,
None => {
if let Err(e) = data.2.delete_upload(*upload_id).await {
return Json(Error::MiscError(e.to_string()).into());
}
continue;
}
};
let upload = match data.2.get_upload_by_id(*upload_id).await {
Ok(u) => u,
Err(e) => return Json(Error::MiscError(e.to_string()).into()),
};
if let Err(e) = save_webp_buffer(
&upload.path(&data.2.0.0.directory).to_string(),
image.to_vec(),
None,
) {
return Json(Error::MiscError(e.to_string()).into());
}
}
// ...
Json(ApiReturn {
ok: true, ok: true,
message: "Post reposted".to_string(), message: "Post reposted".to_string(),
payload: Some(id.to_string()), payload: Some(id.to_string()),
}), })
}
Err(e) => Json(e.into()), Err(e) => Json(e.into()),
} }
} }

View file

@ -1,7 +1,7 @@
[package] [package]
name = "tetratto-core" name = "tetratto-core"
description = "The core behind Tetratto" description = "The core behind Tetratto"
version = "16.0.2" version = "16.0.3"
edition = "2024" edition = "2024"
readme = "../../README.md" readme = "../../README.md"
authors.workspace = true authors.workspace = true