Skip to main content

egs_api/facade/
assets.rs

1use crate::EpicGames;
2use crate::api::error::EpicAPIError;
3use crate::api::types::artifact_service::ArtifactServiceTicket;
4use crate::api::types::asset_info::AssetInfo;
5use crate::api::types::asset_manifest::AssetManifest;
6use crate::api::types::download_manifest::DownloadManifest;
7use crate::api::types::engine_blob;
8use crate::api::types::epic_asset::EpicAsset;
9
10impl EpicGames {
11    /// Like [`list_assets`](Self::list_assets), but returns a `Result` instead of swallowing errors.
12    pub async fn try_list_assets(
13        &mut self,
14        platform: Option<String>,
15        label: Option<String>,
16    ) -> Result<Vec<EpicAsset>, EpicAPIError> {
17        self.egs.assets(platform, label).await
18    }
19
20    /// List all owned assets.
21    ///
22    /// Defaults to platform="Windows" and label="Live" if not specified.
23    /// Returns empty `Vec` on API errors.
24    pub async fn list_assets(
25        &mut self,
26        platform: Option<String>,
27        label: Option<String>,
28    ) -> Vec<EpicAsset> {
29        self.try_list_assets(platform, label)
30            .await
31            .unwrap_or_else(|_| Vec::new())
32    }
33
34    /// Like [`asset_manifest`](Self::asset_manifest), but returns a `Result` instead of swallowing errors.
35    pub async fn try_asset_manifest(
36        &mut self,
37        platform: Option<String>,
38        label: Option<String>,
39        namespace: Option<String>,
40        item_id: Option<String>,
41        app: Option<String>,
42    ) -> Result<AssetManifest, EpicAPIError> {
43        self.egs
44            .asset_manifest(platform, label, namespace, item_id, app)
45            .await
46    }
47
48    /// Fetch asset manifest with CDN download URLs.
49    ///
50    /// Defaults to platform="Windows" and label="Live" if not specified.
51    /// Returns `None` on API errors.
52    pub async fn asset_manifest(
53        &mut self,
54        platform: Option<String>,
55        label: Option<String>,
56        namespace: Option<String>,
57        item_id: Option<String>,
58        app: Option<String>,
59    ) -> Option<AssetManifest> {
60        self.try_asset_manifest(platform, label, namespace, item_id, app)
61            .await
62            .ok()
63    }
64
65    /// Like [`asset_info`](Self::asset_info), but returns a `Result` instead of swallowing errors.
66    pub async fn try_asset_info(
67        &mut self,
68        asset: &EpicAsset,
69    ) -> Result<Option<AssetInfo>, EpicAPIError> {
70        let mut info = self.egs.asset_info(asset).await?;
71        log::debug!(
72            "try_asset_info: catalog_item_id='{}', HashMap keys={:?}",
73            asset.catalog_item_id,
74            info.keys().collect::<Vec<_>>()
75        );
76        Ok(info.remove(asset.catalog_item_id.as_str()))
77    }
78
79    /// Fetch catalog metadata for an asset (includes DLC tree).
80    ///
81    /// Returns `None` on API errors.
82    pub async fn asset_info(&mut self, asset: &EpicAsset) -> Option<AssetInfo> {
83        self.try_asset_info(asset).await.ok().flatten()
84    }
85
86    /// Parse download manifests from all CDN mirrors.
87    ///
88    /// Fetches from all mirrors, parses binary/JSON format, and populates custom fields
89    /// (BaseUrl, CatalogItemId, etc.). Returns empty `Vec` on API errors.
90    pub async fn asset_download_manifests(&self, manifest: AssetManifest) -> Vec<DownloadManifest> {
91        self.egs.asset_download_manifests(manifest).await
92    }
93
94    /// Fetch an artifact service ticket for manifest retrieval via EOS Helper.
95    ///
96    /// The `sandbox_id` is typically the game's namespace and `artifact_id`
97    /// is the app name. Returns a signed ticket for use with
98    /// [`game_manifest_by_ticket`](Self::game_manifest_by_ticket).
99    pub async fn artifact_service_ticket(
100        &self,
101        sandbox_id: &str,
102        artifact_id: &str,
103        label: Option<&str>,
104        platform: Option<&str>,
105    ) -> Result<ArtifactServiceTicket, EpicAPIError> {
106        self.egs
107            .artifact_service_ticket(sandbox_id, artifact_id, label, platform)
108            .await
109    }
110
111    /// Fetch a game manifest using a signed artifact service ticket.
112    ///
113    /// Alternative to [`asset_manifest`](Self::asset_manifest) using ticket-based
114    /// auth from the EOS Helper service.
115    pub async fn game_manifest_by_ticket(
116        &self,
117        artifact_id: &str,
118        signed_ticket: &str,
119        label: Option<&str>,
120        platform: Option<&str>,
121    ) -> Result<AssetManifest, EpicAPIError> {
122        self.egs
123            .game_manifest_by_ticket(artifact_id, signed_ticket, label, platform)
124            .await
125    }
126
127    /// Fetch launcher manifests for self-update checks.
128    pub async fn launcher_manifests(
129        &self,
130        platform: Option<&str>,
131        label: Option<&str>,
132    ) -> Result<AssetManifest, EpicAPIError> {
133        self.egs.launcher_manifests(platform, label).await
134    }
135
136    /// Try to fetch a delta manifest for optimized patching between builds.
137    ///
138    /// Returns `None` if no delta is available or the builds are identical.
139    pub async fn delta_manifest(
140        &self,
141        base_url: &str,
142        old_build_id: &str,
143        new_build_id: &str,
144    ) -> Option<Vec<u8>> {
145        self.egs
146            .delta_manifest(base_url, old_build_id, new_build_id)
147            .await
148    }
149
150    /// Fetch engine version download blobs for a platform. Returns `None` on error.
151    pub async fn engine_versions(
152        &self,
153        platform: &str,
154    ) -> Option<engine_blob::EngineBlobsResponse> {
155        self.egs.engine_versions(platform).await.ok()
156    }
157
158    /// Fetch engine version download blobs. Returns full `Result`.
159    pub async fn try_engine_versions(
160        &self,
161        platform: &str,
162    ) -> Result<engine_blob::EngineBlobsResponse, EpicAPIError> {
163        self.egs.engine_versions(platform).await
164    }
165}