Oscar
Oscar
CDCloudflare Developers
Created by boggin on 7/22/2023 in #pages-help
Sveltekit and private images related: ERROR 9425 Image access denied: sig query-string argument is n
@boggin. thanks for the help... 4 days later - I realize there's a difference between the API key and the key used to serve images... yikes
8 replies
CDCloudflare Developers
Created by Oscar on 9/18/2023 in #pages-help
Unable to serve private CF images
Here's the code, 95% copied from the sample code linked above
const EXPIRATION = 60 * 60 * 24; // 1 day

const bufferToHex = (buffer: ArrayBufferLike) =>
[...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('');

export async function generateSignedUrl(imageId: string) {
const url = new URL(`https://imagedelivery.net/${env.CF_ACCOUNT_HASH}/${imageId}/public`);
const encoder = new TextEncoder();
const secretKeyData = encoder.encode(env.CF_IMAGES_SECRET_KEY);
const key = await crypto.subtle.importKey(
'raw',
secretKeyData,
{ name: 'HMAC', hash: 'SHA-256' },
false,
['sign'],
);

const expiry = Math.floor(Date.now() / 1000) + EXPIRATION;
url.searchParams.set('exp', String(expiry));

const stringToSign = url.pathname + '?' + url.searchParams.toString();

const mac = await crypto.subtle.sign('HMAC', key, encoder.encode(stringToSign));
const sig = bufferToHex(new Uint8Array(mac).buffer);
url.searchParams.set('sig', sig);
return url;
}
const EXPIRATION = 60 * 60 * 24; // 1 day

const bufferToHex = (buffer: ArrayBufferLike) =>
[...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('');

export async function generateSignedUrl(imageId: string) {
const url = new URL(`https://imagedelivery.net/${env.CF_ACCOUNT_HASH}/${imageId}/public`);
const encoder = new TextEncoder();
const secretKeyData = encoder.encode(env.CF_IMAGES_SECRET_KEY);
const key = await crypto.subtle.importKey(
'raw',
secretKeyData,
{ name: 'HMAC', hash: 'SHA-256' },
false,
['sign'],
);

const expiry = Math.floor(Date.now() / 1000) + EXPIRATION;
url.searchParams.set('exp', String(expiry));

const stringToSign = url.pathname + '?' + url.searchParams.toString();

const mac = await crypto.subtle.sign('HMAC', key, encoder.encode(stringToSign));
const sig = bufferToHex(new Uint8Array(mac).buffer);
url.searchParams.set('sig', sig);
return url;
}
2 replies
CDCloudflare Developers
Created by boggin on 7/22/2023 in #pages-help
Sveltekit and private images related: ERROR 9425 Image access denied: sig query-string argument is n
@boggin. Did you ever figure this one out? Having exactly the same trouble
8 replies
DTDrizzle Team
Created by cobite on 8/28/2023 in #help
How to get the count of records? Here is my normal sql, trying to translate into drizzle
100 replies
DTDrizzle Team
Created by Cory on 6/30/2023 in #help
It is possible to have prepared statements inside transactions?
In case anyone else finds this post searching for an answer, it's an open issue: https://github.com/drizzle-team/drizzle-orm/issues/613
2 replies