Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove old queryLogs function
  • Loading branch information
regalijan committed Mar 21, 2024
1 parent 1adda19 commit aa7475f
Showing 1 changed file with 0 additions and 82 deletions.
82 changes: 0 additions & 82 deletions functions/gcloud.ts
Expand Up @@ -100,88 +100,6 @@ export async function GetAccessToken(env: Env): Promise<string> {
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,
Expand Down

0 comments on commit aa7475f

Please sign in to comment.