add: stack clones

This commit is contained in:
trisua 2025-08-15 19:09:37 -04:00
parent 3a48ef2969
commit eec81f5718
5 changed files with 55 additions and 0 deletions

View file

@ -256,6 +256,7 @@ version = "1.0.0"
"stacks:label.remove" = "Remove"
"stacks:label.block_all" = "Block all"
"stacks:label.unblock_all" = "Unblock all"
"stacks:label.clone" = "Clone"
"forge:label.forges" = "Forges"
"forge:label.my_forges" = "My forges"

View file

@ -37,6 +37,14 @@
(text "{{ icon \"pencil\" }}")
(span
(text "{{ text \"general:action.manage\" }}")))
(text "{% elif user -%}")
; clone button for non-owner users
(button
("class" "lowered small")
("onclick" "clone_stack()")
(icon (text "book-copy"))
(span
(str (text "stacks:label.clone"))))
(text "{%- endif %}")))
(div
("class" "card w_full flex flex_col gap_2")
@ -114,5 +122,22 @@
window.location.href = \"/settings#/account/blocks\";
}
});
}
async function clone_stack() {
fetch(\"/api/v1/stacks/{{ stack.id }}/clone\", {
method: \"POST\",
})
.then((res) => res.json())
.then((res) => {
trigger(\"atto::toast\", [
res.ok ? \"success\" : \"error\",
res.message,
]);
if (res.ok) {
window.location.href = `/stacks/${res.payload}`;
}
});
}"))
(text "{% endblock %}")

View file

@ -665,6 +665,7 @@ pub fn routes() -> Router {
.route("/stacks", get(stacks::list_request))
.route("/stacks", post(stacks::create_request))
.route("/stacks/{id}", get(stacks::get_request))
.route("/stacks/{id}/clone", post(stacks::clone_request))
.route("/stacks/{id}/name", post(stacks::update_name_request))
.route("/stacks/{id}/privacy", post(stacks::update_privacy_request))
.route("/stacks/{id}/mode", post(stacks::update_mode_request))

View file

@ -91,6 +91,27 @@ pub async fn create_request(
}
}
pub async fn clone_request(
jar: CookieJar,
Extension(data): Extension<State>,
Path(id): Path<usize>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserCreateStacks) {
Some(ua) => ua,
None => return Json(Error::NotAllowed.into()),
};
match data.clone_stack(user.id, id).await {
Ok(s) => Json(ApiReturn {
ok: true,
message: "Stack created".to_string(),
payload: s.id.to_string(),
}),
Err(e) => Json(e.into()),
}
}
pub async fn update_name_request(
jar: CookieJar,
Extension(data): Extension<State>,