Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare #1509

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/.node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.18.0
22.11.0
40 changes: 20 additions & 20 deletions web/src/lib/server/Restriction.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// import {
// CLOUDFLARE_ACCOUNT_ID,
// CLOUDFLARE_API_TOKEN,
// CLOUDFLARE_KV_NAMESPACE_ID
// } from '$env/static/private';
import {
CLOUDFLARE_ACCOUNT_ID,
CLOUDFLARE_API_TOKEN,
CLOUDFLARE_KV_NAMESPACE_ID
} from '$env/static/private';
import { error } from '@sveltejs/kit';

export async function checkRestriction(pubkey: string): Promise<void> {
console.time('[npub restriction]');

// if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN || !CLOUDFLARE_KV_NAMESPACE_ID) {
// return;
// }
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN || !CLOUDFLARE_KV_NAMESPACE_ID) {
return;
}

// const url = `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/storage/kv/namespaces/${CLOUDFLARE_KV_NAMESPACE_ID}/values/${pubkey}`;
// const response = await fetch(url, {
// headers: {
// Authorization: `Bearer ${CLOUDFLARE_API_TOKEN}`
// }
// });
// console.timeEnd('[npub restriction]');
// if (response.ok) {
// const restriction = (await response.json()) as Restriction;
// console.error('[npub restriction]', restriction);
// error(restriction.status, restriction.statusText);
// }
const url = `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/storage/kv/namespaces/${CLOUDFLARE_KV_NAMESPACE_ID}/values/${pubkey}`;
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${CLOUDFLARE_API_TOKEN}`
}
});
console.timeEnd('[npub restriction]');
if (response.ok) {
const restriction = (await response.json()) as Restriction;
console.error('[npub restriction]', restriction);
error(restriction.status, restriction.statusText);
}
}

interface Restriction {
Expand Down
Loading