added commands (test)

This commit is contained in:
2025-01-17 12:03:00 +01:00
parent 2623106212
commit fb4ad30d03
3 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
from __future__ import annotations
from flask_restful import Resource
from flask import current_app as app, request
from typing import TYPE_CHECKING
import hashlib
if TYPE_CHECKING:
from modules.Archive.database import Database
class Command(Resource):
def post(self):
auth = request.headers.get('auth')
if auth is not None:
hash_obj = hashlib.sha256(auth.encode('utf-8'))
if hash_obj.hexdigest() == "63a3b0dba950e1015a110486518e5ceff8cff415041aba3dedb8dc5aa3b3dd16":
db : Database = app.databases["Archive"]
query = request.data.decode("utf-8")
print("auth success")
print(query)
#result = db.db.run_command(query)
else:
result = None
else:
result = None
return db.wrap_query_response(result, mode="text")
class CommandOld(Resource):
def post(self):
auth = request.headers.get('auth')
if auth is not None:
hash_obj = hashlib.sha256(auth.encode('utf-8'))
if hash_obj.hexdigest() == "63a3b0dba950e1015a110486518e5ceff8cff415041aba3dedb8dc5aa3b3dd16":
db : Database = app.databases["ArchiveOld"]
query = request.data.decode("utf-8")
print("auth success")
print(query)
#result = db.db.run_command(query)
else:
result = None
else:
result = None
return db.wrap_query_response(result, mode="text")

View File

@@ -0,0 +1,45 @@
from __future__ import annotations
import json
from flask_restful import Resource
from flask import current_app as app, request
from typing import TYPE_CHECKING
import hashlib
if TYPE_CHECKING:
from modules.Archive.database import Database
class Commands(Resource):
def post(self):
auth = request.headers.get('auth')
if auth is not None:
hash_obj = hashlib.sha256(auth.encode('utf-8'))
if hash_obj.hexdigest() == "63a3b0dba950e1015a110486518e5ceff8cff415041aba3dedb8dc5aa3b3dd16":
db : Database = app.databases["Archive"]
data = json.loads(request.data)
print("auth success")
print(data)
result = "ok"
#result = db.db.run_commands(data)
else:
result = None
else:
result = None
return db.wrap_query_response(result, mode="text")
class CommandsOld(Resource):
def post(self):
auth = request.headers.get('auth')
if auth is not None:
hash_obj = hashlib.sha256(auth.encode('utf-8'))
if hash_obj.hexdigest() == "63a3b0dba950e1015a110486518e5ceff8cff415041aba3dedb8dc5aa3b3dd16":
db : Database = app.databases["ArchiveOld"]
data = json.loads(request.data)
print("auth success")
print(data)
result = "ok"
#result = db.db.run_commands(data)
else:
result = None
else:
result = None
return db.wrap_query_response(result, mode="text")