java.lang.Object
org.klomp.snark.web.ActionTokens
Mints and resolves short, unique action tokens for per-torrent form controls. A token is the shortest prefix of a torrent's base64 info-hash name that no other currently-loaded torrent shares, floored at 4 chars so tokens stay readable and the stale-token match surface stays small. Tokens are recomputed from the live torrent set on every render (stateless), so uniqueness within a render is guaranteed by construction; POST resolution requires exactly one matching torrent, which makes stale or ambiguous tokens degrade to a safe no-op rather than a misdirected action. Replaces 44-char full-hash parameter names, shrinking row markup by ~40 bytes per control.
Method Summary
All MethodsModifier and TypeMethodDescriptionmint(Collection<String> names) Mints minimal unique prefix tokens for the given names.static StringresolveUnique(String token, Collection<String> names) Resolves a token against candidate names: returns the single name that starts with the token, or null when none or several do.
Method Details
mint
Mints minimal unique prefix tokens for the given names. Names are sorted once; each name's token length is one past the longest common prefix it shares with either sorted neighbor, so every token is distinct from every other by construction. Identical names cannot occur (one info hash = one torrent).- Parameters:
names- base64 info-hash names of all rendered torrents- Returns:
- map of full name to its token; every input name has an entry
resolveUnique
Resolves a token against candidate names: returns the single name that starts with the token, or null when none or several do. The multi-match null return is what makes stale/ambiguous tokens a safe no-op instead of a misdirected action.- Parameters:
token- the token extracted from a submitted control namenames- base64 info-hash names of all currently loaded torrents- Returns:
- the unique matching name, or null when zero or multiple match