now fully working
This commit is contained in:
parent
bc4aa70651
commit
ac2589278b
38
analytics.py
38
analytics.py
@ -37,6 +37,25 @@ class Database(metaclass=SingletonMeta):
|
|||||||
# Enable autocommit so we don't have to call commit() after every transaction.
|
# Enable autocommit so we don't have to call commit() after every transaction.
|
||||||
self.connection.autocommit = True
|
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.
|
# Create a global database instance.
|
||||||
log_db = Database()
|
log_db = Database()
|
||||||
|
|
||||||
@ -64,23 +83,6 @@ def get_device_type(user_agent):
|
|||||||
else:
|
else:
|
||||||
return 'Other'
|
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.
|
# Logging function that uses the singleton connection.
|
||||||
def log_file_access(rel_path, filesize, mime, ip_address, user_agent, device_id, cached):
|
def log_file_access(rel_path, filesize, mime, ip_address, user_agent, device_id, cached):
|
||||||
timestamp = datetime.now() # Use datetime object directly
|
timestamp = datetime.now() # Use datetime object directly
|
||||||
@ -261,5 +263,3 @@ def dashboard():
|
|||||||
unique_user=unique_user,
|
unique_user=unique_user,
|
||||||
timeframe_data=timeframe_data)
|
timeframe_data=timeframe_data)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
init_log_db()
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
flask-app:
|
flask-app:
|
||||||
image: python:3.11-slim
|
image: python:3.11-slim
|
||||||
container_name: "${CONTAINER_NAME}.web"
|
container_name: ${CONTAINER_NAME}
|
||||||
restart: always
|
restart: always
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
volumes:
|
volumes:
|
||||||
@ -19,7 +19,7 @@ services:
|
|||||||
- FLASK_ENV=production
|
- FLASK_ENV=production
|
||||||
- TITLE_SHORT=${TITLE_SHORT}
|
- TITLE_SHORT=${TITLE_SHORT}
|
||||||
- TITLE_LONG=${TITLE_LONG}
|
- TITLE_LONG=${TITLE_LONG}
|
||||||
- DB_HOST=postgres
|
- DB_HOST=${CONTAINER_NAME}.sql
|
||||||
- DB_PORT=5432
|
- DB_PORT=5432
|
||||||
- DB_USER=${POSTGRES_USER}
|
- DB_USER=${POSTGRES_USER}
|
||||||
- DB_PASSWORD=${POSTGRES_PASSWORD}
|
- DB_PASSWORD=${POSTGRES_PASSWORD}
|
||||||
@ -54,7 +54,7 @@ services:
|
|||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:15
|
image: postgres:15
|
||||||
container_name: "${CONTAINER_NAME}.postgres"
|
container_name: "${CONTAINER_NAME}.sql"
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: ${POSTGRES_USER}
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user