mirror of
https://codeberg.org/catask-org/catask.git
synced 2025-04-20 05:43:41 -05:00
add api routes for import/export and updating blacklist
This commit is contained in:
parent
5f1f154789
commit
b98cf142d7
1 changed files with 47 additions and 2 deletions
49
app.py
49
app.py
|
@ -639,6 +639,15 @@ def deleteEmojiPack():
|
||||||
|
|
||||||
# -- misc --
|
# -- misc --
|
||||||
|
|
||||||
|
@api_bp.route('/update_blacklist/', methods=['PUT'])
|
||||||
|
@loginRequired
|
||||||
|
def updateBlacklist():
|
||||||
|
action = request.form.get('action')
|
||||||
|
blacklist = request.form.get('blacklist')
|
||||||
|
with open(const.blacklistFile, 'w') as file:
|
||||||
|
file.write(blacklist)
|
||||||
|
return {'message': 'Blacklist updated!'}, 200
|
||||||
|
|
||||||
@api_bp.route('/get_question_count/', methods=['GET'])
|
@api_bp.route('/get_question_count/', methods=['GET'])
|
||||||
def getQuestionCount():
|
def getQuestionCount():
|
||||||
conn = func.connectToDb()
|
conn = func.connectToDb()
|
||||||
|
@ -646,15 +655,51 @@ def getQuestionCount():
|
||||||
|
|
||||||
app.logger.debug("[CatAsk/API/get_question_count] SELECT'ing question count from database")
|
app.logger.debug("[CatAsk/API/get_question_count] SELECT'ing question count from database")
|
||||||
|
|
||||||
cursor.execute("SELECT COUNT(id) FROM questions WHERE answered=%s", (False,))
|
cursor.execute("SELECT COUNT(id) FROM questions WHERE answered=%s AND unread=%s", (False, True))
|
||||||
question_count = cursor.fetchone()
|
question_count = cursor.fetchone()
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
return str(question_count[0])
|
return str(question_count[0])
|
||||||
|
|
||||||
|
# -- import/export --
|
||||||
|
|
||||||
|
@api_bp.route('/import_data/', methods=['PUT'])
|
||||||
|
def importData():
|
||||||
|
os.makedirs(const.tempDir, exist_ok=True)
|
||||||
|
|
||||||
|
archive = request.files['import_archive']
|
||||||
|
filename = secure_filename(archive.filename)
|
||||||
|
|
||||||
|
file_path = const.tempDir / filename
|
||||||
|
|
||||||
|
archive.save(file_path)
|
||||||
|
return func.importData(file_path)
|
||||||
|
|
||||||
|
@api_bp.route('/import_rs_data/', methods=['PUT'])
|
||||||
|
def importRsData():
|
||||||
|
os.makedirs(const.tempDir, exist_ok=True)
|
||||||
|
|
||||||
|
archive = request.files['import_archive']
|
||||||
|
filename = secure_filename(archive.filename)
|
||||||
|
|
||||||
|
file_path = const.tempDir / filename
|
||||||
|
|
||||||
|
archive.save(file_path)
|
||||||
|
return func.retrospringImport(file_path)
|
||||||
|
|
||||||
|
@api_bp.route('/create_export/', methods=['POST'])
|
||||||
|
@loginRequired
|
||||||
|
def createExport():
|
||||||
|
return func.createExport()
|
||||||
|
|
||||||
|
@api_bp.route('/delete_export/', methods=['DELETE'])
|
||||||
|
@loginRequired
|
||||||
|
def deleteExport():
|
||||||
|
timestamp = request.args.get('timestamp', '')
|
||||||
|
return func.deleteExport(timestamp)
|
||||||
|
|
||||||
# unused
|
# unused
|
||||||
"""
|
|
||||||
@api_bp.route('/view_question/', methods=['GET'])
|
@api_bp.route('/view_question/', methods=['GET'])
|
||||||
@loginRequired
|
@loginRequired
|
||||||
def viewQuestion():
|
def viewQuestion():
|
||||||
|
|
Loading…
Add table
Reference in a new issue