Spaces:
Running
Running
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)
|