From 63cff68bdd73c8a02bc603c70f90f5ad37ee75e9 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 12 Feb 2025 15:24:05 +0000 Subject: [PATCH] wip --- src/main.rs | 21 ++++++++++++++++- src/manifest.rs | 57 ++++++++++++++++++++++++++-------------------- src/repo/github.rs | 2 ++ src/repo/mod.rs | 39 ++++++++++++++++++++++++++++++- 4 files changed, 92 insertions(+), 27 deletions(-) diff --git a/src/main.rs b/src/main.rs index 901f29d..1904eab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,11 @@ mod repo; use crate::manifest::Manifest; use crate::repo::Repo; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, bail, Result}; use clap::Parser; use config::{Config, File, FileSourceFile}; use log::info; +use nostr_sdk::{EventBuilder, JsonUtil, Keys}; use std::path::PathBuf; #[derive(clap::Parser)] @@ -53,6 +54,24 @@ async fn main() -> Result<()> { { return Ok(()); } + + let key = dialoguer::Password::new() + .with_prompt("Enter nsec:") + .interact()?; + + let key = if let Ok(nsec) = Keys::parse(&key) { + nsec + } else { + bail!("Invalid private key") + }; + + let ev: EventBuilder = (&manifest).into(); + + // create release + + // publish application + let ev = ev.build(key.public_key).sign_with_keys(&key)?; + info!("{}", ev.as_json()); } Ok(()) diff --git a/src/manifest.rs b/src/manifest.rs index 58f8665..341c9f0 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -1,3 +1,4 @@ +use nostr_sdk::{Event, EventBuilder, Kind, Tag}; use serde::Deserialize; #[derive(Deserialize)] @@ -14,6 +15,9 @@ pub struct Manifest { /// Repo URL pub repository: Option, + /// SPDX license code + pub license: Option, + /// App icon pub icon: Option, @@ -24,29 +28,32 @@ pub struct Manifest { pub tags: Vec, } -#[derive(Deserialize)] -pub enum Platform { - Android { - arch: Architecture - }, - IOS, - MacOS { - arch: Architecture - }, - Windows { - arch: Architecture - }, - Linux { - arch: Architecture - }, - Web -} +impl Into for &Manifest { + fn into(self) -> EventBuilder { + let mut b = EventBuilder::new( + Kind::Custom(32_267), + self.description.clone().unwrap_or_default(), + ) + .tags([ + Tag::parse(["d", &self.id]).unwrap(), + Tag::parse(["name", &self.name]).unwrap(), + ]); + if let Some(icon) = &self.icon { + b = b.tag(Tag::parse(["icon", icon]).unwrap()); + } + if let Some(repository) = &self.repository { + b = b.tag(Tag::parse(["repository", repository]).unwrap()); + } + if let Some(license) = &self.license { + b = b.tag(Tag::parse(["license", license]).unwrap()); + } + for image in &self.images { + b = b.tag(Tag::parse(["image", image]).unwrap()); + } + for tag in &self.tags { + b = b.tag(Tag::parse(["t", tag]).unwrap()); + } -#[derive(Deserialize)] -pub enum Architecture { - ARMv7, - ARMv8, - X86, - AMD64, - ARM64 -} \ No newline at end of file + b + } +} diff --git a/src/repo/github.rs b/src/repo/github.rs index af0cd9e..367cdbf 100644 --- a/src/repo/github.rs +++ b/src/repo/github.rs @@ -93,7 +93,9 @@ impl TryFrom<&GithubReleaseArtifact> for RepoArtifact { name: value.name.clone(), size: value.size, content_type: value.content_type.clone(), + platform: Platform::IOS, location: RepoResource::Remote(value.browser_download_url.clone()), + metadata: (), }) } } diff --git a/src/repo/mod.rs b/src/repo/mod.rs index f1c631b..8665e31 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -1,8 +1,9 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use crate::manifest::Manifest; use crate::repo::github::GithubRepo; use anyhow::{anyhow, bail, Result}; use semver::Version; +use serde::Deserialize; mod github; @@ -12,6 +13,34 @@ pub struct RepoArtifact { pub size: u64, pub location: RepoResource, pub content_type: String, + pub platform: Platform, + pub metadata: ArtifactMetadata +} + +pub enum ArtifactMetadata { + APK { + version_code: u32, + min_sdk_version: u32, + target_sdk_version: u32, + sig_hash: String, + } +} + +pub enum Platform { + Android { arch: Architecture }, + IOS, + MacOS { arch: Architecture }, + Windows { arch: Architecture }, + Linux { arch: Architecture }, + Web, +} + +pub enum Architecture { + ARMv7, + ARMv8, + X86, + AMD64, + ARM64, } /// A local/remote location where the artifact is located @@ -49,3 +78,11 @@ impl TryInto> for &Manifest { Ok(Box::new(GithubRepo::from_url(repo)?)) } } + +async fn load_artifact_url(url: &str) -> Result { + +} + +async fn load_artifact(path: &Path) -> Result { + +} \ No newline at end of file