add top list folder
This commit is contained in:
parent
1eb7148498
commit
7dd107fc72
23
app.py
23
app.py
@ -275,6 +275,29 @@ def api_browse(subpath):
|
||||
'folder_yesterday': []
|
||||
})
|
||||
|
||||
if subpath.startswith('toplist'):
|
||||
foldernames = []
|
||||
files = []
|
||||
split_path = subpath.split('/')
|
||||
if len(split_path) == 1 and split_path[0] == 'toplist':
|
||||
foldernames = [
|
||||
{'name': 'Predigten', 'path': 'toplist/predigt'},
|
||||
{'name': 'Chorlieder', 'path': 'toplist/chor'},
|
||||
{'name': 'Gemeinsamer Gesang', 'path': 'toplist/gemeinsamer_gesang'},
|
||||
{'name': 'Gruppengesang', 'path': 'toplist/gruppengesang'},
|
||||
]
|
||||
elif len(split_path) > 1 and split_path[0] == 'toplist':
|
||||
files = [
|
||||
hf.generate_top_list(split_path[1])
|
||||
]
|
||||
|
||||
return jsonify({
|
||||
'breadcrumbs': generate_breadcrumbs(subpath),
|
||||
'directories': foldernames,
|
||||
'files': files
|
||||
})
|
||||
|
||||
|
||||
root, *relative_parts = subpath.split('/')
|
||||
base_path = session['folders'][root]
|
||||
directory = os.path.join(base_path, *relative_parts)
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
from datetime import datetime
|
||||
import re
|
||||
import os
|
||||
import sqlite3
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
log_db = sqlite3.connect("access_log.db", check_same_thread=False)
|
||||
|
||||
def extract_date_from_string(string_with_date):
|
||||
# grab X.Y.Z where X,Y,Z are 1–4 digits
|
||||
@ -90,3 +94,48 @@ def extract_structure_from_string(input_string):
|
||||
name = None
|
||||
|
||||
return category, titel, name
|
||||
|
||||
def generate_top_list(category):
|
||||
|
||||
now = datetime.now()
|
||||
|
||||
# We'll compare the timestamp
|
||||
start_dt = now - timedelta(days=30)
|
||||
start_str = start_dt.isoformat()
|
||||
|
||||
# Filter for mimes that start with the given type
|
||||
params_for_filter = (start_str)
|
||||
|
||||
# 1. Top files by access count
|
||||
query = f'''
|
||||
SELECT rel_path, COUNT(*) as access_count
|
||||
FROM file_access_log
|
||||
WHERE timestamp >= ? AND mime LIKE 'audio/%'
|
||||
GROUP BY rel_path
|
||||
ORDER BY access_count DESC
|
||||
LIMIT 1000
|
||||
'''
|
||||
with log_db:
|
||||
cursor = log_db.execute(query, params_for_filter)
|
||||
rows = cursor.fetchall()
|
||||
|
||||
# Convert rows to a list of dictionaries and add category
|
||||
rows = [
|
||||
{
|
||||
'rel_path': rel_path,
|
||||
'category': extract_structure_from_string(rel_path)[0]
|
||||
}
|
||||
for rel_path in rows
|
||||
]
|
||||
|
||||
rows = [r for r in rows if r['category'] == category][:20]
|
||||
|
||||
filelist = [
|
||||
{
|
||||
'name': rel_path,
|
||||
'path': rel_path
|
||||
}
|
||||
for rel_path in [r['rel_path'] for r in rows]
|
||||
]
|
||||
|
||||
return filelist
|
||||
|
||||
@ -116,6 +116,9 @@ function renderContent(data) {
|
||||
} else if (data.breadcrumbs.length === 1 && Array.isArray(data.folder_yesterday) && data.folder_yesterday.length > 0) {
|
||||
contentHTML += `<li class="directory-item"><a href="#" class="directory-link" data-path="gestern">📅 Gestern</a></li>`;
|
||||
}
|
||||
if (data.breadcrumbs.length === 1 ) {
|
||||
contentHTML += `<li class="directory-item"><a href="#" class="directory-link" data-path="toplist">👥 oft gehört</a></li>`;
|
||||
}
|
||||
console.log(data.folder_today, data.folder_yesterday);
|
||||
data.directories.forEach(dir => {
|
||||
if (admin_enabled && data.breadcrumbs.length != 1 && dir.share) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user