mirror of
https://github.com/Jackzmc/storage.git
synced 2025-05-10 05:13:21 +00:00
Finish moving to hbs
This commit is contained in:
parent
3147da7643
commit
7ff6e3cab4
7 changed files with 113 additions and 16 deletions
|
@ -2,6 +2,8 @@ use std::sync::Arc;
|
|||
use log::debug;
|
||||
use rocket::{catch, launch, routes, Request, State};
|
||||
use rocket::data::ByteUnit;
|
||||
use rocket::fs::{relative, FileServer};
|
||||
use rocket_dyn_templates::handlebars::Handlebars;
|
||||
use rocket_dyn_templates::Template;
|
||||
use sqlx::{migrate, Pool, Postgres};
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
@ -32,6 +34,8 @@ async fn rocket() -> _ {
|
|||
setup_logger();
|
||||
dotenvy::dotenv().ok();
|
||||
|
||||
let handlebars = Handlebars::new();
|
||||
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(std::env::var("DATABASE_URL").unwrap().as_str())
|
||||
|
@ -56,8 +60,9 @@ async fn rocket() -> _ {
|
|||
.manage(pool)
|
||||
.manage(repo_manager)
|
||||
.manage(libraries_manager)
|
||||
.mount("/static", FileServer::from(relative!("static")))
|
||||
.mount("/", routes![
|
||||
ui::user::index
|
||||
ui::user::index, ui::user::list_library_files
|
||||
])
|
||||
.mount("/api", routes![
|
||||
api::library::move_file, api::library::upload_file, api::library::download_file, api::library::list_files, api::library::get_file, api::library::delete_file,
|
||||
|
|
|
@ -20,6 +20,10 @@ impl Library {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn model(&self) -> &LibraryModel {
|
||||
&self.model
|
||||
}
|
||||
|
||||
pub async fn write_file(&self, rel_path: &PathBuf, contents: &[u8]) -> Result<(), anyhow::Error> {
|
||||
let mut repo = self.repo.read().await;
|
||||
repo.backend.write_file(&self.model.id.to_string(), rel_path, contents)
|
||||
|
|
|
@ -1,7 +1,29 @@
|
|||
use rocket::get;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use rocket::{get, State};
|
||||
use rocket::serde::json::Json;
|
||||
use rocket_dyn_templates::{context, Template};
|
||||
use tokio::sync::Mutex;
|
||||
use crate::managers::libraries::LibraryManager;
|
||||
use crate::util::{JsonErrorResponse, ResponseError};
|
||||
|
||||
#[get("/")]
|
||||
pub fn index() -> Template {
|
||||
pub async fn index() -> Template {
|
||||
Template::render("index", context! { test: "value" })
|
||||
}
|
||||
|
||||
#[get("/libraries/<library_id>/<_>/<path..>")]
|
||||
pub async fn list_library_files(libraries: &State<Arc<Mutex<LibraryManager>>>, library_id: &str, path: PathBuf) -> Result<Template, ResponseError> {
|
||||
let libs = libraries.lock().await;
|
||||
let library = libs.get(library_id).await?;
|
||||
let files = library.list_files(&PathBuf::from(path)).await
|
||||
.map_err(|e| ResponseError::InternalServerError(JsonErrorResponse {
|
||||
code: "STORAGE_ERROR".to_string(),
|
||||
message: e.to_string(),
|
||||
}))?;
|
||||
|
||||
Ok(Template::render("libraries", context! {
|
||||
library: library.model(),
|
||||
files: files
|
||||
}))
|
||||
}
|
29
server/static/css/main.css
Normal file
29
server/static/css/main.css
Normal file
|
@ -0,0 +1,29 @@
|
|||
.sidebar {
|
||||
|
||||
}
|
||||
.sidebar-header {
|
||||
color: hsl(0, 0%, 48%);
|
||||
padding-left: 8px;
|
||||
}
|
||||
.sidebar-list {
|
||||
/* margin-top: 2px; */
|
||||
padding-top: 10px;
|
||||
padding-left: 5px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
.sidebar-list li button {
|
||||
padding-left: 8px;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
padding-right: 5px;
|
||||
border-radius: 2.5px;
|
||||
/* margin-top: 4px; */
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
}
|
||||
.sidebar i {
|
||||
padding-right: 4px;
|
||||
}
|
||||
.sidebar-list li button:hover, .sidebar-list li button.is-active {
|
||||
background-color: lightgray;
|
||||
}
|
|
@ -2,15 +2,16 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="/favicon.png" />
|
||||
<link rel="icon" href="/static/favicon.png" />
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>storage-app</title>
|
||||
<!-- TODO: use static -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css"
|
||||
>
|
||||
<link href="/static/css/main.css" rel="stylesheet" />
|
||||
<link rel="stylesheet" href="/static/css/bulma.min.css">
|
||||
<link href="/static/icons/css/fontawesome.css" rel="stylesheet" />
|
||||
<link href="/static/icons/css/regular.css" rel="stylesheet" />
|
||||
<link href="/static/icons/css/brands.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
{{> partials/nav }}
|
||||
|
|
38
server/templates/libraries.html.hbs
Normal file
38
server/templates/libraries.html.hbs
Normal file
|
@ -0,0 +1,38 @@
|
|||
{{#> layouts/main }}
|
||||
<div class="">
|
||||
<h4 class="title is-4 is-inline">{{ library.name }} > Files</h4>
|
||||
<div class="is-pulled-right is-inline-block">
|
||||
<div class="buttons">
|
||||
<div class="button is-small">
|
||||
Display
|
||||
</div>
|
||||
<div class="button is-small">
|
||||
Sort
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr class="my-2">
|
||||
<table class="table is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Name </td>
|
||||
<td>Size </td>
|
||||
<td>Last Updated </td>
|
||||
<td>Owner </td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each files }}
|
||||
<tr>
|
||||
<td class="px-4 py-4">
|
||||
<a href="{{ file_name }}">{{ file_name }}</a>
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>Me</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{/layouts/main}}
|
|
@ -1,9 +1,9 @@
|
|||
<aside class="sidebar pl-0 mb-0">
|
||||
<p class="sidebar-header">Workspace</p>
|
||||
<ul class="sidebar-list">
|
||||
<li class="is-active"><button><Icon icon="akar-icons:copy"></Icon> Files</button></li>
|
||||
<li><button><Icon icon="akar-icons:heart"></Icon> Favorites</button></li>
|
||||
<li><button><Icon icon="akar-icons:clock"></Icon> Activities</button></li>
|
||||
<li class="is-active"><button><i class="fa fa-file"></i> Files</button></li>
|
||||
<li><button><i class="fas fa-heart"></i> Favorites</button></li>
|
||||
<li><button><i class="fas fa-clock"></i> Activities</button></li>
|
||||
</ul>
|
||||
<p class="sidebar-header">Help</p>
|
||||
<ul class="sidebar-list">
|
||||
|
@ -12,11 +12,6 @@
|
|||
</ul>
|
||||
</aside>
|
||||
|
||||
|
||||
<script lang="ts">
|
||||
import Icon from "@iconify/svelte";
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.sidebar {
|
||||
|
||||
|
@ -41,6 +36,9 @@
|
|||
width: 100%;
|
||||
text-align: left;
|
||||
}
|
||||
.sidebar i {
|
||||
margin-left: 2px;
|
||||
}
|
||||
.sidebar-list li button:hover, .sidebar-list li button.is-active {
|
||||
background-color: lightgray;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue