Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(routing): resolve user codes to handles on 404

When visiting /ac25namuc (a user code), the system now checks the
permahandle API before showing 404. If the code resolves to a handle,
it redirects to @handle instead. Previously these URLs always 404'd
because user codes aren't piece names.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+29 -2
+29 -2
system/public/aesthetic.computer/lib/disk.mjs
··· 7198 7198 isPlaying: false // Whether emulator is running 7199 7199 }; 7200 7200 7201 + // Resolve a user code (e.g. "ac25namuc") to a handle via the permahandle API. 7202 + // Returns the handle string (e.g. "jeffrey") or null if not a user code / not found. 7203 + async function resolveUserCode(slug) { 7204 + if (!slug || slug.length !== 9 || !slug.startsWith("ac")) return null; 7205 + if (!/^ac[0-9]{2}[a-z]{5}$/.test(slug)) return null; 7206 + try { 7207 + const res = await fetch(`/api/permahandle/${slug}`); 7208 + if (!res.ok) return null; 7209 + const data = await res.json(); 7210 + return data.handle || null; 7211 + } catch { 7212 + return null; 7213 + } 7214 + } 7215 + 7201 7216 // 2. ✔ Loading the disk. 7202 7217 let originalHost; 7203 7218 let firstLoad = true; ··· 7898 7913 7899 7914 // Only return a 404 if the error type is correct. 7900 7915 if (firstLoad && (err.message === "404" || err.message === "403")) { 7901 - $commonApi.jump(`404~${slug}`); 7916 + // Check if slug is a user code (e.g. "ac25namuc") and redirect to their profile. 7917 + const handle = await resolveUserCode(slug); 7918 + if (handle) { 7919 + $commonApi.jump(`@${handle}`); 7920 + } else { 7921 + $commonApi.jump(`404~${slug}`); 7922 + } 7902 7923 } else { 7903 7924 $commonApi.notice(":(", ["red", "yellow"]); 7904 7925 } ··· 7926 7947 7927 7948 // Only return a 404 if the error type is correct. 7928 7949 if (firstLoad && (err.message === "404" || err.message === "403")) { 7929 - $commonApi.jump(`404~${slug}`); 7950 + // Check if slug is a user code (e.g. "ac25namuc") and redirect to their profile. 7951 + const handle = await resolveUserCode(slug); 7952 + if (handle) { 7953 + $commonApi.jump(`@${handle}`); 7954 + } else { 7955 + $commonApi.jump(`404~${slug}`); 7956 + } 7930 7957 } else { 7931 7958 $commonApi.notice(":(", ["red", "yellow"]); 7932 7959 }