Skip to content

Commit

Permalink
dispatch RESOURCE_FILES_LISTED event after a request to list a resour…
Browse files Browse the repository at this point in the history
…ce's files
  • Loading branch information
Austin Raney committed Jan 7, 2022
1 parent 5f839e3 commit 63609fd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hydroshare_on_jupyter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,14 @@ class ListHydroShareResourceFiles(HeadersMixIn, BaseRequestHandler):
_custom_headers = [("Access-Control-Allow-Methods", "GET")]

def get(self, resource_id: str):
# used in `on_finish`
self.resource_id = resource_id

# NOTE: May want to sanitize input in future. i.e. require it be a min/certain length
session = self.get_hs_session()

# TODO: add `force` argument to force update resource checksums from hydroshare
# implement with use_cache flag
resource = session.resource(resource_id)
files = [
file
Expand All @@ -364,6 +369,13 @@ def get(self, resource_id: str):
# Marshall hsclient representation into CollectionOfResourceMetadata
self.write(ResourceFiles(files=files).json())

def on_finish(self) -> None:
# emit event to notify that a local resource has been listed. if there is local copy, it
# will need to be added to aggregate map
session_sync_struct.event_broker.dispatch(
"RESOURCE_FILES_LISTED", self.resource_id
)


class HydroShareResourceHandler(HeadersMixIn, BaseRequestHandler):
"""Download HydroShare resource to local file system."""
Expand Down

0 comments on commit 63609fd

Please sign in to comment.