-
Notifications
You must be signed in to change notification settings - Fork 479
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
Java Lab: add helper to get all project files #44871
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
module JavalabFilesHelper | ||
# Get all files related to the project at the given channel id as a hash. The hash is in the format | ||
# below. All values are StringIO. | ||
# { | ||
# "main.json": <main source file for a project> | ||
# "assets": {"asset_name_1": <asset_value>, ...} | ||
# "validation": <all validation code for a project, in json format> | ||
# "maze": <serialized maze if it exists> | ||
# } | ||
# If the channel doesn't have validation and/or a maze, those fields will not be present. | ||
def self.get_project_files(channel_id) | ||
storage_id, storage_app_id = storage_decrypt_channel_id(channel_id) | ||
all_files = {} | ||
# get sources file | ||
source_data = SourceBucket.new.get(channel_id, "main.json") | ||
# Note: we can call .string on this value (and all other values for files) to get the raw string. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice - for reference, I'm looking into zipping files in rails right now, and passing a string value for each file seems to be the easiest option, so this will work well! |
||
all_files["main.json"] = source_data[:body] | ||
# get starter assets | ||
assets = {} | ||
asset_bucket = AssetBucket.new | ||
channel = ChannelToken.where(storage_app_id: storage_app_id, storage_id: storage_id).first | ||
level = Level.cache_find(channel.level_id) | ||
if level | ||
starter_asset_bucket = Aws::S3::Bucket.new(LevelStarterAssetsController::S3_BUCKET) | ||
(level&.project_template_level&.starter_assets || level.starter_assets || []).map do |friendly_name, uuid_name| | ||
filename = "#{LevelStarterAssetsController::S3_PREFIX}#{uuid_name}" | ||
asset = starter_asset_bucket.object(filename) | ||
assets[friendly_name] = asset.get.body | ||
end | ||
end | ||
# get level assets | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we may want to switch the order here and fetch starter assets after user assets - we currently have logic (both in Javabuilder and in the asset manager I believe) that if a starter asset file and a user asset file have the same name, we use the starter asset file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call out, will reverse this |
||
asset_list = asset_bucket.list(channel_id) | ||
asset_list.each do |asset| | ||
assets[asset[:filename]] = asset_bucket.get(channel_id, asset[:filename])[:body] | ||
end | ||
all_files["assets"] = assets | ||
# get validation code | ||
if level.respond_to?(:validation) && level.validation | ||
all_files["validation"] = StringIO.new(level.validation.to_json) | ||
end | ||
# get maze file | ||
serialized_maze = level.try(:get_serialized_maze) | ||
if serialized_maze | ||
all_files["maze"] = StringIO.new(serialized_maze.to_s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like both |
||
end | ||
return all_files | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I was originally thinking that we'd store both main.json and the maze file in the same
sources/
folder. My thinking was that if we eventually have other level content, then it could all just reside in sources. That being said though, the maze file isn't really a source file so I can also see a case for it being in its own directory. I'm fine with this being separate, we'll just have to fetch it accordingly in Javabuilder.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong preference here. Would it be better to do the below? That way we have 3 clear categories instead of main.json being an outlier:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah, I think having three categories is clearer and more extensible if we want to add more to sources down the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 will update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!