MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / static_url

Function static_url

openlibrary/plugins/upstream/code.py:144–150  ·  view source on GitHub ↗

Takes path relative to static/ and constructs url to that resource with hash.

(path)

Source from the content-addressed store, hash-verified

142@functools.cache
143@public
144def static_url(path):
145 """Takes path relative to static/ and constructs url to that resource with hash."""
146 pardir = os.path.pardir
147 fullpath = os.path.abspath(os.path.join(__file__, pardir, pardir, pardir, pardir, "static", path))
148 with open(fullpath, "rb") as in_file:
149 digest = hashlib.md5(in_file.read()).hexdigest()
150 return f"/static/{path}?v={digest}"
151
152
153class DynamicDocument:

Callers 1

render_componentFunction · 0.90

Calls 2

md5Method · 0.80
readMethod · 0.80

Tested by

no test coverage detected