mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Adding staged user id support to rust SDK
This commit is contained in:
@@ -48,6 +48,7 @@ bitflags.workspace = true
|
||||
rand.workspace = true
|
||||
sha1.workspace = true
|
||||
sha2.workspace = true
|
||||
guid_create = true
|
||||
|
||||
# typescript
|
||||
ts-rs = { workspace = true, optional = true }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::path::PathBuf;
|
||||
use semver::Version;
|
||||
use guid_create::GUID;
|
||||
use crate::{
|
||||
bundle::{self, Manifest},
|
||||
util, Error,
|
||||
@@ -211,6 +212,11 @@ impl VelopackLocator {
|
||||
self.manifest.version.clone()
|
||||
}
|
||||
|
||||
/// Returns unique identifier for this user which is used to calculate whether this user is eligible for staged roll outs.
|
||||
pub fn get_staged_user_id(&self) -> String {
|
||||
self.get_or_create_staged_user_id().clone()
|
||||
}
|
||||
|
||||
/// Returns the current app's version as a string containing all parts.
|
||||
pub fn get_manifest_version_full_string(&self) -> String {
|
||||
self.manifest.version.to_string()
|
||||
@@ -290,6 +296,20 @@ impl VelopackLocator {
|
||||
fn path_as_string(path: &PathBuf) -> String {
|
||||
path.to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
fn get_or_create_staged_user_id(&self) -> String {
|
||||
let packages_dir = self.get_packages_dir();
|
||||
let beta_id_path = packages_dir.join(".betaId");
|
||||
if beta_id_path.exists() {
|
||||
info!("Found existing staged user id...");
|
||||
if let Ok(beta_id) = std::fs::read_to_string(&beta_id_path) {
|
||||
return beta_id;
|
||||
}
|
||||
}
|
||||
let new_id = GUID::rand();
|
||||
std::fs::write(&beta_id_path, &new_id).expect("Unable to write .betaId file");
|
||||
new_id
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a paths object containing default / ideal paths for a given root directory
|
||||
|
||||
@@ -256,6 +256,7 @@ impl UpdateManager {
|
||||
let allow_downgrade = self.options.AllowVersionDowngrade;
|
||||
let app_channel = self.locator.get_manifest_channel();
|
||||
let app_version = self.locator.get_manifest_version();
|
||||
let staged_user_id = self.locator.get_staged_user_id();
|
||||
let feed = self.get_release_feed()?;
|
||||
let assets = feed.Assets;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user