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.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intBase64 of a 32-byte hash is 44 chars including one '=' pad; tokens stop before it.private static final intFloor for readability/stability: tokens shorter than this are too collision-prone.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static intLongest common prefix length of two strings.mint(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.
Field Details
MAX_TOKEN_LEN
private static final int MAX_TOKEN_LENBase64 of a 32-byte hash is 44 chars including one '=' pad; tokens stop before it.- See Also:
MIN_TOKEN_LEN
private static final int MIN_TOKEN_LENFloor for readability/stability: tokens shorter than this are too collision-prone.- See Also:
Constructor Details
ActionTokens
private ActionTokens()Utility class, not intended for instantiation.
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
lcp