mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-08-29 10:09:26 +02:00
server(themes): fix crash when fetching install count
This commit is contained in:
@@ -28,7 +28,7 @@ type WorkersKVRESTConfig = {
|
|||||||
export class KVCounter {
|
export class KVCounter {
|
||||||
private readonly client: Cloudflare;
|
private readonly client: Cloudflare;
|
||||||
private readonly mutex: Mutex;
|
private readonly mutex: Mutex;
|
||||||
private installs: Record<string, string[]> = {};
|
private installs: Record<string, string[] | null> = {};
|
||||||
constructor(private readonly config: WorkersKVRESTConfig) {
|
constructor(private readonly config: WorkersKVRESTConfig) {
|
||||||
this.mutex = new Mutex();
|
this.mutex = new Mutex();
|
||||||
this.client = new Cloudflare({
|
this.client = new Cloudflare({
|
||||||
@@ -50,7 +50,7 @@ export class KVCounter {
|
|||||||
const result: Record<string, number> = {};
|
const result: Record<string, number> = {};
|
||||||
const installs = await readMulti(this.client, this.config, keys);
|
const installs = await readMulti(this.client, this.config, keys);
|
||||||
for (const [key, value] of Object.entries(installs)) {
|
for (const [key, value] of Object.entries(installs)) {
|
||||||
result[key] = value.length;
|
result[key] = value?.length ?? 0;
|
||||||
}
|
}
|
||||||
this.installs = installs;
|
this.installs = installs;
|
||||||
return result;
|
return result;
|
||||||
@@ -61,7 +61,7 @@ async function readMulti(
|
|||||||
client: Cloudflare,
|
client: Cloudflare,
|
||||||
config: WorkersKVRESTConfig,
|
config: WorkersKVRESTConfig,
|
||||||
keys: string[]
|
keys: string[]
|
||||||
): Promise<Record<string, string[]>> {
|
): Promise<Record<string, string[] | null>> {
|
||||||
try {
|
try {
|
||||||
const response = await client.kv.namespaces.bulkGet(config.namespaceId, {
|
const response = await client.kv.namespaces.bulkGet(config.namespaceId, {
|
||||||
account_id: config.cfAccountId,
|
account_id: config.cfAccountId,
|
||||||
|
|||||||
Reference in New Issue
Block a user