Compare commits
7 Commits
e0eceffeb3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
26bef47403
|
|||
|
47df3dc55f
|
|||
|
994a7a7a58
|
|||
|
2ca8cc163d
|
|||
|
8e34e2ce24
|
|||
|
7352d0bb43
|
|||
|
291afd5eaa
|
@@ -5,6 +5,13 @@ jobs:
|
||||
Test-Build-Deploy:
|
||||
name: Test, Build, and Deploy
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_PROJECT_NAME: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
|
||||
COMMIT_SHA: ${{ gitea.sha }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
|
||||
@@ -26,14 +33,28 @@ jobs:
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Set Version as Var
|
||||
run: |
|
||||
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/$CLOUDFLARE_PROJECT_NAME \
|
||||
-X PATCH \
|
||||
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"deployment_configs": {
|
||||
"production": {
|
||||
"env_vars": {
|
||||
"COMMIT_SHA": {
|
||||
"type": "plain_text",
|
||||
"value": "'"$COMMIT_SHA"'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}'
|
||||
|
||||
- name: Deploy
|
||||
run: wrangler pages deploy public --project-name $CLOUDFLARE_PROJECT_NAME
|
||||
|
||||
env:
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_PROJECT_NAME: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
|
||||
|
||||
Sentry-Release:
|
||||
name: Create Sentry Release
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -16,10 +16,18 @@ Sentry.init({
|
||||
useLocation,
|
||||
useMatches,
|
||||
}),
|
||||
Sentry.replayIntegration(),
|
||||
Sentry.replayIntegration({
|
||||
blockAllMedia: false,
|
||||
maskAllInputs: false,
|
||||
maskAllText: false,
|
||||
}),
|
||||
],
|
||||
replaysOnErrorSampleRate: 1,
|
||||
replaysSessionSampleRate: 0.02,
|
||||
release:
|
||||
document
|
||||
.querySelector("meta[name='commit_sha']")
|
||||
?.getAttribute("content") ?? undefined,
|
||||
sendDefaultPii: true,
|
||||
tracesSampleRate: 0.1,
|
||||
tunnel: "/api/st",
|
||||
|
||||
@@ -130,6 +130,7 @@ export async function loader({
|
||||
}): Promise<{ [k: string]: any }> {
|
||||
let data: { [k: string]: string } = {};
|
||||
|
||||
if (context.env.COMMIT_SHA) data.commit_sha = context.env.COMMIT_SHA;
|
||||
if (context.data.current_user) data = { ...context.data.current_user };
|
||||
if (context.env.REMIX_DSN) data.dsn = context.env.REMIX_DSN;
|
||||
if (context.data.nonce) data.nonce = context.data.nonce;
|
||||
@@ -202,6 +203,9 @@ function DocumentWrapper(props: {
|
||||
/>
|
||||
))}
|
||||
<meta charSet="UTF-8" />
|
||||
{loaderData.commit_sha ? (
|
||||
<meta name="commit_sha" content={loaderData.commit_sha} />
|
||||
) : null}
|
||||
{loaderData.dsn ? (
|
||||
<meta name="dsn" content={loaderData.dsn} />
|
||||
) : null}
|
||||
|
||||
@@ -35,29 +35,24 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
month = 12;
|
||||
}
|
||||
|
||||
const eventMemberQuery = await context.env.D1.prepare(
|
||||
"SELECT id, name, roblox_id FROM et_members;",
|
||||
).all();
|
||||
const inactivityQuery: D1Result<Record<string, any>> =
|
||||
await context.env.D1.prepare(
|
||||
"SELECT decisions, json_extract(user, '$.id') AS uid FROM inactivity_notices WHERE (end BETWEEN DATE('now', 'start of month', '-1 month') AND DATE('now', 'start of month', '-1 day')) OR (start BETWEEN DATE('now', 'start of month', '-1 month') AND DATE('now', 'start of month', '-1 day'));",
|
||||
).all();
|
||||
const batchStatements: D1Result<Record<string, any>>[] =
|
||||
await context.env.D1.batch([
|
||||
context.env.D1.prepare("SELECT id, name, roblox_id FROM et_members;"),
|
||||
context.env.D1.prepare(
|
||||
"SELECT decisions, json_extract(user, '$.id') AS uid FROM inactivity_notices WHERE (end BETWEEN DATE('now', 'start of month', '-1 month') AND DATE('now', 'start of month', '-1 day')) OR (start BETWEEN DATE('now', 'start of month', '-1 month') AND DATE('now', 'start of month', '-1 day'));",
|
||||
),
|
||||
context.env.D1.prepare(
|
||||
"SELECT approved, answered_at, created_by, performed_at, reached_minimum_player_count, type FROM events WHERE month = ? AND year = ?;",
|
||||
).bind(month, year),
|
||||
]);
|
||||
|
||||
const eventsQuery = await context.env.D1.prepare(
|
||||
"SELECT approved, answered_at, created_by, performed_at, reached_minimum_player_count, type FROM events WHERE month = ? AND year = ?;",
|
||||
)
|
||||
.bind(month, year)
|
||||
.all();
|
||||
const memberMap = Object.fromEntries(
|
||||
eventMemberQuery.results.map((entry) => {
|
||||
return [
|
||||
entry.id,
|
||||
{ name: entry.name, points: 0, roblox_id: entry.roblox_id },
|
||||
];
|
||||
batchStatements[0].results.map((e) => {
|
||||
return [e.id, { name: e.name, points: 0, roblox_id: e.roblox_id }];
|
||||
}),
|
||||
);
|
||||
|
||||
for (const event of eventsQuery.results as {
|
||||
for (const event of batchStatements[2].results as {
|
||||
approved: number;
|
||||
answered_at: number;
|
||||
created_by: string;
|
||||
@@ -77,10 +72,10 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
for (const member of Object.keys(memberMap))
|
||||
if (
|
||||
(memberMap[member].points < 50 ||
|
||||
eventsQuery.results.filter(
|
||||
batchStatements[2].results.filter(
|
||||
(e) => e.type === "gamenight" && e.created_by === member,
|
||||
).length === 0) &&
|
||||
!inactivityQuery.results.find(
|
||||
!batchStatements[1].results.find(
|
||||
(i) => i.uid === member && JSON.parse(i.decisions).et,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -33,37 +33,31 @@ export async function loader({ context }: { context: RequestContext }) {
|
||||
|
||||
if (!currentUser) throw new Response(null, { status: 401 });
|
||||
|
||||
const d1Promises = [];
|
||||
const batchStatements = [];
|
||||
|
||||
for (const itemType of ["appeals", "inactivity_notices", "reports"])
|
||||
d1Promises.push(
|
||||
for (const itemType of ["appeals", "inactivity_notices", "reports"]) {
|
||||
batchStatements.push(
|
||||
context.env.D1.prepare(
|
||||
`SELECT *
|
||||
FROM ${itemType}
|
||||
WHERE json_extract(user, '$.id') = ?
|
||||
ORDER BY created_at DESC;`,
|
||||
)
|
||||
.bind(currentUser.id)
|
||||
.all(),
|
||||
`SELECT * FROM ${itemType} WHERE json_extract(user, '$.id') = ? ORDER BY created_at DESC;`,
|
||||
).bind(currentUser.id),
|
||||
);
|
||||
|
||||
const settledPromises = await Promise.allSettled(d1Promises);
|
||||
let etData: { [k: string]: any } | null = null;
|
||||
|
||||
if (currentUser.permissions & (1 << 3)) {
|
||||
etData = await context.env.D1.prepare(
|
||||
"SELECT name, points, roblox_id FROM et_members WHERE id = ?;",
|
||||
)
|
||||
.bind(currentUser.id)
|
||||
.first();
|
||||
}
|
||||
|
||||
return {
|
||||
etData,
|
||||
items: settledPromises.map((p) => {
|
||||
if (p.status === "fulfilled") return p.value.results;
|
||||
if (currentUser.permissions & (1 << 3))
|
||||
batchStatements.push(
|
||||
context.env.D1.prepare(
|
||||
"SELECT name, points, roblox_id FROM et_members WHERE id = ? LIMIT 1;",
|
||||
).bind(currentUser.id),
|
||||
);
|
||||
|
||||
return null;
|
||||
const batchResults = await context.env.D1.batch(batchStatements);
|
||||
|
||||
return {
|
||||
etData: batchResults.at(3)?.results?.at(0) as { [k: string]: any } | null,
|
||||
items: batchResults.map((r) => {
|
||||
if (r.success) return r.results;
|
||||
|
||||
return [];
|
||||
}) as any as ({ [k: string]: any }[] | null)[],
|
||||
permissions: currentUser.permissions as number,
|
||||
};
|
||||
|
||||
@@ -383,6 +383,7 @@ async function setTheme(context: RequestContext) {
|
||||
export const onRequest = [
|
||||
Sentry.sentryPagesPlugin((context: RequestContext) => ({
|
||||
dsn: context.env.FUNCTIONS_DSN,
|
||||
release: context.env.COMMIT_SHA,
|
||||
sendDefaultPii: true,
|
||||
})),
|
||||
setAuth,
|
||||
|
||||
@@ -194,8 +194,7 @@ export async function onRequestPost(context: RequestContext) {
|
||||
|
||||
const reportId = `${Date.now()}${context.request.headers
|
||||
.get("cf-ray")
|
||||
?.split("-")
|
||||
?.at(0)}${crypto.randomUUID().replaceAll("-", "")}`;
|
||||
?.replace("-", "")}${crypto.randomUUID().replaceAll("-", "")}`;
|
||||
|
||||
const { current_user: currentUser } = context.data;
|
||||
if (filesToProcess.length)
|
||||
|
||||
@@ -12,18 +12,24 @@ export async function onRequestPost(context: RequestContext) {
|
||||
|
||||
const sentryUrl = new URL(dsn);
|
||||
|
||||
await fetch(`https://${sentryUrl.host}/api${sentryUrl.pathname}/envelope`, {
|
||||
body: clonedRequest.body,
|
||||
headers: {
|
||||
"content-type": "application/x-sentry-envelope",
|
||||
"x-forwarded-for": context.request.headers.get(
|
||||
"cf-connecting-ip",
|
||||
) as string,
|
||||
const resp = await fetch(
|
||||
`https://${sentryUrl.host}/api${sentryUrl.pathname}/envelope/`,
|
||||
{
|
||||
body: clonedRequest.body,
|
||||
headers: {
|
||||
"content-type": "application/x-sentry-envelope",
|
||||
"x-forwarded-for": context.request.headers.get(
|
||||
"cf-connecting-ip",
|
||||
) as string,
|
||||
},
|
||||
method: "POST",
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
);
|
||||
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
return new Response(await resp.text(), {
|
||||
headers: {
|
||||
"content-type": resp.headers.get("content-type") || "text/plain",
|
||||
},
|
||||
status: resp.status,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user