This commit is contained in:
1 parent
1a462c54da
commit
e1129c305e
2 files changed
+10
-4
No files matched your search
@@ -53,7 +53,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (r2Data.length > 0) {
|
if (r2Data.length > 0) {
|
||||||
r2PayloadSize = r2Data[0]?.sum?.payloadSize || 0;
|
r2PayloadSize = r2Data[0]?.max?.payloadSize || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.errorMsg) {
|
if (data.errorMsg) {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export async function fetchAnalytics(platform: App.Platform | undefined) {
|
|||||||
d1Query = `
|
d1Query = `
|
||||||
d1AnalyticsAdaptiveGroups(
|
d1AnalyticsAdaptiveGroups(
|
||||||
limit: 10000,
|
limit: 10000,
|
||||||
filter: { datetime_geq: "${thirtyDaysAgo}T00:00:00Z", databaseId: "${d1Id}" }
|
filter: { date_geq: "${thirtyDaysAgo}", databaseId: "${d1Id}" }
|
||||||
) {
|
) {
|
||||||
sum {
|
sum {
|
||||||
readQueries
|
readQueries
|
||||||
@@ -98,7 +98,7 @@ export async function fetchAnalytics(platform: App.Platform | undefined) {
|
|||||||
filter: { datetime_geq: "${thirtyDaysAgo}T00:00:00Z", bucketName: "${r2Bucket}" },
|
filter: { datetime_geq: "${thirtyDaysAgo}T00:00:00Z", bucketName: "${r2Bucket}" },
|
||||||
orderBy: [datetime_DESC]
|
orderBy: [datetime_DESC]
|
||||||
) {
|
) {
|
||||||
sum {
|
max {
|
||||||
payloadSize
|
payloadSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,6 +155,7 @@ export async function fetchAnalytics(platform: App.Platform | undefined) {
|
|||||||
|
|
||||||
let d1Data: any[] = [];
|
let d1Data: any[] = [];
|
||||||
let r2Data: any[] = [];
|
let r2Data: any[] = [];
|
||||||
|
let accErrorMsg = '';
|
||||||
|
|
||||||
if (accountQuery) {
|
if (accountQuery) {
|
||||||
const accQueryStr = `query { viewer { ${accountQuery} } }`;
|
const accQueryStr = `query { viewer { ${accountQuery} } }`;
|
||||||
@@ -167,6 +168,10 @@ export async function fetchAnalytics(platform: App.Platform | undefined) {
|
|||||||
body: JSON.stringify({ query: accQueryStr })
|
body: JSON.stringify({ query: accQueryStr })
|
||||||
});
|
});
|
||||||
const accResult = (await accRes.json()) as any;
|
const accResult = (await accRes.json()) as any;
|
||||||
|
if (accResult.errors) {
|
||||||
|
console.error('Account GraphQL Errors:', accResult.errors);
|
||||||
|
accErrorMsg = '账户数据查询失败: ' + (accResult.errors[0]?.message || 'Unknown');
|
||||||
|
}
|
||||||
const accountData = accResult?.data?.viewer?.accounts?.[0];
|
const accountData = accResult?.data?.viewer?.accounts?.[0];
|
||||||
if (accountData) {
|
if (accountData) {
|
||||||
d1Data = accountData.d1AnalyticsAdaptiveGroups || [];
|
d1Data = accountData.d1AnalyticsAdaptiveGroups || [];
|
||||||
@@ -178,7 +183,8 @@ export async function fetchAnalytics(platform: App.Platform | undefined) {
|
|||||||
traffic: trafficData,
|
traffic: trafficData,
|
||||||
d1: d1Data,
|
d1: d1Data,
|
||||||
r2: r2Data,
|
r2: r2Data,
|
||||||
missingEnvVars: !accountId || !d1Id || !r2Bucket
|
missingEnvVars: !accountId || !d1Id || !r2Bucket,
|
||||||
|
errorMsg: accErrorMsg ? accErrorMsg : undefined
|
||||||
};
|
};
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Failed to fetch analytics', err);
|
console.error('Failed to fetch analytics', err);
|
||||||
|
|||||||
Reference in new issue
Block a user