github source v1
This commit is contained in:
parent
71f89dde9c
commit
caf870d05e
50 changed files with 4139 additions and 131 deletions
24
crates/aim-core/src/metadata/document.rs
Normal file
24
crates/aim-core/src/metadata/document.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MetadataDocument {
|
||||
pub url: String,
|
||||
pub content_type: Option<String>,
|
||||
pub contents: Vec<u8>,
|
||||
}
|
||||
|
||||
impl MetadataDocument {
|
||||
pub fn plain_text(url: &str, contents: &[u8]) -> Self {
|
||||
Self {
|
||||
url: url.to_owned(),
|
||||
content_type: Some("text/plain".to_owned()),
|
||||
contents: contents.to_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn yaml(url: &str, contents: &[u8]) -> Self {
|
||||
Self {
|
||||
url: url.to_owned(),
|
||||
content_type: Some("application/yaml".to_owned()),
|
||||
contents: contents.to_vec(),
|
||||
}
|
||||
}
|
||||
}
|
||||
30
crates/aim-core/src/metadata/electron_builder.rs
Normal file
30
crates/aim-core/src/metadata/electron_builder.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use crate::domain::update::{MetadataHints, ParsedMetadata, ParsedMetadataKind};
|
||||
use crate::metadata::document::MetadataDocument;
|
||||
|
||||
pub fn parse(document: &MetadataDocument) -> ParsedMetadata {
|
||||
let contents = String::from_utf8_lossy(&document.contents);
|
||||
let version = extract_value(&contents, "version:");
|
||||
let path = extract_value(&contents, "path:").or_else(|| extract_value(&contents, "url:"));
|
||||
let checksum = extract_value(&contents, "sha512:");
|
||||
|
||||
ParsedMetadata {
|
||||
kind: ParsedMetadataKind::ElectronBuilder,
|
||||
hints: MetadataHints {
|
||||
version,
|
||||
primary_download: path,
|
||||
checksum,
|
||||
architecture: Some("x86_64".to_owned()),
|
||||
channel_label: Some("latest".to_owned()),
|
||||
},
|
||||
warnings: Vec::new(),
|
||||
confidence: 90,
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_value(contents: &str, prefix: &str) -> Option<String> {
|
||||
contents
|
||||
.lines()
|
||||
.find_map(|line| line.trim().strip_prefix(prefix).map(str::trim))
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(ToOwned::to_owned)
|
||||
}
|
||||
7
crates/aim-core/src/metadata/mod.rs
Normal file
7
crates/aim-core/src/metadata/mod.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
mod document;
|
||||
mod electron_builder;
|
||||
mod parser;
|
||||
mod zsync;
|
||||
|
||||
pub use document::MetadataDocument;
|
||||
pub use parser::parse_document;
|
||||
22
crates/aim-core/src/metadata/parser.rs
Normal file
22
crates/aim-core/src/metadata/parser.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use crate::domain::update::{MetadataHints, ParsedMetadata, ParsedMetadataKind};
|
||||
use crate::metadata::document::MetadataDocument;
|
||||
|
||||
pub fn parse_document(document: &MetadataDocument) -> Result<ParsedMetadata, MetadataParseError> {
|
||||
if document.url.ends_with("latest-linux.yml") || document.url.ends_with("latest-linux.yaml") {
|
||||
return Ok(super::electron_builder::parse(document));
|
||||
}
|
||||
|
||||
if document.url.ends_with(".zsync") {
|
||||
return Ok(super::zsync::parse(document));
|
||||
}
|
||||
|
||||
Ok(ParsedMetadata {
|
||||
kind: ParsedMetadataKind::Unknown,
|
||||
hints: MetadataHints::default(),
|
||||
warnings: vec!["unsupported metadata document".to_owned()],
|
||||
confidence: 0,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum MetadataParseError {}
|
||||
38
crates/aim-core/src/metadata/zsync.rs
Normal file
38
crates/aim-core/src/metadata/zsync.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use crate::domain::update::{MetadataHints, ParsedMetadata, ParsedMetadataKind};
|
||||
use crate::metadata::document::MetadataDocument;
|
||||
|
||||
pub fn parse(document: &MetadataDocument) -> ParsedMetadata {
|
||||
let contents = String::from_utf8_lossy(&document.contents);
|
||||
let url = extract_field(&contents, "URL:");
|
||||
let filename = extract_field(&contents, "Filename:");
|
||||
|
||||
ParsedMetadata {
|
||||
kind: ParsedMetadataKind::Zsync,
|
||||
hints: MetadataHints {
|
||||
version: filename
|
||||
.as_ref()
|
||||
.and_then(|value| version_from_filename(value)),
|
||||
primary_download: url.or(filename),
|
||||
checksum: None,
|
||||
architecture: Some("x86_64".to_owned()),
|
||||
channel_label: Some("zsync".to_owned()),
|
||||
},
|
||||
warnings: Vec::new(),
|
||||
confidence: 75,
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_field(contents: &str, prefix: &str) -> Option<String> {
|
||||
contents
|
||||
.lines()
|
||||
.find_map(|line| line.trim().strip_prefix(prefix).map(str::trim))
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(ToOwned::to_owned)
|
||||
}
|
||||
|
||||
fn version_from_filename(filename: &str) -> Option<String> {
|
||||
filename
|
||||
.split('-')
|
||||
.find(|segment| segment.chars().any(|ch| ch.is_ascii_digit()) && segment.contains('.'))
|
||||
.map(|value| value.trim_end_matches(".AppImage").to_owned())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue