mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-08 19:16:37 +08:00
type changes
This commit is contained in:
parent
e3a6787f06
commit
0f57257921
@ -74,9 +74,15 @@ export const getAvailableDateKeys = async (): Promise<string[]> => {
|
|||||||
|
|
||||||
export const getSignInCountForPeriod = async (dateKey: string): Promise<number> => {
|
export const getSignInCountForPeriod = async (dateKey: string): Promise<number> => {
|
||||||
try {
|
try {
|
||||||
// Explicitly cast the result of redis.hgetall to an object with string values.
|
const counts = await redis.hgetall(`signin_count:${dateKey}`);
|
||||||
const counts = await redis.hgetall(`signin_count:${dateKey}`) as Record<string, string>;
|
if (counts === null) {
|
||||||
return Object.values(counts).reduce((total, count) => {
|
// If the key does not exist, return 0 as there are no sign-in counts.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we can safely cast counts because we know it's not null.
|
||||||
|
const stringCounts = counts as Record<string, string>;
|
||||||
|
return Object.values(stringCounts).reduce((total, count) => {
|
||||||
// Now TypeScript knows that 'count' is a string.
|
// Now TypeScript knows that 'count' is a string.
|
||||||
return total + parseInt(count, 10);
|
return total + parseInt(count, 10);
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -93,7 +99,9 @@ export const getDetailsByUser = async (dateKey: string): Promise<Record<string,
|
|||||||
const rawCounts = await redis.hgetall(`signin_count:${dateKey}`);
|
const rawCounts = await redis.hgetall(`signin_count:${dateKey}`);
|
||||||
const counts: Record<string, number> = {};
|
const counts: Record<string, number> = {};
|
||||||
|
|
||||||
// Ensure that all values are numbers after parsing.
|
// Check if rawCounts is not null before iterating
|
||||||
|
if (rawCounts) {
|
||||||
|
// Iterate over the entries and parse each value as an integer.
|
||||||
for (const [key, value] of Object.entries(rawCounts)) {
|
for (const [key, value] of Object.entries(rawCounts)) {
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
counts[key] = parseInt(value, 10);
|
counts[key] = parseInt(value, 10);
|
||||||
@ -102,6 +110,7 @@ export const getDetailsByUser = async (dateKey: string): Promise<Record<string,
|
|||||||
counts[key] = 0; // or handle this case as appropriate
|
counts[key] = 0; // or handle this case as appropriate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return counts;
|
return counts;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user