Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
38
crates/scel_api/src/graphql/mutation.rs
Normal file
38
crates/scel_api/src/graphql/mutation.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_graphql::{Context, Object, Result, SimpleObject, ID};
|
||||
use scel_core::{services::Download, App};
|
||||
|
||||
pub struct MutationRoot;
|
||||
|
||||
#[derive(SimpleObject)]
|
||||
struct RequestDownloadResponse {
|
||||
id: ID,
|
||||
}
|
||||
|
||||
#[Object]
|
||||
impl MutationRoot {
|
||||
async fn request_download(
|
||||
&self,
|
||||
ctx: &Context<'_>,
|
||||
download_link: String,
|
||||
) -> Result<RequestDownloadResponse> {
|
||||
let app = ctx.data_unchecked::<Arc<App>>();
|
||||
|
||||
let download = app
|
||||
.download_service
|
||||
.clone()
|
||||
.add_download(Download {
|
||||
id: None,
|
||||
link: download_link,
|
||||
progress: None,
|
||||
file_name: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Ok(RequestDownloadResponse {
|
||||
id: download.id.unwrap().into(),
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user