logos
The pictures of applications and links, served by this node so that no page loads one from elsewhere.
A store names an application's logo by an address on the web, a PRoot Apps
remote its icons the same way, and an administrator may give a home link an
https picture. Such an address never reaches a client: wherever the server
hands one out, local turns it into /api/logos/<name>, <name> being the
hash of the address, and remembers the address under that name. The picture
behind a name is fetched by this node when a store is refreshed (prefetch)
or the first time a client asks for it, and kept under
app_store_cache_path/logos, each node its own copy. A picture is served
with caching headers and a content security policy that keeps a script in an
SVG from running on the web app's origin, since a store, not an
administrator, chose it.
attributelogger= logging.getLogger(__name__)attributeROUTE= '/api/logos/'attributeMAX_BYTES= 2000000attributeTYPES= {'image/png': 'png', 'image/jpeg': 'jpg', 'image/webp': 'webp', 'image/gif': 'gif', 'image/svg+xml': 'svg', 'image/avif': 'avif', 'image/x-icon': 'ico', 'image/vnd.microsoft.icon': 'ico'}attributeMAX_AGE= 86400attributePARALLEL= 6attributeTIMEOUT= httpx.Timeout(15.0, connect=5.0)funcname_of(address) -> strReturn the name a picture at address is served under.
paramaddressstrReturns
strfunclocal(address) -> strReturn the address a client loads a picture from, remembering a web address under its name.
Anything but an http or https address, such as an uploaded icon's path
or nothing, is returned as it is.
paramaddressstrReturns
strfunc_dir() -> strReturns
strfunc_find(name) -> tuple[str, str] | NoneReturn the file and media type of a cached picture, or None where there is none.
paramnamestrReturns
tuple[str, str] | Nonefunc_download(client, address) -> tuple[bytes, str] | NoneFetch a picture, or return None when what answers is not a picture this server keeps.
paramclienthttpx.AsyncClientparamaddressstrReturns
tuple[bytes, str] | Nonefuncfetch(name) -> tuple[bytes, str] | NoneReturn the bytes and media type of a picture, fetching it into the cache when it is not there yet.
paramnamestrReturns
tuple[bytes, str] | NoneNone for a name never handed out or a picture that could not be had.
funcprefetch() -> NoneFetch every known picture that is not cached yet, and drop the files of addresses no longer handed out.
Returns
Nonefuncserve(name, request) -> ResponseAnswer a client's request for a picture by name, 404 for one this server never handed out.
paramnamestrparamrequestRequestReturns
fastapi.Responsefuncreset() -> NoneForget every address, for a test.
Returns
None