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_json",
"tera",
"tetratto-core 16.0.2",
"tetratto-core 16.0.3",
"tetratto-l10n 12.0.0",
"tetratto-shared 12.0.6",
"tokio",
@ -3489,7 +3489,7 @@ dependencies = [
[[package]]
name = "tetratto-core"
version = "16.0.2"
version = "16.0.3"
dependencies = [
"async-recursion",
"base16ct",

View file

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

View file

@ -1494,7 +1494,7 @@
(text "{% macro create_post_options() -%}")
(div
("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
("class" "small square lowered")

View file

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

View file

@ -241,7 +241,7 @@ pub async fn create_repost_request(
jar: CookieJar,
Extension(data): Extension<State>,
Path(id): Path<usize>,
Json(req): Json<CreateRepost>,
JsonMultipart(images, req): JsonMultipart<CreateRepost>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
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()),
};
// 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 {
Ok(id) => Json(ApiReturn {
ok: true,
message: "Post reposted".to_string(),
payload: Some(id.to_string()),
}),
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,
message: "Post reposted".to_string(),
payload: Some(id.to_string()),
})
}
Err(e) => Json(e.into()),
}
}

View file

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