Remove old queryLogs function
This commit is contained in:
parent
1adda195f0
commit
aa7475f9d0
@ -100,88 +100,6 @@ export async function GetAccessToken(env: Env): Promise<string> {
|
|||||||
return ((await tokenRequest.json()) as { [k: string]: any }).access_token;
|
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(
|
export async function sendPushNotification(
|
||||||
env: Env,
|
env: Env,
|
||||||
title: string,
|
title: string,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user