add yesterday
This commit is contained in:
parent
3f0d175277
commit
5b4e7188cd
45
analytics.py
45
analytics.py
@ -11,6 +11,7 @@ import helperfunctions as hf
|
||||
|
||||
file_access_temp = []
|
||||
folder_today = []
|
||||
folder_yesterday = []
|
||||
|
||||
app_config = auth.return_app_config()
|
||||
|
||||
@ -102,7 +103,7 @@ def parse_timestamp(ts_str):
|
||||
def log_file_access(rel_path, filesize, mime, ip_address, user_agent, device_id, cached):
|
||||
"""Insert a file access record into the database and prune entries older than 10 minutes,
|
||||
and track today’s files separately in folder_today."""
|
||||
global file_access_temp, folder_today
|
||||
global file_access_temp, folder_today, folder_yesterday
|
||||
|
||||
# Create a timezone-aware timestamp
|
||||
now = datetime.now(timezone.utc).astimezone()
|
||||
@ -126,22 +127,37 @@ def log_file_access(rel_path, filesize, mime, ip_address, user_agent, device_id,
|
||||
]
|
||||
|
||||
# Keep only today's entries in folder_today
|
||||
date_str = iso_ts.split('T', 1)[0]
|
||||
today_str = iso_ts.split('T', 1)[0]
|
||||
folder_today[:] = [
|
||||
entry for entry in folder_today
|
||||
if entry['date_str'] == date_str
|
||||
if entry['date_str'] == today_str
|
||||
]
|
||||
|
||||
# Keep only yesterday's entries in folder_yesterday
|
||||
yesterday_str = (now - timedelta(days=1)).isoformat().split('T', 1)[0]
|
||||
folder_yesterday[:] = [
|
||||
entry for entry in folder_yesterday
|
||||
if entry['date_str'] == yesterday_str
|
||||
]
|
||||
|
||||
# If this new access is from today, record it
|
||||
# Compare the helper’s YYYY-MM-DD string to today’s ISO date string
|
||||
date_from_path = hf.extract_date_from_string(rel_path)
|
||||
|
||||
if date_from_path == date_str:
|
||||
if date_from_path == today_str:
|
||||
# get just the folder part (everything before the final '/')
|
||||
folder_path = rel_path.rsplit('/', 1)[0] if '/' in rel_path else rel_path
|
||||
# only append if that folder isn't already in folder_today
|
||||
if not any(entry['rel_path'] == folder_path for entry in folder_today):
|
||||
folder_today.append({'date_str': date_str, 'rel_path': folder_path})
|
||||
folder_today.append({'date_str': today_str, 'rel_path': folder_path})
|
||||
|
||||
# If this new access is from yesterday, record it
|
||||
if date_from_path == yesterday_str:
|
||||
# get just the folder part (everything before the final '/')
|
||||
folder_path = rel_path.rsplit('/', 1)[0] if '/' in rel_path else rel_path
|
||||
# only append if that folder isn't already in folder_yesterday
|
||||
if not any(entry['rel_path'] == folder_path for entry in folder_yesterday):
|
||||
folder_yesterday.append({'date_str': yesterday_str, 'rel_path': folder_path})
|
||||
|
||||
# Finally, insert the new access at the top of the temp log
|
||||
file_access_temp.insert(0, [
|
||||
@ -177,6 +193,25 @@ def return_folder_today():
|
||||
return filtered
|
||||
|
||||
|
||||
def return_folder_yesterday():
|
||||
"""
|
||||
Return only those folder_yesterday entries whose first segment
|
||||
(up to the first '/') is in session['folders'].keys().
|
||||
"""
|
||||
valid_keys = set(session.get('folders', {}).keys())
|
||||
|
||||
filtered = []
|
||||
for entry in folder_yesterday:
|
||||
# get the part before the first slash
|
||||
top_level = entry['rel_path'].split('/', 1)[0]
|
||||
|
||||
# include only if this segment is one of the session keys
|
||||
if top_level in valid_keys:
|
||||
filtered.append(entry)
|
||||
|
||||
return filtered
|
||||
|
||||
|
||||
def return_file_access():
|
||||
"""Return recent file access logs from memory (the last 10 minutes)."""
|
||||
global file_access_temp
|
||||
|
||||
15
app.py
15
app.py
@ -254,19 +254,25 @@ def api_browse(subpath):
|
||||
'breadcrumbs': generate_breadcrumbs(),
|
||||
'directories': foldernames,
|
||||
'files': [],
|
||||
'folder_today': a.return_folder_today()
|
||||
'folder_today': a.return_folder_today(),
|
||||
'folder_yesterday': a.return_folder_yesterday()
|
||||
})
|
||||
|
||||
if subpath == 'today':
|
||||
if subpath == 'heute' or subpath == 'gestern':
|
||||
foldernames = []
|
||||
if len(a.return_folder_today()) > 0:
|
||||
for item in a.return_folder_today():
|
||||
foldernames.append({'name': item['rel_path'], 'path': item['rel_path']})
|
||||
elif len(a.return_folder_yesterday()) > 0:
|
||||
for item in a.return_folder_yesterday():
|
||||
foldernames.append({'name': item['rel_path'], 'path': item['rel_path']})
|
||||
|
||||
return jsonify({
|
||||
'breadcrumbs': generate_breadcrumbs(subpath),
|
||||
'directories': foldernames,
|
||||
'files': [],
|
||||
'folder_today': []
|
||||
'folder_today': [],
|
||||
'folder_yesterday': []
|
||||
})
|
||||
|
||||
root, *relative_parts = subpath.split('/')
|
||||
@ -299,7 +305,8 @@ def api_browse(subpath):
|
||||
'breadcrumbs': breadcrumbs,
|
||||
'directories': directories,
|
||||
'files': files,
|
||||
'folder_today': a.return_folder_today()
|
||||
'folder_today': a.return_folder_today(),
|
||||
'folder_yesterday': a.return_folder_yesterday()
|
||||
}
|
||||
|
||||
# If a filename was selected include it.
|
||||
|
||||
@ -112,8 +112,11 @@ function renderContent(data) {
|
||||
} else {
|
||||
contentHTML += '<ul>';
|
||||
if (data.breadcrumbs.length === 1 && Array.isArray(data.folder_today) && data.folder_today.length > 0) {
|
||||
contentHTML += `<li class="directory-item"><a href="#" class="directory-link" data-path="today">📅 Heute</a></li>`;
|
||||
contentHTML += `<li class="directory-item"><a href="#" class="directory-link" data-path="heute">📅 Heute</a></li>`;
|
||||
} 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>`;
|
||||
}
|
||||
console.log(data.folder_today, data.folder_yesterday);
|
||||
data.directories.forEach(dir => {
|
||||
if (admin_enabled && data.breadcrumbs.length != 1 && dir.share) {
|
||||
share_link = `<a href="#" class="create-share" data-url="${dir.path}">⚙️</a>`;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user