Spaces:
Sleeping
Sleeping
Update app-BACKUP2.py
Browse files- app-BACKUP2.py +32 -4
app-BACKUP2.py
CHANGED
|
@@ -293,17 +293,33 @@ def api_favorites():
|
|
| 293 |
"total_pages": total_pages
|
| 294 |
})
|
| 295 |
|
|
|
|
| 296 |
@app.route('/api/url/add', methods=['POST'])
|
| 297 |
def add_url():
|
| 298 |
url = request.form.get('url', '').strip()
|
| 299 |
if not url:
|
| 300 |
return jsonify({"success": False, "message": "URL is required"})
|
| 301 |
|
| 302 |
-
#
|
| 303 |
-
|
| 304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
| 307 |
data = load_json()
|
| 308 |
if url not in data:
|
| 309 |
data.insert(0, url)
|
|
@@ -732,4 +748,16 @@ def before_request_func():
|
|
| 732 |
app._got_first_request = True
|
| 733 |
|
| 734 |
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 735 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 293 |
"total_pages": total_pages
|
| 294 |
})
|
| 295 |
|
| 296 |
+
# `/api/url/add` 경로 함수 수정
|
| 297 |
@app.route('/api/url/add', methods=['POST'])
|
| 298 |
def add_url():
|
| 299 |
url = request.form.get('url', '').strip()
|
| 300 |
if not url:
|
| 301 |
return jsonify({"success": False, "message": "URL is required"})
|
| 302 |
|
| 303 |
+
# SQLite에 추가 시도
|
| 304 |
+
conn = sqlite3.connect(SQLITE_DB)
|
| 305 |
+
cursor = conn.cursor()
|
| 306 |
+
try:
|
| 307 |
+
cursor.execute("INSERT INTO urls (url) VALUES (?)", (url,))
|
| 308 |
+
conn.commit()
|
| 309 |
+
success = True
|
| 310 |
+
except sqlite3.IntegrityError:
|
| 311 |
+
# URL이 이미 존재하는 경우
|
| 312 |
+
success = False
|
| 313 |
+
except Exception as e:
|
| 314 |
+
print(f"SQLite error: {str(e)}")
|
| 315 |
+
success = False
|
| 316 |
+
finally:
|
| 317 |
+
conn.close()
|
| 318 |
|
| 319 |
+
if not success:
|
| 320 |
+
return jsonify({"success": False, "message": "URL already exists or could not be added"})
|
| 321 |
+
|
| 322 |
+
# JSON 파일에도 추가 (백업용)
|
| 323 |
data = load_json()
|
| 324 |
if url not in data:
|
| 325 |
data.insert(0, url)
|
|
|
|
| 748 |
app._got_first_request = True
|
| 749 |
|
| 750 |
if __name__ == '__main__':
|
| 751 |
+
# 앱 시작 전에 명시적으로 DB 초기화
|
| 752 |
+
print("Initializing database...")
|
| 753 |
+
init_db()
|
| 754 |
+
|
| 755 |
+
# 데이터베이스 파일 경로 및 존재 여부 확인
|
| 756 |
+
db_path = os.path.abspath(SQLITE_DB)
|
| 757 |
+
print(f"SQLite DB path: {db_path}")
|
| 758 |
+
if os.path.exists(SQLITE_DB):
|
| 759 |
+
print(f"Database file exists, size: {os.path.getsize(SQLITE_DB)} bytes")
|
| 760 |
+
else:
|
| 761 |
+
print("Warning: Database file does not exist after initialization!")
|
| 762 |
+
|
| 763 |
app.run(host='0.0.0.0', port=7860)
|