parent
fcd3d6ffca
commit
ac07105bf7
6 changed files with 87 additions and 29 deletions
10
src/main.rs
10
src/main.rs
|
@ -8,6 +8,7 @@
|
|||
use based::page::{Shell, render_page};
|
||||
use based::request::{RequestContext, StringResponse};
|
||||
use maud::html;
|
||||
use pkg::Repository;
|
||||
use rocket::get;
|
||||
use rocket::routes;
|
||||
|
||||
|
@ -16,13 +17,18 @@ pub mod routes;
|
|||
|
||||
#[get("/")]
|
||||
pub async fn index_page(ctx: RequestContext) -> StringResponse {
|
||||
let repos: Vec<String> = Repository::list();
|
||||
|
||||
let content = html!(
|
||||
h1 { "Hello World!" };
|
||||
h1 { "Repositories" };
|
||||
@for repo in repos {
|
||||
p { (repo) };
|
||||
};
|
||||
);
|
||||
|
||||
render_page(
|
||||
content,
|
||||
"Hello World",
|
||||
"Repositories",
|
||||
ctx,
|
||||
&Shell::new(html! {}, html! {}, Some(String::new())),
|
||||
)
|
||||
|
|
20
src/pkg.rs
20
src/pkg.rs
|
@ -4,6 +4,26 @@ pub struct Repository {
|
|||
pub name: String,
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
pub fn list() -> Vec<String> {
|
||||
let mut repos = vec![];
|
||||
|
||||
for entry in std::fs::read_dir("./data").unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
let file_name = path.file_name().unwrap().to_str().unwrap().to_string();
|
||||
repos.push(file_name);
|
||||
}
|
||||
|
||||
repos
|
||||
}
|
||||
|
||||
pub fn create(name: &str) -> Repository {
|
||||
let path = PathBuf::from("./data").join(name);
|
||||
std::fs::create_dir_all(path).unwrap();
|
||||
Repository::new(name).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
pub fn new(name: &str) -> Option<Self> {
|
||||
if PathBuf::from("./data").join(name).exists() {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use based::page::{Shell, render_page};
|
||||
use based::request::api::FallibleApiResponse;
|
||||
use based::request::{RawResponse, RequestContext, StringResponse, respond_with};
|
||||
use maud::html;
|
||||
use based::request::api::{FallibleApiResponse, api_error};
|
||||
use based::request::{RawResponse, RequestContext, respond_with};
|
||||
use rocket::http::{ContentType, Status};
|
||||
use rocket::tokio::io::AsyncReadExt;
|
||||
use rocket::{FromForm, get, post};
|
||||
|
@ -39,8 +37,12 @@ pub async fn tmp_file_to_vec<'r>(tmp: &TempFile<'r>) -> Vec<u8> {
|
|||
pub async fn upload_pkg(
|
||||
repo: &str,
|
||||
upload: Form<PkgUpload<'_>>,
|
||||
user: based::auth::User,
|
||||
user: based::auth::APIUser,
|
||||
) -> FallibleApiResponse {
|
||||
if !user.0.is_admin() {
|
||||
return Err(api_error("Forbidden"));
|
||||
}
|
||||
|
||||
let pkg = Package::new(repo, &upload.arch, &upload.name, &upload.version);
|
||||
|
||||
pkg.save(
|
||||
|
@ -101,18 +103,3 @@ pub async fn pkg_route(repo: &str, arch: &str, pkg_name: &str, ctx: RequestConte
|
|||
"Not found".as_bytes().to_vec(),
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
pub async fn index_page(ctx: RequestContext) -> StringResponse {
|
||||
let content = html!(
|
||||
h1 { "Hello World!" };
|
||||
);
|
||||
|
||||
render_page(
|
||||
content,
|
||||
"Hello World",
|
||||
ctx,
|
||||
&Shell::new(html! {}, html! {}, Some(String::new())),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue