Skip to content

Commit

Permalink
prep download
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDavenport committed Apr 24, 2024
1 parent 9c42cb6 commit 24ab164
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gamercade_app/src/task_manager/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl TaskRequest<HttpManagerState> for HttpRequest {
state: &Arc<Mutex<HttpManagerState>>,
) {
match self {
HttpRequest::DownloadRom(request) => download_file(sender.clone(), request),
HttpRequest::DownloadRom(request) => download_file(sender.clone(), state.clone(), request),
HttpRequest::UploadRom(request) => {
let WithSession {
data: request,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl TaskRequest<HttpManagerState> for HttpRequest {
}

// TODO: May want to keep the join handle around
fn download_file(sender: Sender<TaskNotification>, request: WithSession<DownloadRom>) {
fn download_file(sender: Sender<TaskNotification>, state: Arc<Mutex<HttpManagerState>>, request: WithSession<DownloadRom>) {
tokio::spawn(async move {
let WithSession {
session,
Expand All @@ -137,6 +137,7 @@ fn download_file(sender: Sender<TaskNotification>, request: WithSession<Download
loop {
match response.chunk().await {
Ok(Some(bytes)) => {
// TODO: Notify state of downloaded chunks
buffer.extend_from_slice(&bytes);
}
Ok(None) => {
Expand All @@ -158,6 +159,8 @@ fn download_file(sender: Sender<TaskNotification>, request: WithSession<Download
}

// Notify the main thread that the download is done
// TODO: Include checksum in output

sender
.send(TaskNotification::HttpResponse(
HttpResponse::DownloadComplete(DownloadRomComplete {
Expand Down

0 comments on commit 24ab164

Please sign in to comment.