INNER CODE UNIT · TypeScript
generateCode
Hash-Studios/Prism · infra/cloudflare/worker/src/index.ts:715
function generateCode(length: number): string {
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const bytes = crypto.getRandomValues(new Uint8Array(length));
let out = '';
for (let i = 0; i < bytes.length; i += 1) {
out += alphabet[bytes[i] % alphabet.length];
}
return out;
}
async function generateAndPersistOgImage(code: string, record: LinkRecord, env: Env): Promise<OgStorageType | null> {
const pngBytes = await renderOgImageWithBrowserRendering(code, record, env);
if (pngBytes == null) {
return null;
}
const objectKey = ogObjectKey(code, record.version);
if (env.OG_IMAGES != null) {