extra url modifications
This commit is contained in:
parent
a78ca2d0b2
commit
aeaac5fd4e
@ -5,6 +5,7 @@ from dotenv import load_dotenv
|
||||
from ktvmanager.config import DevelopmentConfig, ProductionConfig
|
||||
from routes.api import api_blueprint
|
||||
from routes.dns import dns_bp
|
||||
from routes.extra_urls import extra_urls_bp
|
||||
from ktvmanager.lib.database import initialize_db_pool
|
||||
from ktvmanager.account_checker import send_expiry_notifications
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
@ -31,6 +32,7 @@ def create_app():
|
||||
# Register blueprints
|
||||
app.register_blueprint(api_blueprint)
|
||||
app.register_blueprint(dns_bp)
|
||||
app.register_blueprint(extra_urls_bp)
|
||||
|
||||
@app.route('/check-expiry', methods=['POST'])
|
||||
def check_expiry():
|
||||
|
60
routes/extra_urls.py
Normal file
60
routes/extra_urls.py
Normal file
@ -0,0 +1,60 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
import os
|
||||
|
||||
extra_urls_bp = Blueprint('extra_urls', __name__)
|
||||
|
||||
EXTRA_URLS_FILE = os.path.join(os.path.dirname(__file__), '..', 'ktvmanager', 'lib', 'extra_urls.txt')
|
||||
|
||||
def read_extra_urls_list():
|
||||
if not os.path.exists(EXTRA_URLS_FILE):
|
||||
return []
|
||||
with open(EXTRA_URLS_FILE, 'r') as f:
|
||||
return [line.strip() for line in f.readlines() if line.strip()]
|
||||
|
||||
def write_extra_urls_list(extra_urls_list):
|
||||
with open(EXTRA_URLS_FILE, 'w') as f:
|
||||
for item in extra_urls_list:
|
||||
f.write(f"{item}\n")
|
||||
|
||||
@extra_urls_bp.route('/extra_urls', methods=['GET'])
|
||||
def get_extra_urls_list():
|
||||
"""Gets the list of extra URLs."""
|
||||
return jsonify(read_extra_urls_list())
|
||||
|
||||
@extra_urls_bp.route('/extra_urls', methods=['POST'])
|
||||
def add_extra_url():
|
||||
"""Adds a new extra URL."""
|
||||
data = request.get_json()
|
||||
if not data or 'extra_url' not in data:
|
||||
return jsonify({'error': 'Missing extra_url in request body'}), 400
|
||||
|
||||
extra_url = data.get('extra_url')
|
||||
if not extra_url:
|
||||
return jsonify({'error': 'Extra URL cannot be empty.'}), 400
|
||||
|
||||
extra_urls_list = read_extra_urls_list()
|
||||
if extra_url in extra_urls_list:
|
||||
return jsonify({'message': 'Extra URL already exists.'}), 200
|
||||
|
||||
extra_urls_list.append(extra_url)
|
||||
write_extra_urls_list(extra_urls_list)
|
||||
return jsonify({'message': 'Extra URL added successfully.'}), 201
|
||||
|
||||
@extra_urls_bp.route('/extra_urls', methods=['DELETE'])
|
||||
def remove_extra_url():
|
||||
"""Removes an extra URL."""
|
||||
data = request.get_json()
|
||||
if not data or 'extra_url' not in data:
|
||||
return jsonify({'error': 'Missing extra_url in request body'}), 400
|
||||
|
||||
extra_url = data.get('extra_url')
|
||||
if not extra_url:
|
||||
return jsonify({'error': 'Extra URL cannot be empty.'}), 400
|
||||
|
||||
extra_urls_list = read_extra_urls_list()
|
||||
if extra_url not in extra_urls_list:
|
||||
return jsonify({'error': 'Extra URL not found.'}), 404
|
||||
|
||||
extra_urls_list.remove(extra_url)
|
||||
write_extra_urls_list(extra_urls_list)
|
||||
return jsonify({'message': 'Extra URL removed successfully.'}), 200
|
Loading…
x
Reference in New Issue
Block a user