JuliaGizmos / WebIO.jl

A bridge between Julia and the Web.
https://juliagizmos.github.io/WebIO.jl/latest/
Other
228 stars 64 forks source link

add possibility to register directories #417

Open hhaensel opened 4 years ago

hhaensel commented 4 years ago

This is the corrseponding PR to issue #416

Currently, WebIO does not allow for serving of directories.

I propose to slightly modify asset.jl to allow for the serving of directories. This is a prerequisite to adapt PlotlyJS to include mathjax in its output.

To me it looks as if the design is already made for this purpose, but is not fully completed yet. I think one return was forgotten and I chose to use SubString to remove the initial path but include the separator.

hhaensel commented 4 years ago

I've added another commit, which does not cut the query string at a potential '?'. It's even a bit shorter ;-) But I wonder whether baseurl[] * should not be omitted here as it already occurs in AssetRegistry.getkey. Instead it should probably be added in line 185 before "/assetserver/". Please correct me, if I'm wrong. One last question. Currently AssetRegistry.isregistered() computes the key everytime. Wouldn't it be better to check for the value instead, i.e.

isregistered(path) = abspath(path) in values(registry)

instead of

isregistered(path) = haskey(registry, getkey(path))

Getkey could be made faster along the same lines by first checking existing entries.

generatekey(path) =  baseurl[] * "/assetserver/" * bytes2hex(sha1(abspath(path))) * "-" * basename(path)

function getkey(path)
    key = findfirst(x -> x == abspath(path), registry)
    key === nothing ? generatekey(path) : key
end

I could file a PR for AssetRegistry as well, if this is welcome. The main time killer, however, is abspath(), at least on my windows machine ...