Skip to content

Commit 9431aa2

Browse files
quexekyDecDuck
authored andcommitted
SLowly integrating game_download into the FE. Started with using the manifest minimal example in the server (#1)
1 parent f5a7660 commit 9431aa2

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed

pages/store/index.vue

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
<template>
2-
3-
</template>
2+
3+
<button class="w-full rounded-md p-4 bg-blue-600 text-white" @click="requestGameWrapper">
4+
Load Data
5+
</button>
6+
</template>
7+
<script setup lang="ts">
8+
definePageMeta({
9+
layout: "mini",
10+
});
11+
12+
import { invoke } from "@tauri-apps/api/core";
13+
14+
async function requestGame() {
15+
console.log("Requested game from FE");
16+
await invoke("start_game_download", { gameId: "123", gameVersion: "1.2.3", maxThreads: 4 });
17+
}
18+
function requestGameWrapper() {
19+
console.log("Wrapper started");
20+
requestGame()
21+
.then(() => {})
22+
.catch((e) => {
23+
console.log(e);
24+
})
25+
}
26+
</script>

src-tauri/src/downloads/game_download.rs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
use std::future::Future;
2+
use std::str::FromStr;
23
use std::sync::{Arc, Mutex};
34
use std::sync::atomic::AtomicUsize;
5+
use log::info;
46
use serde::{Deserialize, Serialize};
57
use versions::Version;
6-
use crate::AppState;
8+
use crate::{AppState, DB};
9+
use crate::auth::generate_authorization_header;
10+
use crate::db::DatabaseImpls;
711
use crate::downloads::progress::ProgressChecker;
812

913
#[derive(Serialize, Deserialize)]
@@ -32,6 +36,7 @@ pub enum GameDownloadError {
3236
ManifestAlreadyExists,
3337
ManifestDoesNotExist,
3438
ManifestDownloadError,
39+
StatusError(u16)
3540
}
3641
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Ord, PartialOrd)]
3742
#[serde(rename_all="camelCase")]
@@ -72,7 +77,39 @@ impl GameDownload {
7277
if self.manifest.is_some() {
7378
return Err(GameDownloadError::ManifestAlreadyExists);
7479
}
75-
todo!() // Need to actually download the manifest
80+
81+
info!("Getting url components");
82+
let base_url = DB.fetch_base_url();
83+
let manifest_url = base_url
84+
.join(
85+
format!(
86+
"/api/v1/client/metadata/manifest?id={}&version={}",
87+
self.id,
88+
self.version.to_string()
89+
)
90+
.as_str()
91+
)
92+
.unwrap();
93+
94+
info!("Generating authorization header");
95+
let header = generate_authorization_header();
96+
97+
info!("Generating & sending client");
98+
let client = reqwest::blocking::Client::new();
99+
let response = client
100+
.get(manifest_url.to_string())
101+
.header("Authorization", header)
102+
.send()
103+
.unwrap();
104+
105+
info!("Got status");
106+
if response.status() != 200 {
107+
return Err(GameDownloadError::StatusError(response.status().as_u16()));
108+
}
109+
110+
info!("{:?}", response.text());
111+
112+
Ok(())
76113
}
77114
pub fn change_state(&self, state: GameDownloadState) {
78115
let mut lock = self.state.lock().unwrap();
@@ -92,16 +129,23 @@ fn download_game_chunk(ctx: GameChunkCtx) {
92129
#[tauri::command]
93130
pub async fn start_game_download(
94131
game_id: String,
95-
game_version: Version,
132+
game_version: String,
96133
max_threads: usize,
97134
state: tauri::State<'_, Mutex<AppState>>,
98135
) -> Result<(), GameDownloadError> {
99-
let mut download = Arc::new(GameDownload::new(game_id, game_version));
100-
let mut app_state = state.lock().unwrap();
136+
137+
info!("Triggered Game Download");
138+
139+
let mut download = Arc::new(GameDownload::new(game_id, Version::from_str(&*game_version).unwrap()));
140+
//let mut app_state = state.lock().unwrap();
101141

102142
let tmp = download.clone();
103-
let manifest = &tmp.manifest;
143+
//let manifest = &tmp.manifest;
144+
145+
let res = download.download_manifest().await;
104146

147+
res
148+
/*
105149
let Some(unlocked) = manifest else { return Err(GameDownloadError::ManifestDoesNotExist) };
106150
let lock = unlocked.lock().unwrap();
107151
@@ -119,5 +163,7 @@ pub async fn start_game_download(
119163
120164
app_state.game_downloads.push(download.clone());
121165
download.download(max_threads, chunks).await
166+
167+
*/
122168
}
123169

src-tauri/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::{
2222
use std::sync::Arc;
2323
use tauri_plugin_deep_link::DeepLinkExt;
2424
use crate::db::DatabaseImpls;
25-
use crate::downloads::game_download::GameDownload;
25+
use crate::downloads::game_download::{start_game_download, GameDownload};
2626

2727
#[derive(Clone, Copy, Serialize)]
2828
pub enum AppStatus {
@@ -110,6 +110,8 @@ pub fn run() {
110110
// Library
111111
fetch_library,
112112
fetch_game,
113+
// Downloads
114+
start_game_download
113115
])
114116
.plugin(tauri_plugin_shell::init())
115117
.setup(|app| {

0 commit comments

Comments
 (0)