Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(routes): Replace json.dumps with flask.jsonify for formatting responses in JSON. #40

Merged
merged 6 commits into from
Jan 5, 2025
5 changes: 2 additions & 3 deletions application/routes/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
# furnished to do so, subject to the following conditions:
#
#
import json

from flask import request, abort
from flask import request, abort, jsonify
xx12345798 marked this conversation as resolved.
Show resolved Hide resolved

from .common import create_connection
from .. import api
Expand All @@ -53,4 +52,4 @@ def start_audio():
'audio_id': audio.id
}

return json.dumps(result)
return jsonify(result)
5 changes: 2 additions & 3 deletions application/routes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

import json
import threading

from flask import request, abort
from flask import request, abort, jsonify

from .. import api, profiles
from ..codes import ICtrlError, ConnectionType
Expand Down Expand Up @@ -80,7 +79,7 @@ def handle_session():
session_id = request.args.get('id')
host, username, _, _, nickname = profiles.get_session_info(session_id)

return json.dumps({
return jsonify({
'host': host,
'username': username,
'nickname': nickname
Expand Down
4 changes: 2 additions & 2 deletions application/routes/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from datetime import datetime
from pathlib import Path

from flask import request, abort, stream_with_context
from flask import request, abort, stream_with_context, jsonify

from .common import create_connection
from .. import api, app
Expand All @@ -48,7 +48,7 @@ def sftp_ls(session_id):
'cwd': cwd,
'files': file_list
}
return json.dumps(result)
return jsonify(result)
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved


@api.route('/sftp_dl/<session_id>')
Expand Down
2 changes: 1 addition & 1 deletion application/routes/vnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def change_vncpasswd():

vnc, reason = create_connection(session_id, ConnectionType.VNC)
if reason != '':
logger.error("create_connection() failed with status=", status)
logger.error("create_connection() failed with status=", reason)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Align log message formatting for clarity.
Here, you are passing reason as a second argument without using the %s placeholder. For consistency with other calls (e.g., line 117 logs reset_vnc_password() failed with status=%s), consider:

-logger.error("create_connection() failed with status=", reason)
+logger.error("create_connection() failed with status=%s", reason)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
logger.error("create_connection() failed with status=", reason)
logger.error("create_connection() failed with status=%s", reason)

abort(403, description=reason)

passwd = request.json.get('passwd')
Expand Down
Loading