@@ -6,11 +6,7 @@ import { EventEmitter } from 'node:events';
66import { v4 as uuidv4 } from 'uuid' ;
77
88import cacheMachine from '../utils/cache-machine.mjs' ;
9-
10- const accountId = '424ad63426a1ae47d559873f929eb9fc' ;
11-
12- const productionNamespaceId = '2e6feba88a9e4097b6d2209191ed4ae5' ;
13- const devNameSpaceID = '17fd725f04984e408d4a70b37c817171' ;
9+ import cloudflareKv from './cloudflare-kv.mjs' ;
1410
1511const emitter = new EventEmitter ( ) ;
1612
@@ -43,15 +39,7 @@ async function messageParentProcess(message) {
4339}
4440
4541async function getDataPrimary ( kvName , format ) {
46- const namespaceId = process . env . ENVIRONMENT === 'production' ? productionNamespaceId : devNameSpaceID ;
47- const url = `https://api.cloudflare.com/client/v4/accounts/${ accountId } /storage/kv/namespaces/${ namespaceId } /values/${ kvName } ` ;
48- const response = await fetch ( url , {
49- method : 'GET' ,
50- headers : {
51- 'Content-Type' : 'application/json' ,
52- Authorization : `Bearer ${ process . env . CLOUDFLARE_TOKEN } ` ,
53- } ,
54- } ) ;
42+ const response = await cloudflareKv . get ( kvName ) ;
5543 if ( response . status === 404 ) {
5644 return null ;
5745 }
@@ -68,7 +56,7 @@ async function getDataPrimary(kvName, format) {
6856}
6957
7058async function getDataWorker ( kvName , format ) {
71- return messageParentProcess ( { action : 'getKv' , kvName} ) ;
59+ return messageParentProcess ( { action : 'getKv' , kvName, timeout : 25000 } ) ;
7260}
7361
7462const DATA_CACHE = {
0 commit comments