mirror of
https://github.com/uqbar-dao/nectar.git
synced 2025-01-03 14:17:20 +03:00
app_store: erroring fixes
This commit is contained in:
parent
a5ed152747
commit
d83e8e2ade
@ -176,7 +176,7 @@ fn make_widget() -> String {
|
||||
/// - download a listed app: POST /apps/:id/download
|
||||
/// - install a downloaded app: POST /apps/:id/install
|
||||
/// - uninstall/delete a downloaded app: DELETE /apps/:id
|
||||
/// - update a downloaded app: PUT /apps/:id FIX
|
||||
/// - update a downloaded app: POST /apps/:id/update
|
||||
/// - approve capabilities for a downloaded app: POST /apps/:id/caps
|
||||
/// - start mirroring a downloaded app: PUT /apps/:id/mirror
|
||||
/// - stop mirroring a downloaded app: DELETE /apps/:id/mirror
|
||||
@ -373,13 +373,23 @@ fn serve_paths(
|
||||
.ok_or(anyhow::anyhow!("missing blob"))?
|
||||
.bytes;
|
||||
let body_json: serde_json::Value = serde_json::from_slice(&body).unwrap_or_default();
|
||||
let mirrors: &Vec<NodeId> = pkg_listing
|
||||
let mirrors: Option<&Vec<NodeId>> = pkg_listing
|
||||
.metadata
|
||||
.as_ref()
|
||||
.expect("Package does not have metadata")
|
||||
.properties
|
||||
.mirrors
|
||||
.as_ref();
|
||||
.and_then(|metadata| Some(metadata.properties.mirrors.as_ref()));
|
||||
|
||||
let mirrors = match mirrors {
|
||||
Some(m) => m,
|
||||
None => {
|
||||
return Ok((
|
||||
StatusCode::BAD_REQUEST,
|
||||
None,
|
||||
"Package does not have metadata or mirrors"
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let download_from = body_json
|
||||
.get("download_from")
|
||||
|
@ -505,6 +505,9 @@ fn handle_receive_download_package(
|
||||
};
|
||||
// check the version hash for this download against requested!
|
||||
let download_hash = utils::sha_256_hash(&blob.bytes);
|
||||
|
||||
// note TEMP: erroring here, to not mess up internal installed state
|
||||
// longer term, separate downloads and installs logic.
|
||||
let verified = match requested_package.desired_version_hash {
|
||||
Some(hash) => {
|
||||
if download_hash != hash {
|
||||
@ -517,8 +520,9 @@ fn handle_receive_download_package(
|
||||
}
|
||||
None => match state.packages.get(package_id) {
|
||||
None => {
|
||||
println!("downloaded package cannot be found onchain, proceeding with unverified download");
|
||||
false
|
||||
return Err(anyhow::anyhow!(
|
||||
"downloaded package cannot be found onchain, rejecting unverified download"
|
||||
));
|
||||
}
|
||||
Some(package_listing) => {
|
||||
if let Some(metadata) = &package_listing.metadata {
|
||||
@ -527,16 +531,15 @@ fn handle_receive_download_package(
|
||||
.code_hashes
|
||||
.get(&metadata.properties.current_version);
|
||||
if Some(&download_hash) != latest_hash {
|
||||
println!(
|
||||
return Err(anyhow::anyhow!(
|
||||
"downloaded package is not latest version \
|
||||
download hash: {download_hash}, latest hash: {latest_hash:?} \
|
||||
proceeding with unverified download"
|
||||
);
|
||||
rejecting unverified download"
|
||||
));
|
||||
}
|
||||
false
|
||||
} else {
|
||||
println!("downloaded package has no metadata to check validity against, proceeding with unverified download");
|
||||
false
|
||||
return Err(anyhow::anyhow!("downloaded package has no metadata to check validity against, rejecting unverified download"));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -74,9 +74,7 @@
|
||||
}
|
||||
|
||||
.app-actions-buttons button {
|
||||
flex: 1 0 auto;
|
||||
min-width: 120px;
|
||||
/* Ensure buttons have a minimum width */
|
||||
}
|
||||
|
||||
.mirror-selection {
|
||||
|
@ -50,16 +50,28 @@ export default function AppPage() {
|
||||
}, [app]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("Checking app version updates...");
|
||||
if (app && app.metadata?.properties?.code_hashes) {
|
||||
const versions = Object.entries(app.metadata.properties.code_hashes);
|
||||
console.log("Available versions:", versions);
|
||||
if (versions.length > 0) {
|
||||
const [latestVersion, latestHash] = versions[versions.length - 1];
|
||||
console.log(`Latest version found: ${latestVersion} with hash ${latestHash}`);
|
||||
setLatestVersion(latestVersion);
|
||||
setUpdateAvailable(app.state?.our_version !== latestHash);
|
||||
const isUpdateAvailable = app.state?.our_version !== latestHash;
|
||||
console.log(`Update available: ${isUpdateAvailable}`);
|
||||
setUpdateAvailable(isUpdateAvailable);
|
||||
}
|
||||
} else {
|
||||
console.log("No code hashes available in metadata.");
|
||||
// app metadata
|
||||
console.log("App metadata:", app);
|
||||
// app state
|
||||
console.log("App state:", app.state);
|
||||
// app publisher
|
||||
console.log("App publisher:", app.publisher);
|
||||
}
|
||||
}, [app]);
|
||||
|
||||
if (!app) {
|
||||
return <div className="app-page"><h4>App details not found for {id}</h4></div>;
|
||||
}
|
||||
@ -314,6 +326,21 @@ export default function AppPage() {
|
||||
<>
|
||||
<button onClick={handleLaunch} className="primary"><FaPlay /> Launch</button>
|
||||
{updateAvailable && (
|
||||
<>
|
||||
<div className="mirror-selection">
|
||||
<select
|
||||
value={selectedMirror || ''}
|
||||
onChange={(e) => setSelectedMirror(e.target.value)}
|
||||
disabled={isUpdating}
|
||||
>
|
||||
<option value="" disabled>Select Mirror</option>
|
||||
{Object.entries(mirrorStatuses).map(([mirror, status]) => (
|
||||
<option key={mirror} value={mirror} disabled={!status?.is_online}>
|
||||
{mirror} {status?.is_online ? '(Online)' : '(Offline)'}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleUpdate}
|
||||
className={`secondary ${isUpdating ? 'updating' : ''}`}
|
||||
@ -329,6 +356,7 @@ export default function AppPage() {
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
<button onClick={handleUninstall} className="secondary"><FaTrash /> Uninstall</button>
|
||||
</>
|
||||
|
Loading…
Reference in New Issue
Block a user