Lines
100 %
Functions
91.67 %
Branches
//! Template storage natives. Wraps `server::command::template::DeleteTemplate`;
//! not render-safe, so it is never linked into the render surface.
use scripting::runtime::read_string_arg;
use server::command::template::DeleteTemplate;
use uuid::Uuid;
use wasmtime::{ArrayRef, Linker, Rooted};
use crate::host_failure::cmd_failure;
use crate::natives::args::uuid_arg;
use crate::natives::native::register_native;
use crate::session::SessionData;
pub const REGISTERED_COMMANDS: &[&str] = &["delete-template"];
pub fn register(linker: &mut Linker<SessionData>) -> wasmtime::Result<()> {
register_native(
linker,
"template_store_delete_template",
|caller, (id_arg,): (Option<Rooted<ArrayRef>>,)| {
Box::pin(async move {
let user_id = caller.data().ctx().user_id;
let id = read_string_arg(caller, id_arg)?;
run_delete_template(user_id, id).await
})
},
)
}
/// Removes the template; an id the user does not hold is `not-found`. Returns
/// `t` on success.
pub(super) async fn run_delete_template(
user_id: Uuid,
id_arg: Option<String>,
) -> wasmtime::Result<i32> {
let template_id = uuid_arg("delete-template", "template-id", id_arg)?;
DeleteTemplate::new()
.user_id(user_id)
.template_id(template_id)
.run()
.await
.map(|_| 1)
.map_err(|err| cmd_failure("delete-template", err))