This commit is contained in:
@@ -22,7 +22,7 @@ CUSTOM_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.3
|
|||||||
|
|
||||||
# Initialize SQLite database
|
# Initialize SQLite database
|
||||||
def init_db():
|
def init_db():
|
||||||
conn = sqlite3.connect('cache.db')
|
conn = sqlite3.connect('/db/cache.db')
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
CREATE TABLE IF NOT EXISTS cache (
|
CREATE TABLE IF NOT EXISTS cache (
|
||||||
@@ -38,7 +38,7 @@ def init_db():
|
|||||||
|
|
||||||
# Get cached data if it exists and is not older than 36 hours
|
# Get cached data if it exists and is not older than 36 hours
|
||||||
def get_cached_data(url, route):
|
def get_cached_data(url, route):
|
||||||
conn = sqlite3.connect('cache.db')
|
conn = sqlite3.connect('/db/cache.db')
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cache_expiry = int(time.time()) - (36 * 60 * 60) # 36 hours in seconds
|
cache_expiry = int(time.time()) - (36 * 60 * 60) # 36 hours in seconds
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
@@ -55,7 +55,7 @@ def get_cached_data(url, route):
|
|||||||
|
|
||||||
# Save data to cache
|
# Save data to cache
|
||||||
def save_to_cache(url, route, data):
|
def save_to_cache(url, route, data):
|
||||||
conn = sqlite3.connect('cache.db')
|
conn = sqlite3.connect('/db/cache.db')
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
|
|
||||||
@@ -338,7 +338,7 @@ async def clear_cache(x_api_key: Optional[str] = Header(None)):
|
|||||||
if not x_api_key or x_api_key != API_KEY:
|
if not x_api_key or x_api_key != API_KEY:
|
||||||
raise HTTPException(status_code=401, detail="Invalid API key")
|
raise HTTPException(status_code=401, detail="Invalid API key")
|
||||||
|
|
||||||
conn = sqlite3.connect('cache.db')
|
conn = sqlite3.connect('/db/cache.db')
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("DELETE FROM cache")
|
cursor.execute("DELETE FROM cache")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@@ -353,7 +353,7 @@ async def cache_stats(x_api_key: Optional[str] = Header(None)):
|
|||||||
if not x_api_key or x_api_key != API_KEY:
|
if not x_api_key or x_api_key != API_KEY:
|
||||||
raise HTTPException(status_code=401, detail="Invalid API key")
|
raise HTTPException(status_code=401, detail="Invalid API key")
|
||||||
|
|
||||||
conn = sqlite3.connect('cache.db')
|
conn = sqlite3.connect('/db/cache.db')
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# Get total entries
|
# Get total entries
|
||||||
|
|||||||
Reference in New Issue
Block a user