clementpep commited on
Commit
1511698
·
1 Parent(s): 26bac7c

fix: db config and improve logs

Browse files
backend/.env.exemple CHANGED
@@ -13,6 +13,3 @@ MIN_VIEWS_THRESHOLD=100000
13
  # YouTube API (optional - required for upload feature)
14
  # YOUTUBE_API_KEY=your_youtube_api_key_here
15
  # YOUTUBE_CHANNEL_ID=your_youtube_channel_id_here
16
-
17
- # Database
18
- DB_URL=sqlite:///./insta.db
 
13
  # YouTube API (optional - required for upload feature)
14
  # YOUTUBE_API_KEY=your_youtube_api_key_here
15
  # YOUTUBE_CHANNEL_ID=your_youtube_channel_id_here
 
 
 
backend/app/db.py CHANGED
@@ -6,8 +6,9 @@ from datetime import datetime
6
  import os
7
 
8
 
9
- DB_URL = os.getenv("DB_URL", "sqlite:///./insta.db")
10
- engine = create_engine(DB_URL, echo=False)
 
11
 
12
 
13
  class Media(SQLModel, table=True):
 
6
  import os
7
 
8
 
9
+ # SQLite database in app directory
10
+ DB_URL = "sqlite:///./insta.db"
11
+ engine = create_engine(DB_URL, echo=False, connect_args={"check_same_thread": False})
12
 
13
 
14
  class Media(SQLModel, table=True):
backend/app/instagram_client.py CHANGED
@@ -19,7 +19,13 @@ class InstagramClient:
19
  p = params.copy() if params else {}
20
  p["access_token"] = self.token
21
  r = self.http.get(f"{BASE_URL}{path}", params=p)
22
- r.raise_for_status()
 
 
 
 
 
 
23
  return r.json()
24
 
25
  def find_hashtag_id(self, name: str) -> Optional[str]:
 
19
  p = params.copy() if params else {}
20
  p["access_token"] = self.token
21
  r = self.http.get(f"{BASE_URL}{path}", params=p)
22
+
23
+ if r.status_code != 200:
24
+ error_detail = r.text
25
+ print(f"Instagram API Error: {r.status_code}")
26
+ print(f"Response: {error_detail}")
27
+ r.raise_for_status()
28
+
29
  return r.json()
30
 
31
  def find_hashtag_id(self, name: str) -> Optional[str]:
backend/app/main.py CHANGED
@@ -47,6 +47,9 @@ def ingest():
47
  count = ingest_hashtags()
48
  return {"success": True, "processed": count}
49
  except Exception as e:
 
 
 
50
  raise HTTPException(status_code=500, detail=str(e))
51
 
52
 
@@ -88,7 +91,7 @@ def list_videos(uploaded: bool = None):
88
  return videos
89
 
90
 
91
- @app.patch(f"{settings.API_PREFIX}/videos/{video_id}/approve")
92
  def approve_video(video_id: int, approved: bool):
93
  """Approve or unapprove a video."""
94
  with get_session() as session:
 
47
  count = ingest_hashtags()
48
  return {"success": True, "processed": count}
49
  except Exception as e:
50
+ import traceback
51
+ print(f"ERROR in ingest: {str(e)}")
52
+ print(traceback.format_exc())
53
  raise HTTPException(status_code=500, detail=str(e))
54
 
55
 
 
91
  return videos
92
 
93
 
94
+ @app.patch(f"{settings.API_PREFIX}/videos/{{video_id}}/approve")
95
  def approve_video(video_id: int, approved: bool):
96
  """Approve or unapprove a video."""
97
  with get_session() as session:
docker-compose.yml CHANGED
@@ -9,7 +9,6 @@ services:
9
  - "8000:8000"
10
  volumes:
11
  - ./backend:/app
12
- - ./backend/insta.db:/app/insta.db
13
  environment:
14
  - PYTHONUNBUFFERED=1
15
  healthcheck:
 
9
  - "8000:8000"
10
  volumes:
11
  - ./backend:/app
 
12
  environment:
13
  - PYTHONUNBUFFERED=1
14
  healthcheck: