chore: lints
This commit is contained in:
parent
063627b1d8
commit
7f4e6d5bda
17 changed files with 58 additions and 63 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -311,6 +311,7 @@ dependencies = [
|
|||
name = "api_routes"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"db-core",
|
||||
"serde",
|
||||
]
|
||||
|
||||
|
|
|
@ -86,12 +86,12 @@ pub struct LatestResp {
|
|||
pub latest: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct SearchRepositoryReq {
|
||||
pub query: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct SearchRepositoryResp {
|
||||
pub repositories: Vec<Repository>,
|
||||
}
|
||||
|
|
2
build.rs
2
build.rs
|
@ -20,7 +20,7 @@ use std::process::Command;
|
|||
|
||||
fn main() {
|
||||
let output = Command::new("git")
|
||||
.args(&["rev-parse", "HEAD"])
|
||||
.args(["rev-parse", "HEAD"])
|
||||
.output()
|
||||
.expect("error in git command, is git installed?");
|
||||
let git_hash = String::from_utf8(output.stdout).unwrap();
|
||||
|
|
|
@ -58,14 +58,14 @@ pub mod dev {
|
|||
pub use async_trait::async_trait;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
/// Data related to a Starchart instance
|
||||
pub struct Starchart {
|
||||
/// URL of the Starchart instance
|
||||
pub instance_url: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
/// create a new forge on the database
|
||||
pub struct CreateForge<'a> {
|
||||
/// url of the Starchart instance
|
||||
|
@ -88,7 +88,7 @@ pub fn clean_url(url: &Url) -> String {
|
|||
url.as_str().to_string()
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
/// user data
|
||||
pub struct User {
|
||||
/// url of the forge instance: with scheme but remove trailing slash
|
||||
|
@ -104,7 +104,7 @@ pub struct User {
|
|||
pub import: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
/// add new user to database
|
||||
pub struct AddUser<'a> {
|
||||
/// url of the forge instance: with scheme but remove trailing slash
|
||||
|
@ -120,7 +120,7 @@ pub struct AddUser<'a> {
|
|||
pub import: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
/// add new repository to database
|
||||
pub struct AddRepository<'a> {
|
||||
/// html link to the repository
|
||||
|
@ -142,7 +142,7 @@ pub struct AddRepository<'a> {
|
|||
pub import: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
/// data representing a forge instance
|
||||
pub struct Forge {
|
||||
/// url of the Starchart instance
|
||||
|
@ -157,7 +157,7 @@ pub struct Forge {
|
|||
pub last_crawl_on: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
/// repository
|
||||
pub struct Repository {
|
||||
/// html link to the repository
|
||||
|
@ -295,7 +295,7 @@ impl Clone for Box<dyn SCDatabase> {
|
|||
}
|
||||
|
||||
/// Forge type: Gitea, Sourcehut, GitLab, etc. Support is currently only available for Gitea
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ForgeImplementation {
|
||||
/// [Gitea](https://gitea.io) softare forge
|
||||
|
|
|
@ -67,7 +67,7 @@ pub async fn adding_forge_works<'a, T: SCDatabase>(
|
|||
.await
|
||||
.unwrap());
|
||||
assert!(db
|
||||
.is_word_mini_indexed(&add_user_msg2.username)
|
||||
.is_word_mini_indexed(add_user_msg2.username)
|
||||
.await
|
||||
.unwrap());
|
||||
|
||||
|
@ -78,18 +78,18 @@ pub async fn adding_forge_works<'a, T: SCDatabase>(
|
|||
.repository_exists(add_repo_msg.name, add_repo_msg.owner, &add_repo_msg.url)
|
||||
.await
|
||||
.unwrap());
|
||||
assert!(db.is_word_mini_indexed(&add_repo_msg.owner).await.unwrap());
|
||||
assert!(db.is_word_mini_indexed(&add_repo_msg.name).await.unwrap());
|
||||
assert!(db.is_word_mini_indexed(add_repo_msg.owner).await.unwrap());
|
||||
assert!(db.is_word_mini_indexed(add_repo_msg.name).await.unwrap());
|
||||
assert!(db
|
||||
.is_word_mini_indexed(&add_repo_msg.description.unwrap())
|
||||
.is_word_mini_indexed(add_repo_msg.description.unwrap())
|
||||
.await
|
||||
.unwrap());
|
||||
assert!(db
|
||||
.is_word_mini_indexed(&add_repo_msg.website.unwrap())
|
||||
.is_word_mini_indexed(add_repo_msg.website.unwrap())
|
||||
.await
|
||||
.unwrap());
|
||||
|
||||
assert!(db.get_all_repositories(00, 1000).await.unwrap().len() >= 1);
|
||||
assert!(!db.get_all_repositories(00, 1000).await.unwrap().is_empty());
|
||||
let repo_search = db.search_repository(add_repo_msg.name).await.unwrap();
|
||||
|
||||
assert!(!repo_search.is_empty());
|
||||
|
|
|
@ -186,8 +186,8 @@ impl Database {
|
|||
for repo in repositories.drain(0..) {
|
||||
self.new_fts_repositories(
|
||||
&repo.name,
|
||||
repo.description.as_ref().map(|d| d.as_str()),
|
||||
repo.website.as_ref().map(|s| s.as_str()),
|
||||
repo.description.as_deref(),
|
||||
repo.website.as_deref(),
|
||||
&repo.html_url,
|
||||
)
|
||||
.await?;
|
||||
|
@ -675,7 +675,7 @@ impl SCDatabase for Database {
|
|||
|
||||
/// delete user
|
||||
async fn delete_user(&self, username: &str, url: &Url) -> DBResult<()> {
|
||||
let user = self.get_user(username, &url).await?;
|
||||
let user = self.get_user(username, url).await?;
|
||||
self.rm_word_from_mini_index(&user.username).await?;
|
||||
|
||||
let url = db_core::clean_url(url);
|
||||
|
@ -980,7 +980,7 @@ impl SCDatabase for Database {
|
|||
mini_index: &str,
|
||||
) -> DBResult<()> {
|
||||
// delete old index before importing fresh index
|
||||
let _ = self.rm_imported_mini_index(&starchart_instance_url).await;
|
||||
let _ = self.rm_imported_mini_index(starchart_instance_url).await;
|
||||
let url = db_core::clean_url(starchart_instance_url);
|
||||
sqlx::query!(
|
||||
"INSERT OR IGNORE INTO
|
||||
|
|
|
@ -306,7 +306,7 @@ impl Federate for PccFederate {
|
|||
/// import archive from another Starchart instance
|
||||
async fn import(
|
||||
&self,
|
||||
mut starchart_url: Url,
|
||||
starchart_url: Url,
|
||||
client: &Client,
|
||||
db: &Box<dyn SCDatabase>,
|
||||
) -> Result<(), Self::Error> {
|
||||
|
@ -365,7 +365,7 @@ impl Federate for PccFederate {
|
|||
|
||||
let user_file = instance_dir_entry
|
||||
.path()
|
||||
.join(&username)
|
||||
.join(username)
|
||||
.join(USER_INFO_FILE);
|
||||
let user_file_content = fs::read_to_string(user_file).await.unwrap();
|
||||
let mut user: AddUser<'_> = serde_yaml::from_str(&user_file_content).unwrap();
|
||||
|
@ -376,7 +376,7 @@ impl Federate for PccFederate {
|
|||
if !self.user_exists(username, &instance.url).await.unwrap() {
|
||||
let user_file = instance_dir_entry
|
||||
.path()
|
||||
.join(&username)
|
||||
.join(username)
|
||||
.join(USER_INFO_FILE);
|
||||
let user_file_content = fs::read_to_string(user_file).await.unwrap();
|
||||
let mut user: AddUser<'_> = serde_yaml::from_str(&user_file_content).unwrap();
|
||||
|
|
|
@ -145,16 +145,12 @@ impl Repository {
|
|||
.get("en")
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.short_description
|
||||
.as_ref()
|
||||
.map(|s| s.as_str());
|
||||
.short_description.as_deref();
|
||||
let website = self
|
||||
.description
|
||||
.get("en")
|
||||
.unwrap()
|
||||
.documentation
|
||||
.as_ref()
|
||||
.map(|s| s.as_str());
|
||||
.documentation.as_deref();
|
||||
AddRepository {
|
||||
html_link: self.url.as_str(),
|
||||
tags,
|
||||
|
|
|
@ -95,21 +95,21 @@ pub struct Repository {
|
|||
pub repo_transfer: Option<Team>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct InternalIssueTracker {
|
||||
pub enable_time_tracker: bool,
|
||||
pub allow_only_contributors_to_track_time: bool,
|
||||
pub enable_issue_dependencies: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RepoTransfer {
|
||||
pub doer: User,
|
||||
pub recipient: User,
|
||||
pub teams: Option<Team>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Hash, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Hash, Deserialize)]
|
||||
pub struct Organization {
|
||||
pub avatar_url: String,
|
||||
pub description: String,
|
||||
|
@ -122,7 +122,7 @@ pub struct Organization {
|
|||
pub website: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Hash, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Hash, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Permission {
|
||||
None,
|
||||
|
@ -132,7 +132,7 @@ pub enum Permission {
|
|||
Owner,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Team {
|
||||
pub can_create_org_repo: bool,
|
||||
pub description: String,
|
||||
|
@ -145,7 +145,7 @@ pub struct Team {
|
|||
pub units_map: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Topics {
|
||||
pub topics: Vec<String>,
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Clone, Serialize, Deserialize)]
|
||||
pub struct Configuration {
|
||||
pub spidering: bool,
|
||||
pub rate: Option<u64>,
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
use std::collections::HashSet;
|
||||
|
||||
use actix_web::web::{self, get};
|
||||
use actix_web::web;
|
||||
use actix_web::{HttpResponse, Responder};
|
||||
use actix_web_codegen_const_routes::get;
|
||||
use actix_web_codegen_const_routes::post;
|
||||
|
@ -145,8 +145,8 @@ impl Ctx {
|
|||
}
|
||||
self.import_forges(node_url, db).await?;
|
||||
let mini_index = self.client_get_mini_index(starchart.clone()).await?;
|
||||
db.rm_imported_mini_index(&starchart).await?;
|
||||
db.import_mini_index(&starchart, &mini_index.mini_index)
|
||||
db.rm_imported_mini_index(starchart).await?;
|
||||
db.import_mini_index(starchart, &mini_index.mini_index)
|
||||
.await?;
|
||||
}
|
||||
page += 1;
|
||||
|
|
|
@ -43,7 +43,7 @@ impl CtxError for AddChallenge {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub struct AddChallengePayload {
|
||||
pub hostname: Url,
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||
pub async fn add_submit(
|
||||
payload: web::Form<AddChallengePayload>,
|
||||
) -> PageResult<impl Responder, AddChallenge> {
|
||||
let link = PAGES.auth.verify_get(&payload.hostname.to_string());
|
||||
let link = PAGES.auth.verify_get(payload.hostname.as_ref());
|
||||
|
||||
Ok(HttpResponse::Found()
|
||||
.insert_header((http::header::LOCATION, link))
|
||||
|
|
|
@ -45,7 +45,7 @@ impl CtxError for VerifyChallenge {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub struct VerifyChallengePayload {
|
||||
pub hostname: Url,
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ impl CtxError for HomePage {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Default, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Default, Deserialize, Serialize)]
|
||||
pub struct HomePagePayload {
|
||||
pub repos: Vec<Repository>,
|
||||
pub next_page: String,
|
||||
|
@ -76,7 +76,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||
cfg.service(home);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Page {
|
||||
pub page: u32,
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ impl Page {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct OptionalPage {
|
||||
pub page: Option<u32>,
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize};
|
|||
use url::Url;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Server {
|
||||
pub port: u32,
|
||||
pub domain: String,
|
||||
|
@ -40,7 +40,7 @@ impl Server {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Display, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Display, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum LogLevel {
|
||||
#[display(fmt = "debug")]
|
||||
|
@ -64,7 +64,7 @@ impl LogLevel {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
|
||||
pub struct Repository {
|
||||
pub root: String,
|
||||
}
|
||||
|
@ -74,11 +74,11 @@ impl Repository {
|
|||
let root = Path::new(&self.root);
|
||||
if root.exists() {
|
||||
if !root.is_dir() {
|
||||
fs::remove_file(&root).unwrap();
|
||||
fs::create_dir_all(&root).unwrap();
|
||||
fs::remove_file(root).unwrap();
|
||||
fs::create_dir_all(root).unwrap();
|
||||
}
|
||||
} else {
|
||||
fs::create_dir_all(&root).unwrap();
|
||||
fs::create_dir_all(root).unwrap();
|
||||
}
|
||||
self.create_license_file();
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ impl Repository {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Display, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Display, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum DBType {
|
||||
#[display(fmt = "postgres")]
|
||||
|
@ -111,14 +111,14 @@ pub enum DBType {
|
|||
Sqlite,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Database {
|
||||
pub url: String,
|
||||
pub pool: u32,
|
||||
pub database_type: DBType,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Crawler {
|
||||
pub ttl: u64,
|
||||
pub client_timeout: u64,
|
||||
|
@ -126,13 +126,13 @@ pub struct Crawler {
|
|||
pub wait_before_next_api_call: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Introducer {
|
||||
pub nodes: Vec<Url>,
|
||||
pub public_url: Url,
|
||||
}
|
||||
|
||||
#[derive(Debug, Validate, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Validate, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Settings {
|
||||
pub log: LogLevel,
|
||||
pub database: Database,
|
||||
|
|
|
@ -141,7 +141,7 @@ macro_rules! get_app {
|
|||
.wrap(actix_web::middleware::NormalizePath::new(
|
||||
actix_web::middleware::TrailingSlash::Trim,
|
||||
))
|
||||
.configure(crate::routes::services)
|
||||
.configure($crate::routes::services)
|
||||
};
|
||||
|
||||
($settings:ident) => {
|
||||
|
@ -150,9 +150,9 @@ macro_rules! get_app {
|
|||
($ctx:expr, $db:expr, $federate:expr) => {
|
||||
test::init_service(
|
||||
get_app!("APP", &$ctx.settings)
|
||||
.app_data(crate::WebDB::new($db.clone()))
|
||||
.app_data(crate::WebCtx::new($ctx.clone()))
|
||||
.app_data(crate::WebFederate::new($federate.clone())),
|
||||
.app_data($crate::WebDB::new($db.clone()))
|
||||
.app_data($crate::WebCtx::new($ctx.clone()))
|
||||
.app_data($crate::WebFederate::new($federate.clone())),
|
||||
)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -41,8 +41,6 @@ pub struct TXTChallenge {
|
|||
pub value: String,
|
||||
}
|
||||
|
||||
const VALUES_LEN: usize = 30;
|
||||
|
||||
impl TXTChallenge {
|
||||
pub fn get_challenge_txt_key_prefix(ctx: &ArcCtx) -> String {
|
||||
// starchart-{{ starchart instance's hostname}}.{{ forge instance's hostname }}
|
||||
|
|
Loading…
Reference in a new issue