Compare commits
No commits in common. "433f48ed840f8598263c29d27cd864d9a722815e" and "f78b439a36cdbc477cedb96ff7094aa010b43042" have entirely different histories.
433f48ed84
...
f78b439a36
File diff suppressed because it is too large
Load Diff
|
|
@ -11,9 +11,6 @@ axum = { version = "0.6.18", features = ["http2"] }
|
||||||
clap = { version = "4.3.12", features = ["env", "derive"] }
|
clap = { version = "4.3.12", features = ["env", "derive"] }
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
libarchive = { path = "../libarchive" }
|
libarchive = { path = "../libarchive" }
|
||||||
sea-orm = { version = "0.12.1", features = ["sqlx-sqlite", "runtime-tokio-rustls", "macros"] }
|
|
||||||
sea-orm-migration = "0.12.1"
|
|
||||||
serde = { version = "1.0.178", features = ["derive"] }
|
|
||||||
sha256 = "1.1.4"
|
sha256 = "1.1.4"
|
||||||
tokio = { version = "1.29.1", features = ["full"] }
|
tokio = { version = "1.29.1", features = ["full"] }
|
||||||
tokio-util = { version = "0.7.8", features = ["io"] }
|
tokio-util = { version = "0.7.8", features = ["io"] }
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
use axum::Router;
|
|
||||||
use axum::extract::State;
|
|
||||||
use axum::routing::get;
|
|
||||||
use sea_orm::entity::EntityTrait;
|
|
||||||
use sea_orm::query::QueryOrder;
|
|
||||||
use axum::Json;
|
|
||||||
|
|
||||||
use crate::db::entities::repo;
|
|
||||||
|
|
||||||
pub fn router() -> Router<crate::Global> {
|
|
||||||
Router::new()
|
|
||||||
.route("/repos", get(get_repos))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_repos(State(global): State<crate::Global>) -> crate::Result<Json<Vec<repo::Model>>> {
|
|
||||||
let repos = repo::Entity::find().order_by_asc(repo::Column::Id).all(&global.db).await?;
|
|
||||||
|
|
||||||
Ok(Json(repos))
|
|
||||||
}
|
|
||||||
|
|
@ -47,8 +47,6 @@ impl Cli {
|
||||||
pub async fn run(&self) {
|
pub async fn run(&self) {
|
||||||
self.init_tracing();
|
self.init_tracing();
|
||||||
|
|
||||||
let db = crate::db::init("sqlite://test.db?mode=rwc").await.unwrap();
|
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
repo_dir: self.repo_dir.clone(),
|
repo_dir: self.repo_dir.clone(),
|
||||||
pkg_dir: self.pkg_dir.clone(),
|
pkg_dir: self.pkg_dir.clone(),
|
||||||
|
|
@ -58,12 +56,10 @@ impl Cli {
|
||||||
let global = Global {
|
let global = Global {
|
||||||
config,
|
config,
|
||||||
repo_manager: Arc::new(RwLock::new(repo_manager)),
|
repo_manager: Arc::new(RwLock::new(repo_manager)),
|
||||||
db
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// build our application with a single route
|
// build our application with a single route
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.nest("/api", crate::api::router())
|
|
||||||
.merge(crate::repo::router(&global))
|
.merge(crate::repo::router(&global))
|
||||||
.with_state(global)
|
.with_state(global)
|
||||||
.layer(TraceLayer::new_for_http());
|
.layer(TraceLayer::new_for_http());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
|
||||||
|
|
||||||
pub mod prelude;
|
|
||||||
|
|
||||||
pub mod repo;
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
|
||||||
|
|
||||||
pub use super::repo::Entity as Repo;
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
|
||||||
|
|
||||||
use sea_orm::entity::prelude::*;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
|
|
||||||
#[sea_orm(table_name = "repo")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key)]
|
|
||||||
pub id: i32,
|
|
||||||
pub name: String,
|
|
||||||
pub description: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
use sea_orm_migration::prelude::*;
|
|
||||||
|
|
||||||
pub struct Migration;
|
|
||||||
|
|
||||||
impl MigrationName for Migration {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"m_20230730_000001_create_repo_tables"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl MigrationTrait for Migration {
|
|
||||||
// Define how to apply this migration: Create the Bakery table.
|
|
||||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.create_table(
|
|
||||||
Table::create()
|
|
||||||
.table(Repo::Table)
|
|
||||||
.col(
|
|
||||||
ColumnDef::new(Repo::Id)
|
|
||||||
.integer()
|
|
||||||
.not_null()
|
|
||||||
.auto_increment()
|
|
||||||
.primary_key(),
|
|
||||||
)
|
|
||||||
.col(ColumnDef::new(Repo::Name).string().not_null().unique_key())
|
|
||||||
.col(ColumnDef::new(Repo::Description).string())
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define how to rollback this migration: Drop the Bakery table.
|
|
||||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
||||||
manager
|
|
||||||
.drop_table(Table::drop().table(Repo::Table).to_owned())
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Iden)]
|
|
||||||
pub enum Repo {
|
|
||||||
Table,
|
|
||||||
Id,
|
|
||||||
Name,
|
|
||||||
Description,
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
use sea_orm_migration::prelude::*;
|
|
||||||
|
|
||||||
pub struct Migrator;
|
|
||||||
|
|
||||||
mod m20230730_000001_create_repo_tables;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl MigratorTrait for Migrator {
|
|
||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
|
||||||
vec![Box::new(m20230730_000001_create_repo_tables::Migration)]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
mod migrator;
|
|
||||||
pub mod entities;
|
|
||||||
|
|
||||||
use migrator::Migrator;
|
|
||||||
use sea_orm::ConnectOptions;
|
|
||||||
use sea_orm::Database;
|
|
||||||
use sea_orm_migration::MigratorTrait;
|
|
||||||
|
|
||||||
pub async fn init<C: Into<ConnectOptions>>(
|
|
||||||
opt: C,
|
|
||||||
) -> Result<sea_orm::DatabaseConnection, sea_orm::DbErr> {
|
|
||||||
let db = Database::connect(opt).await?;
|
|
||||||
|
|
||||||
Migrator::refresh(&db).await?;
|
|
||||||
|
|
||||||
Ok(db)
|
|
||||||
}
|
|
||||||
|
|
@ -10,7 +10,6 @@ pub type Result<T> = std::result::Result<T, ServerError>;
|
||||||
pub enum ServerError {
|
pub enum ServerError {
|
||||||
IO(io::Error),
|
IO(io::Error),
|
||||||
Axum(axum::Error),
|
Axum(axum::Error),
|
||||||
Db(sea_orm::DbErr),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ServerError {
|
impl fmt::Display for ServerError {
|
||||||
|
|
@ -18,7 +17,6 @@ impl fmt::Display for ServerError {
|
||||||
match self {
|
match self {
|
||||||
ServerError::IO(err) => write!(fmt, "{}", err),
|
ServerError::IO(err) => write!(fmt, "{}", err),
|
||||||
ServerError::Axum(err) => write!(fmt, "{}", err),
|
ServerError::Axum(err) => write!(fmt, "{}", err),
|
||||||
ServerError::Db(err) => write!(fmt, "{}", err),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -30,8 +28,6 @@ impl IntoResponse for ServerError {
|
||||||
match self {
|
match self {
|
||||||
ServerError::IO(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
ServerError::IO(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||||
ServerError::Axum(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
ServerError::Axum(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||||
ServerError::Db(sea_orm::DbErr::RecordNotFound(_)) => StatusCode::NOT_FOUND.into_response(),
|
|
||||||
ServerError::Db(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,9 +49,3 @@ impl From<tokio::task::JoinError> for ServerError {
|
||||||
ServerError::IO(err.into())
|
ServerError::IO(err.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<sea_orm::DbErr> for ServerError {
|
|
||||||
fn from(err: sea_orm::DbErr) -> Self {
|
|
||||||
ServerError::Db(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,12 @@
|
||||||
mod cli;
|
mod cli;
|
||||||
mod db;
|
|
||||||
mod error;
|
mod error;
|
||||||
mod repo;
|
mod repo;
|
||||||
mod api;
|
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
pub use error::{Result, ServerError};
|
pub use error::{Result, ServerError};
|
||||||
use repo::RepoGroupManager;
|
use repo::RepoGroupManager;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use sea_orm::DatabaseConnection;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
@ -21,7 +18,6 @@ pub struct Config {
|
||||||
pub struct Global {
|
pub struct Global {
|
||||||
config: Config,
|
config: Config,
|
||||||
repo_manager: Arc<RwLock<RepoGroupManager>>,
|
repo_manager: Arc<RwLock<RepoGroupManager>>,
|
||||||
db: DatabaseConnection
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ pub fn router(global: &crate::Global) -> Router<crate::Global> {
|
||||||
delete(delete_package).get(serve_repos.clone()),
|
delete(delete_package).get(serve_repos.clone()),
|
||||||
)
|
)
|
||||||
.fallback(serve_repos)
|
.fallback(serve_repos)
|
||||||
|
.with_state(global.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn post_package_archive(
|
async fn post_package_archive(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue