SealSkin

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
= 2000000
attributeTYPES
= {'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
= 86400
attributePARALLEL
= 6
attributeTIMEOUT
= httpx.Timeout(15.0, connect=5.0)
funcname_of(address) -> str

Return the name a picture at address is served under.

paramaddressstr

Returns

str
funclocal(address) -> str

Return 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.

paramaddressstr

Returns

str
func_dir() -> str

Returns

str
func_find(name) -> tuple[str, str] | None

Return the file and media type of a cached picture, or None where there is none.

paramnamestr

Returns

tuple[str, str] | None
func_download(client, address) -> tuple[bytes, str] | None

Fetch a picture, or return None when what answers is not a picture this server keeps.

paramclienthttpx.AsyncClient
paramaddressstr

Returns

tuple[bytes, str] | None
funcfetch(name) -> tuple[bytes, str] | None

Return the bytes and media type of a picture, fetching it into the cache when it is not there yet.

paramnamestr

Returns

tuple[bytes, str] | None

None for a name never handed out or a picture that could not be had.

funcprefetch() -> None

Fetch every known picture that is not cached yet, and drop the files of addresses no longer handed out.

Returns

None
funcserve(name, request) -> Response

Answer a client's request for a picture by name, 404 for one this server never handed out.

paramnamestr
paramrequestRequest

Returns

fastapi.Response
funcreset() -> None

Forget every address, for a test.

Returns

None