openfree commited on
Commit
0c3b5c4
ยท
verified ยท
1 Parent(s): bdb5ea4

Update app-BACKUP2.py

Browse files
Files changed (1) hide show
  1. 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
- # Check if URL already exists in database
303
- if not add_url_to_sqlite(url):
304
- return jsonify({"success": False, "message": "URL already exists"})
 
 
 
 
 
 
 
 
 
 
 
 
305
 
306
- # Also update JSON file for backward compatibility
 
 
 
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)