-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3edfcf9
commit 4ef0c88
Showing
23 changed files
with
330 additions
and
146 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
|
||
/** | ||
* Service configuration. | ||
*/ | ||
export type Config = { | ||
/** | ||
* Node alias. | ||
*/ | ||
publicKey: string; | ||
/** | ||
* Node alias. | ||
*/ | ||
alias: string; | ||
/** | ||
* Default seeding policy. | ||
*/ | ||
seedingPolicy: | ||
| { default: "allow"; scope: "followed" | "all" } | ||
| { default: "block" }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
import type { SupportedPayloads } from "./SupportedPayloads"; | ||
|
||
/** | ||
* Repos info. | ||
*/ | ||
export type RepoInfo = { | ||
payloads: SupportedPayloads; | ||
delegates: ({ id: string } | { id: string; alias?: string })[]; | ||
threshold: number; | ||
visibility: { type: "public" } | { type: "private"; allow?: string[] }; | ||
rid: string; | ||
seeding: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
|
||
export type SupportedPayloads = { | ||
"xyz.radicle.project"?: { | ||
data: { | ||
defaultBranch: string; | ||
description: string; | ||
name: string; | ||
}; | ||
meta: { | ||
head: string; | ||
issues: { | ||
open: number; | ||
closed: number; | ||
}; | ||
patches: { | ||
open: number; | ||
draft: number; | ||
archived: number; | ||
merged: number; | ||
}; | ||
lastCommit: number; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
|
||
export type JsonValue = | ||
| number | ||
| string | ||
| Array<JsonValue> | ||
| { [key: string]: JsonValue }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod auth; | ||
pub mod profile; | ||
pub mod repos; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::error::Error; | ||
use crate::types::config::Config; | ||
use crate::AppState; | ||
|
||
/// Get active config. | ||
#[tauri::command] | ||
pub fn config(ctx: tauri::State<AppState>) -> Result<Config, Error> { | ||
let config = Config { | ||
public_key: ctx.profile.public_key, | ||
alias: ctx.profile.config.node.alias.clone(), | ||
seeding_policy: ctx.profile.config.node.seeding_policy, | ||
}; | ||
|
||
Ok::<_, Error>(config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use radicle::storage::ReadStorage; | ||
|
||
use crate::error::Error; | ||
use crate::types; | ||
use crate::AppState; | ||
|
||
/// List all repos. | ||
#[tauri::command] | ||
pub fn list_repos(ctx: tauri::State<AppState>) -> Result<Vec<types::repo::RepoInfo>, Error> { | ||
let storage = &ctx.profile.storage; | ||
let policies = ctx.profile.policies()?; | ||
|
||
let mut repos = storage.repositories()?.into_iter().collect::<Vec<_>>(); | ||
repos.sort_by_key(|p| p.rid); | ||
|
||
let infos = repos | ||
.into_iter() | ||
.filter_map(|info| { | ||
if !policies.is_seeding(&info.rid).unwrap_or_default() { | ||
return None; | ||
} | ||
let (repo, doc) = ctx.repo(info.rid).ok()?; | ||
let repo_info = ctx.repo_info(&repo, doc).ok()?; | ||
|
||
Some(repo_info) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok::<_, Error>(infos) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use serde_json::{json, Value}; | ||
|
||
use radicle::identity; | ||
use radicle::node::AliasStore; | ||
|
||
pub(crate) struct Author<'a>(&'a identity::Did); | ||
|
||
impl<'a> Author<'a> { | ||
pub fn new(did: &'a identity::Did) -> Self { | ||
Self(did) | ||
} | ||
|
||
pub fn as_json(&self, aliases: &impl AliasStore) -> Value { | ||
aliases.alias(self.0).map_or( | ||
json!({ "id": self.0 }), | ||
|alias| json!({ "id": self.0, "alias": alias, }), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use radicle::crypto::PublicKey; | ||
use serde::Serialize; | ||
use ts_rs::TS; | ||
|
||
use radicle::node::config::DefaultSeedingPolicy; | ||
use radicle::node::Alias; | ||
|
||
/// Service configuration. | ||
#[derive(Debug, Clone, TS, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
#[ts(export)] | ||
pub struct Config { | ||
/// Node Public Key in NID format. | ||
#[ts(as = "String")] | ||
pub public_key: PublicKey, | ||
/// Node alias. | ||
#[ts(as = "String")] | ||
pub alias: Alias, | ||
/// Default seeding policy. | ||
#[serde(default)] | ||
#[ts(type = "{ default: 'allow', scope: 'followed' | 'all' } | { default: 'block' }")] | ||
pub seeding_policy: DefaultSeedingPolicy, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod config; | ||
pub mod repo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use serde::Serialize; | ||
use serde_json::Value; | ||
use ts_rs::TS; | ||
|
||
use radicle::identity::RepoId; | ||
|
||
/// Repos info. | ||
#[derive(Serialize, TS)] | ||
#[ts(export)] | ||
pub struct RepoInfo { | ||
pub payloads: SupportedPayloads, | ||
#[ts(type = "({ id: string } | { id: string, alias?: string })[]")] | ||
pub delegates: Vec<Value>, | ||
pub threshold: usize, | ||
#[ts(type = "{ type: 'public' } | { type: 'private', allow?: string[] }")] | ||
pub visibility: radicle::identity::Visibility, | ||
#[ts(as = "String")] | ||
pub rid: RepoId, | ||
pub seeding: usize, | ||
} | ||
|
||
#[derive(Serialize, TS)] | ||
#[ts(export)] | ||
pub struct SupportedPayloads { | ||
#[serde(rename = "xyz.radicle.project")] | ||
#[serde(default, skip_serializing_if = "Option::is_none")] | ||
#[ts(optional)] | ||
#[ts(type = r#"{ | ||
data: { | ||
defaultBranch: string, | ||
description: string, | ||
name: string, | ||
}, | ||
meta: { | ||
head: string, | ||
issues: { | ||
open: number, | ||
closed: number, | ||
}, | ||
patches: { | ||
open: number, | ||
draft: number, | ||
archived: number, | ||
merged: number, | ||
} | ||
lastCommit: number, | ||
} | ||
}"#)] | ||
pub project: Option<Value>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.