add: backup version converter/ backup logic 1.0

This commit is contained in:
h z
2025-04-25 13:00:41 +01:00
parent 35c8934963
commit 84494827ad
15 changed files with 2107 additions and 76 deletions

View File

@@ -11,6 +11,21 @@ from db.models.MarkdownSetting import MarkdownSetting
@limiter.limit(api.get_rate_limit)
@etag_response
def get_markdown_path(setting_id):
"""
Get a specific markdown setting by ID.
This endpoint retrieves a markdown setting by its ID.
Request:
- setting_id (int): The ID of the markdown setting to retrieve
Returns:
A JSON object containing the markdown setting.
Response Codes:
- 200: Success
- 204: No content (setting not found)
"""
with get_db() as session:
setting = session.query(MarkdownSetting).get(setting_id)
if setting is None:
@@ -21,6 +36,23 @@ def get_markdown_path(setting_id):
@setting_bp.route('/markdown/', methods=['POST'])
@require_auth(roles=['admin'])
def create_markdown_setting():
"""
Create a new markdown setting.
This endpoint creates a new markdown setting with the provided template and permission settings.
It requires authentication with the 'admin' role.
Request:
- template_setting_id (int, optional): The ID of the template setting to associate
- permission_setting_id (int, optional): The ID of the permission setting to associate
Returns:
A JSON object containing the created markdown setting.
Response Codes:
- 200: Created successfully
- 500: Server error
"""
data = request.json
template_setting_id = data.get('template_setting_id')
permission_setting_id = data.get('permission_setting_id')
@@ -39,6 +71,25 @@ def create_markdown_setting():
@setting_bp.route('/markdown/<int:setting_id>', methods=['PUT', 'PATCH'])
@require_auth(roles=['admin'])
def update_markdown_setting(setting_id):
"""
Update a markdown setting.
This endpoint updates an existing markdown setting with the provided template and permission settings.
It requires authentication with the 'admin' role.
Request:
- setting_id (int): The ID of the markdown setting to update
- template_setting_id (int, optional): The new template setting ID
- permission_setting_id (int, optional): The new permission setting ID
Returns:
A JSON object containing the updated markdown setting.
Response Codes:
- 200: Updated successfully
- 400: Bad request (setting not found)
- 500: Server error
"""
data = request.json
try:
with get_db() as session:
@@ -58,6 +109,22 @@ def update_markdown_setting(setting_id):
@setting_bp.route('/markdown/<int:setting_id>', methods=['DELETE'])
@require_auth(roles=['admin'])
def delete_markdown_setting(setting_id):
"""
Delete a markdown setting.
This endpoint deletes an existing markdown setting.
It requires authentication with the 'admin' role.
Request:
- setting_id (int): The ID of the markdown setting to delete
Returns:
A JSON object with a success message.
Response Codes:
- 200: Deleted successfully
- 400: Bad request (setting not found)
"""
with get_db() as session:
setting = session.query(MarkdownSetting).get(setting_id)
if setting is None:

View File

