update
This commit is contained in:
parent
221b2a82e7
commit
2ed9cd25a3
7 changed files with 126 additions and 7 deletions
|
@ -1,14 +1,60 @@
|
|||
use based::page::{Shell, render_page};
|
||||
use based::request::api::FallibleApiResponse;
|
||||
use based::request::{RawResponse, RequestContext, StringResponse, respond_with};
|
||||
use maud::html;
|
||||
use rocket::get;
|
||||
use rocket::http::{ContentType, Status};
|
||||
use rocket::tokio::io::AsyncReadExt;
|
||||
use rocket::{FromForm, get, post};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::pkg::Repository;
|
||||
use crate::pkg::{Package, Repository};
|
||||
|
||||
// /pkg/<repo>/<arch>/<pkg_name>
|
||||
// /pkg/<repo>/<arch>/
|
||||
|
||||
use rocket::form::Form;
|
||||
use rocket::fs::TempFile;
|
||||
|
||||
#[derive(FromForm)]
|
||||
pub struct PkgUpload<'r> {
|
||||
name: String,
|
||||
arch: String,
|
||||
version: String,
|
||||
pkg: TempFile<'r>,
|
||||
sig: Option<TempFile<'r>>,
|
||||
}
|
||||
|
||||
pub async fn tmp_file_to_vec<'r>(tmp: &TempFile<'r>) -> Vec<u8> {
|
||||
let mut buf = Vec::with_capacity(tmp.len() as usize);
|
||||
tmp.open()
|
||||
.await
|
||||
.unwrap()
|
||||
.read_to_end(&mut buf)
|
||||
.await
|
||||
.unwrap();
|
||||
buf
|
||||
}
|
||||
|
||||
#[post("/pkg/<repo>/upload", data = "<upload>")]
|
||||
pub async fn upload_pkg(
|
||||
repo: &str,
|
||||
upload: Form<PkgUpload<'_>>,
|
||||
user: based::auth::User,
|
||||
) -> FallibleApiResponse {
|
||||
let pkg = Package::new(repo, &upload.arch, &upload.name, &upload.version);
|
||||
|
||||
pkg.save(
|
||||
tmp_file_to_vec(&upload.pkg).await,
|
||||
if let Some(sig) = &upload.sig {
|
||||
Some(tmp_file_to_vec(sig).await)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
);
|
||||
|
||||
Ok(json!({"ok": 1}))
|
||||
}
|
||||
|
||||
#[get("/pkg/<repo>/<arch>/<pkg_name>")]
|
||||
pub async fn pkg_route(repo: &str, arch: &str, pkg_name: &str, ctx: RequestContext) -> RawResponse {
|
||||
if let Some(repo) = Repository::new(repo) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue