// The reading log's scratch session key (server side: node:crypto). import { createHash } from "node:crypto"; /** * The scratch session a reading log belongs to until R2's cases exist: the * query and the scope, normalised, hashed. Same query, same scope, same log. * * @param {Record} scope source, query, regex, channels, dates, states, mediaType, posts */ export function sessionKey(scope) { const norm = { source: String(scope.source ?? ""), query: String(scope.query ?? "").trim(), regex: scope.regex === true, channels: [...((scope.channels ?? []))].map(String).sort(), dateFrom: scope.dateFrom ?? "", dateTo: scope.dateTo ?? "", states: [...((scope.states ?? []))].map(String).sort(), mediaType: scope.mediaType ?? "", posts: scope.posts === true, }; return createHash("sha1").update(JSON.stringify(norm)).digest("hex").slice(0, 16); }