@@ -10,6 +10,21 @@ from db.models.MarkdownPermissionSetting import MarkdownPermissionSetting
@etag_response
@limiter.limit(api.get_rate_limit)
def get_permission_setting(setting_id):
"""
Get a specific markdown permission setting by ID.
This endpoint retrieves a markdown permission setting by its ID.
Request:
- setting_id (int): The ID of the permission setting to retrieve
Returns:
A JSON object containing the permission setting.
Response Codes:
- 200: Success
- 204: No content (setting not found)
"""
with get_db() as session:
setting = session.query(MarkdownPermissionSetting).get(setting_id)
if not setting:
@@ -20,6 +35,21 @@ def get_permission_setting(setting_id):
@setting_bp.route('/markdown/permission/', methods=['POST'])
@require_auth(roles=['admin'])
def create_permission_setting():
"""
Create a new markdown permission setting.
This endpoint creates a new markdown permission setting with the provided permission value.
It requires authentication with the 'admin' role.
Request:
- permission (str): The permission value (e.g., 'private', 'protected', etc.)
Returns:
A JSON object containing the created permission setting.
Response Codes:
- 201: Created successfully
"""
data = request.json
permission = data.get('permission')
new_setting = MarkdownPermissionSetting(permission=permission)
@@ -32,6 +62,26 @@ def create_permission_setting():
@setting_bp.route('/markdown/permission/<int:setting_id>', methods=['PUT', 'PATCH'])
@require_auth(roles=['admin'])
def update_permission_setting(setting_id):
"""
Update a markdown permission setting.
This endpoint updates an existing markdown permission setting with the provided permission value.
It requires authentication with the 'admin' role.
- PUT: Replaces the entire permission setting
- PATCH: Updates only the specified fields
Request:
- setting_id (int): The ID of the permission setting to update
- permission (str): The new permission value
Returns:
A JSON object containing the updated permission setting.
Response Codes:
- 200: Updated successfully
- 404: Permission setting not found
"""
with get_db() as session:
setting = session.get(MarkdownPermissionSetting, setting_id)
if setting is None:
@@ -48,6 +98,21 @@ def update_permission_setting(setting_id):
@setting_bp.route('/markdown/permission/<int:setting_id>', methods=['DELETE'])
@require_auth(roles=['admin'])
def delete_permission_setting(setting_id):
"""
Delete a markdown permission setting.
This endpoint deletes an existing markdown permission setting.
It requires authentication with the 'admin' role.
Request:
- setting_id (int): The ID of the permission setting to delete
Returns:
A JSON object containing the deleted permission setting.
Response Codes:
- 200: Deleted successfully
"""
with get_db() as session:
setting = session.get(MarkdownPermissionSetting, setting_id)
st = setting.to_dict()

View File

@@ -9,6 +9,17 @@ from db.models.MarkdownTemplateSetting import MarkdownTemplateSetting
@setting_bp.route('/markdown/template/', methods=['GET'])
@etag_response
def list_template_settings():
"""
List all markdown template settings.
This endpoint retrieves a list of all markdown template settings in the system.
Returns:
A JSON array containing all template settings.
Response Codes:
- 200: Success
"""
with get_db() as session:
settings = session.query(MarkdownTemplateSetting).all()
return jsonify([s.to_dict() for s in settings]), 200
@@ -17,6 +28,21 @@ def list_template_settings():
@etag_response
@limiter.limit(api.get_rate_limit)
def get_template_setting(setting_id):
"""
Get a specific markdown template setting by ID.
This endpoint retrieves a markdown template setting by its ID.
Request:
- setting_id (int): The ID of the template setting to retrieve
Returns:
A JSON object containing the template setting.
Response Codes:
- 200: Success
- 204: No content (setting not found)
"""
with get_db() as session:
setting = session.query(MarkdownTemplateSetting).get(setting_id)
if not setting:
@@ -27,6 +53,21 @@ def get_template_setting(setting_id):
@setting_bp.route('/markdown/template/', methods=['POST'])
@require_auth(roles=['admin'])
def create_template_setting():
"""
Create a new markdown template setting.
This endpoint creates a new markdown template setting with the provided template ID.
It requires authentication with the 'admin' role.
Request:
- template_id (int): The ID of the template to associate with this setting
Returns:
A JSON object containing the created template setting.
Response Codes:
- 201: Created successfully
"""
data = request.json
template_id = data.get('template_id')
new_setting = MarkdownTemplateSetting(template_id=template_id)
@@ -39,6 +80,26 @@ def create_template_setting():
@setting_bp.route('/markdown/template/<int:setting_id>', methods=['PUT', 'PATCH'])
@require_auth(roles=['admin'])
def update_template_setting(setting_id):
"""
Update a markdown template setting.
This endpoint updates an existing markdown template setting with the provided template ID.
It requires authentication with the 'admin' role.
- PUT: Replaces the entire template setting
- PATCH: Updates only the specified fields
Request:
- setting_id (int): The ID of the template setting to update
- template_id (int): The new template ID
Returns:
A JSON object containing the updated template setting.
Response Codes:
- 200: Updated successfully
- 404: Template setting not found
"""
with get_db() as session:
setting = session.get(MarkdownTemplateSetting, setting_id)
if setting is None:
@@ -55,6 +116,21 @@ def update_template_setting(setting_id):
@setting_bp.route('/markdown/template/<int:setting_id>', methods=['DELETE'])
@require_auth(roles=['admin'])
def delete_template_setting(setting_id):
"""
Delete a markdown template setting.
This endpoint deletes an existing markdown template setting.
It requires authentication with the 'admin' role.
Request:
- setting_id (int): The ID of the template setting to delete
Returns:
A JSON object containing the deleted template setting.
Response Codes:
- 200: Deleted successfully
"""
with get_db() as session:
setting = session.get(MarkdownTemplateSetting, setting_id)
st = setting.to_dict()

