Skip to content
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

add possibility to register directories #417

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 11 additions & 9 deletions src/asset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,21 @@ function path2url(path::AbstractString)
:webio_pkg_urls,
)
return path
elseif startswith(path, "/assetserver/") && haskey(AssetRegistry.registry, path)
# check if file or containing directory has already been registered
elseif startswith(path, "/assetserver/") && haskey(AssetRegistry.registry, join(split(path, "/")[1:3],"/"))
return path
elseif isfile(abspath(path))
elseif isfile(abspath(path)) || isdir(abspath(path))
# TODO: this should be implemented in AssetRegistry, not here.
path = abspath(path)
# first lookup to see if any of the file itself or any of the parent
# directories are registered.
AssetRegistry.isregistered(path) && AssetRegistry.getkey(path)
AssetRegistry.isregistered(path) && return AssetRegistry.getkey(path)
cur_path = path
while true
if AssetRegistry.isregistered(cur_path) && isdir(cur_path)
key = AssetRegistry.getkey(cur_path)
url = key * "/" * replace(replace(path, cur_path => ""), r"^\/"=>"")
#strip cur_path and convert all backslashes to slashes (for windows ;-) )
url = key * replace(SubString(path, length(cur_path) + 1, length(path)), "\\" => "/")
return url
end
cur_path1 = dirname(cur_path)
Expand All @@ -220,9 +222,9 @@ there.
function dep2url(dep::AbstractString)
# if is an url, we are done :)
islocal(dep) || return dep
query_parts = split(dep, "?") # remove anything after ?
file_path = first(query_parts)
query_part = length(query_parts) >= 2 ? "?" * query_parts[2] : ""
url = path2url(file_path)
return string(baseurl[], url, query_part)
# split query from url path, including further '?'s
url_parts = split(dep, "?")
# register the url file without the query part
url_parts[1] = path2url(baseurl[] * url_parts[1])
return join(url_parts, "?")
end