Skip to content

Commit e713850

Browse files
authored
include metadata JSON file in output zip (#178)
* include metadata JSON file in output zip * formatting
1 parent 0e98928 commit e713850

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

backend/app/routers/datasets.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,25 @@ async def download_dataset(
652652
f.write("BagIt-Version: 0.97" + "\n")
653653
f.write("Tag-File-Character-Encoding: UTF-8" + "\n")
654654

655+
# Write dataset metadata if found
656+
metadata = []
657+
async for md in db["metadata"].find(
658+
{"resource.resource_id": ObjectId(dataset_id)}
659+
):
660+
metadata.append(md)
661+
if len(metadata) > 0:
662+
datasetmetadata_path = os.path.join(
663+
current_temp_dir, "_dataset_metadata.json"
664+
)
665+
metadata_content = json_util.dumps(metadata)
666+
with open(datasetmetadata_path, "w") as f:
667+
f.write(metadata_content)
668+
crate.add_file(
669+
datasetmetadata_path,
670+
dest_path="metadata/_dataset_metadata.json",
671+
properties={"name": "_dataset_metadata.json"},
672+
)
673+
655674
bag_size = 0 # bytes
656675
file_count = 0
657676

@@ -684,7 +703,6 @@ async def download_dataset(
684703
current_file_size = os.path.getsize(current_file_path)
685704
bag_size += current_file_size
686705

687-
# TODO add file metadata
688706
metadata = []
689707
async for md in db["metadata"].find(
690708
{"resource.resource_id": ObjectId(file.id)}

0 commit comments

Comments
 (0)