feat(channel): impl fetcher constructor and use owned values
This commit is contained in:
parent
106fee3d46
commit
b94972e183
2 changed files with 23 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
use langtag::LangTag;
|
use color_eyre::eyre;
|
||||||
|
use langtag::LangTagBuf;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_with::serde_as;
|
use serde_with::serde_as;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -7,13 +8,26 @@ use crate::{ManifestInfo, app::arch::Arch};
|
||||||
|
|
||||||
use super::{ChannelItemType, Payload};
|
use super::{ChannelItemType, Payload};
|
||||||
|
|
||||||
|
pub const CHANNEL_ENDPOINT_URL: &str = "https://aka.ms/vs/17/release/channel";
|
||||||
|
pub const PREVIEW_CHANNEL_ENDPOINT_URL: &str = "https://aka.ms/vs/17/pre/channel";
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Manifest<'manifest> {
|
pub struct Manifest {
|
||||||
pub manifest_version: String,
|
pub manifest_version: String,
|
||||||
pub info: ChannelManifestInfo,
|
pub info: ChannelManifestInfo,
|
||||||
#[serde(borrow)]
|
pub channel_items: Vec<ChannelItem>,
|
||||||
pub channel_items: Vec<ChannelItem<'manifest>>,
|
}
|
||||||
|
|
||||||
|
impl Manifest {
|
||||||
|
pub fn from_endpoint(endpoint: Url) -> eyre::Result<Self> {
|
||||||
|
if !endpoint.domain().is_some_and(|domain| domain == "aka.ms") {
|
||||||
|
tracing::warn!("Endpoint is not a Microsoft shortened link");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut resp = ureq::get(endpoint.as_str()).call()?;
|
||||||
|
Ok(resp.body_mut().read_json::<Self>()?)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ManifestInfo! {
|
ManifestInfo! {
|
||||||
|
@ -29,13 +43,12 @@ ManifestInfo! {
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[serde_as]
|
#[serde_as]
|
||||||
pub struct ChannelItem<'lang> {
|
pub struct ChannelItem {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub version: String,
|
pub version: String,
|
||||||
pub r#type: ChannelItemType,
|
pub r#type: ChannelItemType,
|
||||||
pub payloads: Option<Vec<Payload>>,
|
pub payloads: Option<Vec<Payload>>,
|
||||||
#[serde(borrow)]
|
pub localized_resoures: Option<Vec<LocalizedResource>>,
|
||||||
pub localized_resoures: Option<Vec<LocalizedResource<'lang>>>,
|
|
||||||
#[serde_as(as = "FromStr")]
|
#[serde_as(as = "FromStr")]
|
||||||
pub chip: Arch,
|
pub chip: Arch,
|
||||||
#[serde_as(as = "FromStr")]
|
#[serde_as(as = "FromStr")]
|
||||||
|
@ -47,9 +60,8 @@ pub struct ChannelItem<'lang> {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct LocalizedResource<'lang> {
|
pub struct LocalizedResource {
|
||||||
#[serde(borrow)]
|
pub language: LangTagBuf,
|
||||||
pub language: &'lang LangTag,
|
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub license: Url,
|
pub license: Url,
|
||||||
|
|
|
@ -57,4 +57,4 @@ pub struct Payload {
|
||||||
pub size: usize,
|
pub size: usize,
|
||||||
pub url: Url,
|
pub url: Url,
|
||||||
pub signer: Option<Vec<SignerRef>>,
|
pub signer: Option<Vec<SignerRef>>,
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue