Selaa lähdekoodia

add filesizes and stray files in snapshot dir to snapshot_live ui

Nick Sweeting 1 vuosi sitten
vanhempi
sitoutus
1cd62ecc61
2 muutettua tiedostoa jossa 48 lisäystä ja 1 poistoa
  1. 38 0
      archivebox/core/views.py
  2. 10 1
      archivebox/templates/core/snapshot_live.html

+ 38 - 0
archivebox/core/views.py

@@ -85,9 +85,47 @@ class SnapshotView(View):
                     'name': result.extractor,
                     'name': result.extractor,
                     'path': embed_path,
                     'path': embed_path,
                     'ts': ts_to_date_str(result.end_ts),
                     'ts': ts_to_date_str(result.end_ts),
+                    'size': abs_path.stat().st_size or '?',
                 }
                 }
                 archiveresults[result.extractor] = result_info
                 archiveresults[result.extractor] = result_info
 
 
+        existing_files = {result['path'] for result in archiveresults.values()}
+        min_size_threshold = 128  # bytes
+        allowed_extensions = {
+            'txt',
+            'html',
+            'htm',
+            'png',
+            'jpg',
+            'jpeg',
+            'gif',
+            'webp'
+            'svg',
+            'webm',
+            'mp4',
+            'mp3',
+            'pdf',
+            'md',
+        }
+
+        # iterate through all the files in the snapshot dir and add the biggest ones to the result list
+        for result_file in Path(snapshot.link_dir).glob('*/*/*'):
+            extension = result_file.suffix.lstrip('.').lower()
+            if result_file.is_dir() or result_file.name.startswith('.') or extension not in allowed_extensions:
+                continue
+            if result_file.name in existing_files:
+                continue
+
+            file_size = result_file.stat().st_size or 0
+
+            if file_size > min_size_threshold:
+                archiveresults[result_file.name] = {
+                    'name': result_file.stem,
+                    'path': result_file.relative_to(snapshot.link_dir),
+                    'ts': ts_to_date_str(result_file.stat().st_mtime or 0),
+                    'size': file_size,
+                }
+
         preferred_types = ('singlefile', 'wget', 'screenshot', 'dom', 'media', 'pdf', 'readability', 'mercury')
         preferred_types = ('singlefile', 'wget', 'screenshot', 'dom', 'media', 'pdf', 'readability', 'mercury')
         all_types = preferred_types + tuple(result_type for result_type in archiveresults.keys() if result_type not in preferred_types)
         all_types = preferred_types + tuple(result_type for result_type in archiveresults.keys() if result_type not in preferred_types)
 
 

+ 10 - 1
archivebox/templates/core/snapshot_live.html

@@ -395,12 +395,14 @@
             </div>
             </div>
             <div class="header-bottom container-fluid">
             <div class="header-bottom container-fluid">
                 <div class="row header-bottom-frames">
                 <div class="row header-bottom-frames">
+                    
+                    
                     {% for result in archiveresults %}
                     {% for result in archiveresults %}
                         <div class="col-lg-2">
                         <div class="col-lg-2">
                             <div class="card {% if forloop.first %}selected-card{% endif %}">
                             <div class="card {% if forloop.first %}selected-card{% endif %}">
                                 <div class="card-body">
                                 <div class="card-body">
                                     <a href="{{result.path}}" target="preview" title="./{{result.path}} (downloaded {{result.ts}})">
                                     <a href="{{result.path}}" target="preview" title="./{{result.path}} (downloaded {{result.ts}})">
-                                        <h4>{{result.name}}</h4>
+                                        <h4>{{result.name}} <small>({{result.size|filesizeformat}})</small></h4>
                                         <!-- <p class="card-text" ><code>./{{result.path|truncatechars:30}}</code></p> -->
                                         <!-- <p class="card-text" ><code>./{{result.path|truncatechars:30}}</code></p> -->
                                     </a>
                                     </a>
                                     <!--<a href="{{result.path}}" target="preview"><h4 class="card-title">{{result.name}}</h4></a>-->
                                     <!--<a href="{{result.path}}" target="preview"><h4 class="card-title">{{result.name}}</h4></a>-->
@@ -409,6 +411,8 @@
                             </div>
                             </div>
                         </div>
                         </div>
                     {% endfor %}
                     {% endfor %}
+
+
                     <div class="col-lg-2">
                     <div class="col-lg-2">
                         <div class="card">
                         <div class="card">
                             <div class="card-body">
                             <div class="card-body">
@@ -423,8 +427,13 @@
                 </div>
                 </div>
             </div>
             </div>
         </header>
         </header>
+
+
+
         <iframe id="main-frame" sandbox="allow-same-origin allow-top-navigation-by-user-activation allow-scripts allow-forms" class="full-page-iframe" src="{{best_result.path}}" name="preview"></iframe>
         <iframe id="main-frame" sandbox="allow-same-origin allow-top-navigation-by-user-activation allow-scripts allow-forms" class="full-page-iframe" src="{{best_result.path}}" name="preview"></iframe>
     
     
+
+
         <script src="{% static 'jquery.min.js' %}" type="text/javascript"></script>
         <script src="{% static 'jquery.min.js' %}" type="text/javascript"></script>
 
 
         <script>
         <script>