now fully working

This commit is contained in:
lelo 2025-03-31 18:14:45 +00:00
parent bc4aa70651
commit ac2589278b
2 changed files with 22 additions and 22 deletions

View File

@ -37,6 +37,25 @@ class Database(metaclass=SingletonMeta):
# Enable autocommit so we don't have to call commit() after every transaction.
self.connection.autocommit = True
self.init_log_db()
# Function to initialize the database.
def init_log_db(self):
with self.connection.cursor() as cursor:
cursor.execute('''
CREATE TABLE IF NOT EXISTS file_access_log (
id SERIAL PRIMARY KEY,
timestamp TIMESTAMP,
rel_path TEXT,
filesize BIGINT,
mime TEXT,
ip_address TEXT,
user_agent TEXT,
device_id TEXT,
cached BOOLEAN
)
''')
# Create a global database instance.
log_db = Database()
@ -64,23 +83,6 @@ def get_device_type(user_agent):
else:
return 'Other'
# Function to initialize the database.
def init_log_db():
with log_db.connection.cursor() as cursor:
cursor.execute('''
CREATE TABLE IF NOT EXISTS file_access_log (
id SERIAL PRIMARY KEY,
timestamp TIMESTAMP,
rel_path TEXT,
filesize BIGINT,
mime TEXT,
ip_address TEXT,
user_agent TEXT,
device_id TEXT,
cached BOOLEAN
)
''')
# Logging function that uses the singleton connection.
def log_file_access(rel_path, filesize, mime, ip_address, user_agent, device_id, cached):
timestamp = datetime.now() # Use datetime object directly
@ -261,5 +263,3 @@ def dashboard():
unique_user=unique_user,
timeframe_data=timeframe_data)
if __name__ == '__main__':
init_log_db()

View File

@ -1,7 +1,7 @@
services:
flask-app:
image: python:3.11-slim
container_name: "${CONTAINER_NAME}.web"
container_name: ${CONTAINER_NAME}
restart: always
working_dir: /app
volumes:
@ -19,7 +19,7 @@ services:
- FLASK_ENV=production
- TITLE_SHORT=${TITLE_SHORT}
- TITLE_LONG=${TITLE_LONG}
- DB_HOST=postgres
- DB_HOST=${CONTAINER_NAME}.sql
- DB_PORT=5432
- DB_USER=${POSTGRES_USER}
- DB_PASSWORD=${POSTGRES_PASSWORD}
@ -54,7 +54,7 @@ services:
postgres:
image: postgres:15
container_name: "${CONTAINER_NAME}.postgres"
container_name: "${CONTAINER_NAME}.sql"
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}