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_with::serde_as;
|
||||
use url::Url;
|
||||
|
@ -7,13 +8,26 @@ use crate::{ManifestInfo, app::arch::Arch};
|
|||
|
||||
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)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Manifest<'manifest> {
|
||||
pub struct Manifest {
|
||||
pub manifest_version: String,
|
||||
pub info: ChannelManifestInfo,
|
||||
#[serde(borrow)]
|
||||
pub channel_items: Vec<ChannelItem<'manifest>>,
|
||||
pub channel_items: Vec<ChannelItem>,
|
||||
}
|
||||
|
||||
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! {
|
||||
|
@ -29,13 +43,12 @@ ManifestInfo! {
|
|||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde_as]
|
||||
pub struct ChannelItem<'lang> {
|
||||
pub struct ChannelItem {
|
||||
pub id: String,
|
||||
pub version: String,
|
||||
pub r#type: ChannelItemType,
|
||||
pub payloads: Option<Vec<Payload>>,
|
||||
#[serde(borrow)]
|
||||
pub localized_resoures: Option<Vec<LocalizedResource<'lang>>>,
|
||||
pub localized_resoures: Option<Vec<LocalizedResource>>,
|
||||
#[serde_as(as = "FromStr")]
|
||||
pub chip: Arch,
|
||||
#[serde_as(as = "FromStr")]
|
||||
|
@ -47,9 +60,8 @@ pub struct ChannelItem<'lang> {
|
|||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LocalizedResource<'lang> {
|
||||
#[serde(borrow)]
|
||||
pub language: &'lang LangTag,
|
||||
pub struct LocalizedResource {
|
||||
pub language: LangTagBuf,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub license: Url,
|
||||
|
|
Loading…
Add table
Reference in a new issue