View File

@@ -13,6 +13,21 @@ logger = logging.getLogger(__name__)
@limiter.limit(api.get_rate_limit)
@etag_response
def get_path_setting(setting_id):
"""
Get a specific path setting by ID.
This endpoint retrieves a path setting by its ID.
Request:
- setting_id (int): The ID of the path setting to retrieve
Returns:
A JSON object containing the path setting.
Response Codes:
- 200: Success
- 204: No content (setting not found)
"""
with get_db() as session:
setting = session.query(PathSetting).get(setting_id)
if setting is None:
@@ -22,6 +37,23 @@ def get_path_setting(setting_id):
@setting_bp.route('/path/', methods=['POST'])
@require_auth(roles=['admin'])
def create_path_setting():
"""
Create a new path setting.
This endpoint creates a new path setting with the provided webhook and template settings.
It requires authentication with the 'admin' role.
Request:
- webhook_setting_id (int, optional): The ID of the webhook setting to associate
- template_setting_id (int, optional): The ID of the template setting to associate
Returns:
A JSON object containing the created path setting.
Response Codes:
- 200: Created successfully
- 500: Server error
"""
data = request.json
webhook_setting_id = data.get('webhook_setting_id')
template_setting_id = data.get('template_setting_id')
@@ -42,6 +74,25 @@ def create_path_setting():
@setting_bp.route('/path/<int:setting_id>', methods=['PUT', 'PATCH'])
@require_auth(roles=['admin'])
def update_path_setting(setting_id):
"""
Update a path setting.
This endpoint updates an existing path setting with the provided webhook and template settings.
It requires authentication with the 'admin' role.
Request:
- setting_id (int): The ID of the path setting to update
- webhook_setting_id (int, optional): The new webhook setting ID
- template_setting_id (int, optional): The new template setting ID
Returns:
A JSON object containing the updated path setting.
Response Codes:
- 200: Updated successfully
- 400: Bad request (setting not found)
- 500: Server error
"""
data = request.json
with get_db() as session:
try:
@@ -60,10 +111,25 @@ def update_path_setting(setting_id):
@setting_bp.route('/path/<int:setting_id>', methods=['DELETE'])
@require_auth(roles=['admin'])
def delete_path_setting(setting_id):
"""
Delete a path setting.
This endpoint deletes an existing path setting.
It requires authentication with the 'admin' role.
Request:
- setting_id (int): The ID of the path setting to delete
Returns:
A JSON object with a success message.
Response Codes:
- 200: Deleted successfully
- 400: Bad request (setting not found)
"""
with get_db() as session:
setting = session.query(PathSetting).get(setting_id)
if setting is None:
return jsonify({"error": "setting not exists"}), 400
session.delete(setting)
return jsonify({"message": "deleted"}), 200

View File

