mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: migrate to asset uploader
This commit is contained in:
1 parent
797307fb81
commit
a3bb023309
29 files changed
+764
-1003
No files matched your search
@@ -2,31 +2,34 @@ import {
|
||||
assertSecret,
|
||||
fetchTankDefinitions,
|
||||
PopularTanks,
|
||||
} from '@blitzkit/core';
|
||||
import { google } from 'googleapis';
|
||||
import { commitAssets } from '../core/github/commitAssets';
|
||||
} from "@blitzkit/core";
|
||||
import { google } from "googleapis";
|
||||
import { AssetUploader } from "../core/github/assetUploader";
|
||||
|
||||
export async function popularTanks() {
|
||||
using uploader = new AssetUploader("popular tanks");
|
||||
const tankDefinitions = await fetchTankDefinitions();
|
||||
|
||||
const auth = await google.auth.getClient({
|
||||
keyFile: import.meta.env.GOOGLE_APPLICATION_CREDENTIALS,
|
||||
scopes: ['https://www.googleapis.com/auth/analytics.readonly'],
|
||||
scopes: ["https://www.googleapis.com/auth/analytics.readonly"],
|
||||
});
|
||||
const analytics = google.analyticsdata({ version: 'v1beta', auth });
|
||||
const analytics = google.analyticsdata({ version: "v1beta", auth });
|
||||
const report = await analytics.properties.runReport({
|
||||
property: `properties/${assertSecret(import.meta.env.PUBLIC_GOOGLE_ANALYTICS_PROPERTY_ID)}`,
|
||||
property: `properties/${assertSecret(
|
||||
import.meta.env.PUBLIC_GOOGLE_ANALYTICS_PROPERTY_ID
|
||||
)}`,
|
||||
requestBody: {
|
||||
dateRanges: [{ startDate: '7daysAgo', endDate: 'today' }],
|
||||
dimensions: [{ name: 'pagePath' }],
|
||||
metrics: [{ name: 'screenPageViews' }],
|
||||
orderBys: [{ metric: { metricName: 'screenPageViews' }, desc: true }],
|
||||
dateRanges: [{ startDate: "7daysAgo", endDate: "today" }],
|
||||
dimensions: [{ name: "pagePath" }],
|
||||
metrics: [{ name: "screenPageViews" }],
|
||||
orderBys: [{ metric: { metricName: "screenPageViews" }, desc: true }],
|
||||
dimensionFilter: {
|
||||
filter: {
|
||||
fieldName: 'pagePath',
|
||||
fieldName: "pagePath",
|
||||
stringFilter: {
|
||||
matchType: 'BEGINS_WITH',
|
||||
value: '/tanks/',
|
||||
matchType: "BEGINS_WITH",
|
||||
value: "/tanks/",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -34,7 +37,7 @@ export async function popularTanks() {
|
||||
});
|
||||
|
||||
if (!report.data.rows) {
|
||||
throw new Error('No rows in report');
|
||||
throw new Error("No rows in report");
|
||||
}
|
||||
|
||||
const tanks = report.data.rows
|
||||
@@ -42,21 +45,21 @@ export async function popularTanks() {
|
||||
(row) =>
|
||||
row.dimensionValues &&
|
||||
row.dimensionValues[0].value &&
|
||||
row.dimensionValues[0].value !== '/tanks/' &&
|
||||
row.dimensionValues[0].value !== "/tanks/" &&
|
||||
row.metricValues &&
|
||||
row.metricValues[0].value,
|
||||
row.metricValues[0].value
|
||||
)
|
||||
.map((row) => ({
|
||||
id: Number(
|
||||
row.dimensionValues![0].value!.match(
|
||||
/\/tools\/tankopedia\/(\d+)\/?/,
|
||||
)?.[1],
|
||||
/\/tools\/tankopedia\/(\d+)\/?/
|
||||
)?.[1]
|
||||
),
|
||||
views: Number(row.metricValues![0].value!),
|
||||
}))
|
||||
.filter((row) => {
|
||||
if (!(row.id in tankDefinitions.tanks)) {
|
||||
console.warn('Skipping unknown popular tank', row.id);
|
||||
console.warn("Skipping unknown popular tank", row.id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -66,10 +69,9 @@ export async function popularTanks() {
|
||||
.map(({ id, views }) => ({ id, views }));
|
||||
const popularTanks: PopularTanks = { tanks };
|
||||
|
||||
await commitAssets('popular tanks', [
|
||||
{
|
||||
path: 'definitions/popular-tanks.pb',
|
||||
content: PopularTanks.encode(popularTanks).finish(),
|
||||
},
|
||||
]);
|
||||
await uploader.add({
|
||||
path: "definitions/popular-tanks.pb",
|
||||
content: PopularTanks.encode(popularTanks).finish(),
|
||||
});
|
||||
await uploader.flush();
|
||||
}
|
||||
Reference in new issue
Block a user