Compare commits

..

2 Commits

3 changed files with 20 additions and 4 deletions

View File

@@ -2,7 +2,7 @@ import logging
import os import os
from pathlib import Path from pathlib import Path
DB_PATH = Path(os.getenv("DB_NAME", "owlynews.sqlite3")) DB_PATH = Path(os.getenv("DB_NAME", os.path.join(os.path.dirname(os.path.dirname(__file__)), "owlynews.sqlite3")))
OLLAMA_HOST = os.getenv("OLLAMA_HOST", "http://localhost:11434") OLLAMA_HOST = os.getenv("OLLAMA_HOST", "http://localhost:11434")
MIN_CRON_HOURS = float(os.getenv("MIN_CRON_HOURS", 0.5)) MIN_CRON_HOURS = float(os.getenv("MIN_CRON_HOURS", 0.5))
DEFAULT_CRON_HOURS = float(os.getenv("CRON_HOURS", MIN_CRON_HOURS)) DEFAULT_CRON_HOURS = float(os.getenv("CRON_HOURS", MIN_CRON_HOURS))

View File

@@ -290,7 +290,7 @@ async def get_model_status():
@app.post("/sync", response_model=None) @app.post("/sync", response_model=None)
async def manual_sync(db: sqlite3.Cursor = Depends(get_db)): async def manual_sync(db: sqlite3.Cursor = Depends(get_db_write)): # Note: changed to get_db_write
""" """
Manually trigger a feed synchronization. Manually trigger a feed synchronization.
@@ -302,7 +302,14 @@ async def manual_sync(db: sqlite3.Cursor = Depends(get_db)):
""" """
db.execute("SELECT val FROM meta WHERE key='last_sync'") db.execute("SELECT val FROM meta WHERE key='last_sync'")
row = db.fetchone() row = db.fetchone()
last_sync_ts = int(row["val"])
if row is None:
# Initialize the last_sync key if it doesn't exist
import time
last_sync_ts = int(time.time()) - (SYNC_COOLDOWN_MINUTES * 60 + 1) # Set to a time that allows sync
db.execute("INSERT INTO meta (key, val) VALUES ('last_sync', ?)", (str(last_sync_ts),))
else:
last_sync_ts = int(row["val"])
now = datetime.now(timezone.utc) now = datetime.now(timezone.utc)
last_sync_time = datetime.fromtimestamp(last_sync_ts, timezone.utc) last_sync_time = datetime.fromtimestamp(last_sync_ts, timezone.utc)
@@ -314,13 +321,18 @@ async def manual_sync(db: sqlite3.Cursor = Depends(get_db)):
try: try:
task = asyncio.create_task(NewsFetcher.harvest_feeds()) task = asyncio.create_task(NewsFetcher.harvest_feeds())
# Update the last_sync timestamp after triggering the sync
current_ts = int(time.time())
db.execute("UPDATE meta SET val=? WHERE key='last_sync'", (str(current_ts),))
return {"status": "triggered", "task_id": id(task)} return {"status": "triggered", "task_id": id(task)}
except Exception as e: except Exception as e:
logger.error(f"❌ Failed to trigger sync: {e}")
raise HTTPException( raise HTTPException(
500, f"Failed to trigger sync: {str(e)}" 500, f"Failed to trigger sync: {str(e)}"
) )
@app.get("/meta/last-sync", response_model=TimestampResponse) @app.get("/meta/last-sync", response_model=TimestampResponse)
async def get_last_sync(db: sqlite3.Cursor = Depends(get_db)): async def get_last_sync(db: sqlite3.Cursor = Depends(get_db)):
""" """

View File

@@ -23,7 +23,11 @@ export default defineConfig({
server: { server: {
proxy: { proxy: {
'/news': 'http://localhost:8000', '/news': 'http://localhost:8000',
'/meta': 'http://localhost:8000' '/meta': 'http://localhost:8000',
'/feeds': 'http://localhost:8000',
'/model': 'http://localhost:8000',
'/sync': 'http://localhost:8000',
'/settings': 'http://localhost:8000'
} }
}, },
}); });