Skip to content

Conversation

@faretek1
Copy link
Collaborator

@faretek1 faretek1 commented Jun 2, 2025

correctly decode sb2 (#415)

(project data that is not sent as project JSON, but as a sb2 (zip) file)

Sometimes, regarding 2.0 projects, the regular JSON endpoint for the project actually returns an sb2 file. This pull request

  1. specifically catches the JSON decoder error when attempting to json-decode a zip file
  2. decode the zip file and return project.json from the zip, if the previous error is caught

Note

It is interesting to note that both sa.editor and project_json_capabilities use this same method for getting project JSON data by id, but it is wasteful to not cache the asset data included within the zip file. Since both of these submodules use this method, there is also probably not going to be code duplication.

I tested this like so:

import warnings
from pprint import pprint

import scratchattach as sa
from local_test.payload import faretek1

warnings.filterwarnings('ignore', category=sa.LoginDataWarning)

sess = sa.login(**faretek1)


print(sess.connect_project("1023073403").raw_json())
print(sess.connect_project("918894112").raw_json())

todo:

  • test
  • edit/add comments

@faretek1 faretek1 marked this pull request as ready for review June 2, 2025 21:47
@faretek1
Copy link
Collaborator Author

faretek1 commented Jun 2, 2025

i don't see why to not merge this

@faretek1 faretek1 merged commit efa5b5b into TimMcCool:main Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant