File tree Expand file tree Collapse file tree
templates/content_folders Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use crate :: database:: torrent;
2+
13use super :: * ;
24
35/// A loaded folder, with all surrounding entities loaded as well:
@@ -11,6 +13,7 @@ pub struct FolderView {
1113 pub ancestors : Vec < Model > ,
1214 pub children : Vec < Model > ,
1315 pub folder : Option < Model > ,
16+ pub torrents : Vec < torrent:: Model > ,
1417}
1518
1619impl FolderView {
@@ -27,6 +30,7 @@ impl FolderView {
2730 ancestors : vec ! [ ] ,
2831 folder : None ,
2932 children,
33+ torrents : vec ! [ ] ,
3034 } )
3135 }
3236
@@ -43,6 +47,13 @@ impl FolderView {
4347 let list = operator. list ( ) . await ?;
4448
4549 if let Some ( folder) = list. iter ( ) . find ( |x| x. id == id) {
50+ let torrents = operator
51+ . db ( )
52+ . torrent ( )
53+ . list_for_folder ( folder)
54+ . await
55+ . unwrap ( ) ;
56+
4657 Ok ( Self {
4758 ancestors : folder
4859 . ancestors_from_list ( & list)
@@ -55,6 +66,7 @@ impl FolderView {
5566 . cloned ( )
5667 . collect ( ) ,
5768 folder : Some ( folder. clone ( ) ) ,
69+ torrents,
5870 } )
5971 } else {
6072 Err ( ContentFolderError :: NotFound { id } )
Original file line number Diff line number Diff line change @@ -49,6 +49,22 @@ impl TorrentOperator {
4949 . context ( DBSnafu )
5050 }
5151
52+ /// List torrents for a given content folder
53+ ///
54+ /// Should not fail, unless SQLite was corrupted for some reason.
55+ pub async fn list_for_folder (
56+ & self ,
57+ folder : & content_folder:: Model ,
58+ ) -> Result < Vec < Model > , TorrentError > {
59+ // TODO: optimization
60+ Ok ( self
61+ . list ( )
62+ . await ?
63+ . into_iter ( )
64+ . filter ( |x| x. content_folder_id == folder. id )
65+ . collect ( ) )
66+ }
67+
5268 /// Count torrents
5369 ///
5470 /// Should not fail, unless SQLite was corrupted for some reason.
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use axum::extract::Path;
55use axum_extra:: extract:: CookieJar ;
66use serde:: { Deserialize , Serialize } ;
77
8- use crate :: database:: content_folder;
8+ use crate :: database:: { content_folder, torrent } ;
99use crate :: state:: AppStateContext ;
1010use crate :: state:: error:: AppStateError ;
1111use crate :: state:: flash_message:: {
@@ -24,6 +24,8 @@ pub struct ContentFolderShowTemplate {
2424 pub state : AppStateContext ,
2525 /// Current folder, unless we're on the index page
2626 pub folder : Option < content_folder:: Model > ,
27+ /// Torrents associated with the content folder (empty on index page)
28+ pub torrents : Vec < torrent:: Model > ,
2729 /// Folders with parent_id set to current folder
2830 // TODO: order by alphanumeric
2931 pub children : Vec < content_folder:: Model > ,
@@ -39,12 +41,14 @@ impl ContentFolderShowTemplate {
3941 ancestors,
4042 children,
4143 folder,
44+ torrents,
4245 } = folder;
4346
4447 Self {
4548 children,
4649 flash : None ,
4750 folder,
51+ torrents,
4852 ancestors,
4953 state : context,
5054 }
Original file line number Diff line number Diff line change @@ -45,6 +45,35 @@ <h4 class="mb-0">{% block folder_title %}{% if let Some(folder) = folder %}{{ fo
4545 </ div >
4646 </ div >
4747
48+ {% if torrents.len() > 0 %}
49+ < div class ="card mt-4 ">
50+ < div class ="card-body ">
51+ < div class ="p-4 ">
52+ < div class ="d-flex align-items-center mb-4 ">
53+ < h4 class ="mb-0 "> {{ torrents.len() }} torrents waiting for confirmation in this folder</ h4 >
54+ </ div >
55+ </ div >
56+ < ul class ="list-group ">
57+ {% for torrent in torrents %}
58+ {% if let Some(torrent_file) = torrent.torrent_file %}
59+ < li >
60+ < span > {{ torrent.name }} will create the following folders/files in this folder:</ span >
61+ {# TODO: file tree in hightorrent #}
62+ < ul >
63+ {% for file in torrent_file.decoded.files().unwrap() %}
64+ < li > ({{ file.size | filesizeformat }}) {{ file.path.to_str().unwrap() }}</ li >
65+ {% endfor %}
66+ </ ul >
67+ </ li >
68+ {% else %}
69+ < li > < span > {{ torrent.name }} is still resolving so we can't know the files yet</ span > </ li >
70+ {% endif %}
71+ {% endfor %}
72+ </ ul >
73+ </ div >
74+ </ div >
75+ {% endif %}
76+
4877 < ul class ="list-group ">
4978 {% block system_list %}
5079 {% if children.is_empty() %}
You can’t perform that action at this time.
0 commit comments