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

Fix copy network #186

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion front/src/miminet_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,26 @@ def copy_network():
n = Network(author_id=user.id, guid=str(u))
n.network = net.network
n.title = net.title + str(" - копия")
n.preview_uri = net.preview_uri

new_picture_blob_uri = os.urandom(16).hex() + ".png"
Copy link
Collaborator

Choose a reason for hiding this comment

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

ты скопировал способ генерации picture_blob_uri.
Тогда лучше выделить его в метод/функцию и применить в обоих местах, чтобы небыло копирования кода.

try:
copy_picture_blob = open(
"static/images/preview/" + net.preview_uri, "rb"
).read()
except Exception:
ret = {"message": "Не могу скопировать PNG"}
return make_response(jsonify(ret), 400)

try:
open("static/images/preview/" + new_picture_blob_uri, "wb").write(
copy_picture_blob
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Это очень странный способ скопировать файл.
Используй https://docs.python.org/3/library/shutil.html

except Exception:
ret = {"message": "Не могу сохранить копию PNG"}
return make_response(jsonify(ret), 400)

n.preview_uri = new_picture_blob_uri

db.session.add(n)
db.session.commit()
ret = {"message": "Сделана копия.", "new_url": "/web_network?guid=" + str(u)}
Expand Down
Loading