예제 #1
0
def download_file_in_problem_config(
    path: str = Path(...),
    problem: models.Problem = Depends(parse_problem),
    config: Optional[models.ProblemConfig] = Depends(parse_problem_config),
) -> Any:
    problem_config = LakeFSProblemConfig(problem)
    ref: Optional[str]
    if config is not None:
        ref = config.commit_id
    else:
        ref = None
    file = problem_config.download_file(pathlib.Path(path), ref)
    response = StreamingResponse(file)
    filename = pathlib.Path(path).name
    response.content_disposition = f'attachment; filename="{filename}"'
    return response
예제 #2
0
def download_problem_config_archive(
    temp_dir: pathlib.Path = Depends(TemporaryDirectory()),
    archive_format: ArchiveType = Query(ArchiveType.zip),
    problem: models.Problem = Depends(parse_problem),
    config: Optional[models.ProblemConfig] = Depends(parse_problem_config),
) -> Any:
    # use lakefs to sync and zip files
    ref: Optional[str]
    if config is not None:
        ref = config.commit_id
    else:
        ref = None
    problem_config = LakeFSProblemConfig(problem)
    file_path = problem_config.download_archive(temp_dir, archive_format, ref)
    # TODO: cache the archive
    response = StreamingResponse(iter_file(file_path))
    response.content_disposition = f'attachment; filename="{file_path.name}"'
    return response