Skip to content

Commit

Permalink
fix library page
Browse files Browse the repository at this point in the history
  • Loading branch information
notmarek committed Jul 13, 2023
1 parent 16c7580 commit 0f4bf8a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/api/library.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
eventqueue::{QueueTrait, RawEvent},
models::{library::LibraryActions, user::UserActions},
models::{file::FileActions, library::LibraryActions, user::UserActions},
ArcQueue, ErrorResponse, Response, VerifiedAuthData,
};
use actix_web::{delete, get, post, put};
Expand Down Expand Up @@ -71,6 +71,7 @@ async fn library(
#[derive(Serialize)]
struct Bruh {
library_info: Library,
root_file: File,
files: Vec<File>,
}
let library = {
Expand All @@ -79,6 +80,7 @@ async fn library(
status: "ok".to_string(),
data: Bruh {
library_info: u.clone(),
root_file: File::get_from_path(u.path.clone(), &db).await.unwrap(),
files: u.get_files(&db).await.unwrap(),
},
},
Expand Down
13 changes: 13 additions & 0 deletions src/models/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub trait FileActions {
db: &DatabaseConnection,
) -> Result<file::Model, String>;
async fn get(fid: String, db: &DatabaseConnection) -> Result<file::Model, String>;
async fn get_from_path(path: String, db: &DatabaseConnection) -> Result<file::Model, String>;
async fn scan(&mut self, db: &DatabaseConnection);
async fn get_folder_content(&self, db: &DatabaseConnection)
-> Result<Vec<file::Model>, String>;
Expand Down Expand Up @@ -65,6 +66,18 @@ impl FileActions for file::Model {
}
}

async fn get_from_path(path: String, db: &DatabaseConnection) -> Result<file::Model, String> {
match File::find()
.filter(file::Column::Path.eq(&path))
.one(db)
.await
{
Ok(Some(f)) => Ok(f),
Ok(None) => Err("No entry in db".to_string()),
Err(e) => Err(e.to_string()),
}
}

async fn scan(&mut self, db: &DatabaseConnection) {
if self.size.is_some() {
return;
Expand Down
2 changes: 1 addition & 1 deletion static/content/modules/library/authenticated.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h2 class="secondary" id="libraryPath"></h2>
lib.library_info.name;
// document.getElementById("libraryPath").innerText =
// lib.library_info.path;
let root_file = lib.files.find((f) => !f.parent);
let root_file = lib.root_file;
for (const entry of lib.files) {
console.log(entry);
if (entry.parent !== root_file.id) continue;
Expand Down

0 comments on commit 0f4bf8a

Please sign in to comment.