diff --git a/functions/gcloud.ts b/functions/gcloud.ts index 70d656e..3d62c12 100644 --- a/functions/gcloud.ts +++ b/functions/gcloud.ts @@ -100,88 +100,6 @@ export async function GetAccessToken(env: Env): Promise { return ((await tokenRequest.json()) as { [k: string]: any }).access_token; } -async function getKeyIDs( - access_token: string, - projectId: string, - keys: { partitionId: { projectId: string }; path: { kind: string }[] }[], -) { - const keyRequest = await fetch( - `https://datastore.googleapis.com/v1/projects/${projectId}:allocateIds`, - { - body: JSON.stringify({ keys }), - headers: { - authorization: `Bearer ${access_token}`, - "content-type": "application/json", - }, - method: "POST", - }, - ); - - if (!keyRequest.ok) { - console.log(await keyRequest.json()); - throw new Error("Failed to allocate key IDs"); - } - - return ((await keyRequest.json()) as { keys: { [k: string]: any }[] }).keys; -} - -export async function queryLogs(user: number, context: RequestContext) { - const accessToken = await GetAccessToken(context.env); - - const queryRequest = await fetch( - `https://datastore.googleapis.com/v1/projects/${context.env.DATASTORE_PROJECT}:runQuery`, - { - body: JSON.stringify({ - partitionId: { - projectId: context.env.DATASTORE_PROJECT, - }, - query: { - filter: { - propertyFilter: { - op: "EQUAL", - property: { - name: "target", - }, - value: { - integerValue: user.toString(), - }, - }, - }, - kind: [ - { - name: "log", - }, - ], - }, - }), - headers: { - authorization: `Bearer ${accessToken}`, - "content-type": "application/json", - }, - method: "POST", - }, - ); - - if (!queryRequest.ok) { - console.log(await queryRequest.json()); - throw new Error("Failed to query logs"); - } - - return ( - ( - (await queryRequest.json()) as { - batch: { - entityResults: { - cursor: string; - entity: { [k: string]: any }; - version: string; - }[]; - }; - } - ).batch?.entityResults ?? [] - ); -} - export async function sendPushNotification( env: Env, title: string,