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
4 changes: 2 additions & 2 deletions application/routes/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#
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 +53,4 @@ def start_audio():
'audio_id': audio.id
}

return json.dumps(result)
return jsonify(result)
4 changes: 2 additions & 2 deletions application/routes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import json
Copy link
Owner

Choose a reason for hiding this comment

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

ditto. If json is no longer needed to be imported, remove.

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 +80,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
4 changes: 2 additions & 2 deletions application/routes/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import json

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

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Approve import change and suggest removal of unused import

The addition of jsonify from Flask is correct and aligns with the PR objective. However, the json import at the beginning of the file is now unused and should be removed.

Please remove the unused json import at the beginning of the file:

-import json

Committable suggestion was skipped due to low confidence.


from .common import create_connection
from .. import api, app
Expand Down Expand Up @@ -59,7 +59,7 @@ def generate():
'port': TERMINAL_PORT,
'term_id': term.id
}
yield json.dumps(result)
yield jsonify(result)
Copy link
Owner

Choose a reason for hiding this comment

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

The response type is application/octet-stream here and using jsonify introduces unnecessary overhead with mere benefits. Consider reverting the change.


return app.response_class(stream_with_context(generate()), mimetype='application/octet-stream')

Expand Down
4 changes: 2 additions & 2 deletions application/routes/vnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import json
import logging

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, profiles
Expand Down Expand Up @@ -93,7 +93,7 @@ def generate():
'port': ws_port,
'credentials': credentials
}
yield json.dumps(result)
yield jsonify(result)
Copy link
Owner

Choose a reason for hiding this comment

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

The response type is application/octet-stream here and using jsonify introduces unnecessary overhead with mere benefits. Consider reverting the change.


return app.response_class(stream_with_context(generate()), mimetype='application/octet-stream')

Expand Down
Loading