@@ -8,6 +8,18 @@ from db.models.WebhookSetting import WebhookSetting
@setting_bp.route('/path/webhook/', methods=['GET'])
@require_auth(roles=['admin'])
def list_webhook_settings():
"""
List all webhook settings.
This endpoint retrieves a list of all webhook settings in the system.
It requires authentication with the 'admin' role.
Returns:
A JSON array containing all webhook settings.
Response Codes:
- 200: Success
"""
with get_db() as session:
settings = session.query(WebhookSetting).all()
return jsonify([s.to_dict() for s in settings]), 200
@@ -16,6 +28,22 @@ def list_webhook_settings():
@setting_bp.route('/path/webhook/<int:setting_id>', methods=['GET'])
@require_auth(roles=['admin'])
def webhook_setting(setting_id):
"""
Get a specific webhook setting by ID.
This endpoint retrieves a webhook setting by its ID.
It requires authentication with the 'admin' role.
Request:
- setting_id (int): The ID of the webhook setting to retrieve
Returns:
A JSON object containing the webhook setting.
Response Codes:
- 200: Success
- 204: No content (setting not found)
"""
with get_db() as session:
setting = session.query(WebhookSetting).filter(WebhookSetting.id == setting_id).first()
if not setting:
@@ -26,6 +54,25 @@ def webhook_setting(setting_id):
@setting_bp.route('/path/webhook/', methods=['POST'])
@require_auth(roles=['admin'])
def create_webhook_setting():
"""
Create a new webhook setting.
This endpoint creates a new webhook setting with the provided parameters.
It requires authentication with the 'admin' role.
Request:
- webhook_id (int): The ID of the webhook to associate
- recursive (bool, optional): Whether the webhook applies to subpaths (default: false)
- additional_header (str, optional): Additional headers for the webhook (default: '')
- enabled (bool, optional): Whether the webhook is enabled (default: true)
- on_events (int, optional): Event types that trigger the webhook (default: 1)
Returns:
A JSON object containing the created webhook setting.
Response Codes:
- 201: Created successfully
"""
data = request.json
with get_db() as session:
setting = WebhookSetting(
@@ -43,6 +90,27 @@ def create_webhook_setting():
@setting_bp.route('/path/webhook/<int:setting_id>', methods=['PUT', 'PATCH'])
@require_auth(roles=['admin'])
def update_webhook_setting(setting_id):
"""
Update a webhook setting.
This endpoint updates an existing webhook setting with the provided parameters.
It requires authentication with the 'admin' role.
Request:
- setting_id (int): The ID of the webhook setting to update
- webhook_id (int, optional): The new webhook ID
- recursive (bool, optional): Whether the webhook applies to subpaths
- additional_header (str, optional): Additional headers for the webhook
- enabled (bool, optional): Whether the webhook is enabled
- on_events (int, optional): Event types that trigger the webhook
Returns:
A JSON object containing the updated webhook setting.
Response Codes:
- 200: Updated successfully
- 404: Webhook setting not found
"""
data = request.json
with get_db() as session:
setting = session.query(WebhookSetting).get(setting_id)
@@ -66,6 +134,22 @@ def update_webhook_setting(setting_id):
@setting_bp.route('/path/webhook/<int:setting_id>', methods=['DELETE'])
@require_auth(roles=['admin'])
def delete_webhook_setting(setting_id):
"""
Delete a webhook setting.
This endpoint deletes an existing webhook setting.
It requires authentication with the 'admin' role.
Request:
- setting_id (int): The ID of the webhook setting to delete
Returns:
A JSON object with a success message.
Response Codes:
- 200: Deleted successfully
- 404: Webhook setting not found
"""
with get_db() as session:
setting = session.query(WebhookSetting).get(setting_id)
if not setting:
@@ -74,4 +158,3 @@ def delete_webhook_setting(setting_id):
session.delete(setting)
session.commit()
return jsonify({'message': 'Webhook setting deleted'}), 200