Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/server/routes/clade_cumulus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ end
end

@post "/api/v1/studies/{study}/runs/{run}/clade-cumulus" function(req::HTTP.Request, study::String, run::String)
try
return _clade_cumulus_post_impl(req, study, run)
catch e
@error "clade-cumulus request failed" exception = (e, catch_backtrace())
return json_error(500, "clade_cumulus_failed", sprint(showerror, e))
end
end

function _clade_cumulus_post_impl(req::HTTP.Request, study::String, run::String)
group = _req_group(req)
err = _validate_run_request(study, run)
!isnothing(err) && return err
Expand Down
10 changes: 5 additions & 5 deletions src/server/routes/trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ const _TREE_MAX_BYTES = 50 * 1024 * 1024
const _VIEW_MAX_BYTES = 5 * 1024 * 1024
const _tree_view_lock = ReentrantLock()

_trees_dir(study::String) = joinpath(ServerState.projects_dir(), study, "trees")
_tree_view_path(study::String, file::String) = joinpath(_trees_dir(study), ".views", file * ".json")
_trees_dir(study::AbstractString) = joinpath(ServerState.projects_dir(), study, "trees")
_tree_view_path(study::AbstractString, file::AbstractString) = joinpath(_trees_dir(study), ".views", file * ".json")

_tree_format(file::AbstractString) = endswith(lowercase(file), ".jplace") ? "jplace" : "newick"

function _valid_tree_file(file::AbstractString)::Bool

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Normalize the tree filename before calling _tree_format

When treeFile comes from the JSON request, _resolve_tree_inputs_from_request obtains a SubString from strip; widening this validator lets that value pass, but the same path then calls the still-String-only _tree_format(tree_file) at src/server/routes/clade_cumulus.jl:113. Thus every treeSource: "study_tree" POST reaches a MethodError before the analysis try/catch and returns 500; convert tree_file to String at the request boundary or widen _tree_format too.

Useful? React with 👍 / 👎.

_valid_name(file) && any(ext -> endswith(lowercase(file), ext), _TREE_EXTENSIONS)
end

function _study_exists(study::String)::Bool
function _study_exists(study::AbstractString)::Bool
_valid_name(study) &&
(isdir(joinpath(ServerState.projects_dir(), study)) || study in _study_names())
end

function _tree_request_error(study::String, file::Union{String,Nothing}=nothing)
function _tree_request_error(study::AbstractString, file::Union{AbstractString,Nothing}=nothing)
_study_exists(study) || return json_error(404, "study_not_found", "Study '$study' not found")
isnothing(file) && return nothing
_valid_tree_file(file) || return json_error(400, "invalid_name",
"Tree files need a plain name ending in one of: $(join(_TREE_EXTENSIONS, ", "))")
nothing
end

function _tree_listing(study::String)
function _tree_listing(study::AbstractString)
dir = _trees_dir(study)
isdir(dir) || return NamedTuple[]
files = sort(filter(f -> _valid_tree_file(f) && isfile(joinpath(dir, f)), readdir(dir)))
Expand Down
Loading