~james/core

core/web/src/lib/api/rawCommit.ts -rw-r--r-- 711 bytes
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// a full commit hash, and the raw /commit/<hash>.patch|.diff specs. a leaf module, no
// imports: src/params.ts matches routes with it, and kit loads that file outside vite
// go-git's IsHash accepts uppercase hex too (hex.DecodeString), both sha1
// and sha256 match case-insensitively
export const FULL_HASH_RE = /^([0-9a-fA-F]{40}|[0-9a-fA-F]{64})$/;

export const parseRawCommit = (spec: string): { ref: string; format: "patch" | "diff" } | null => {
	const dot = spec.lastIndexOf(".");
	if (dot === -1) return null;
	const format = spec.slice(dot + 1);
	if (format !== "patch" && format !== "diff") return null;
	const ref = spec.slice(0, dot);
	return FULL_HASH_RE.test(ref) ? { ref, format } : null;
};