Skip to content

Commit 15751a0

Browse files
committed
lots of stuff, fixing/investigating weird production bugs
1 parent 7b11dfe commit 15751a0

6 files changed

Lines changed: 122 additions & 38 deletions

File tree

.github/workflows/buildanddeploy.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,20 @@ jobs:
9999
needs: build-and-deploy-gh-pages
100100
runs-on: ubuntu-latest
101101
steps:
102-
- uses: actions/checkout@v4
103-
with:
104-
ref: gh-pages
105-
- uses: FirebaseExtended/action-hosting-deploy@v0
102+
- name: Checkout
103+
uses: actions/checkout@v4
104+
105+
- name: Setup Bun
106+
uses: oven-sh/setup-bun@v1
107+
108+
- name: Install dependencies
109+
run: bun install
110+
111+
- name: Build static site
112+
run: bunx vite build
113+
114+
- name: Deploy to Firebase
115+
uses: FirebaseExtended/action-hosting-deploy@v0
106116
with:
107117
repoToken: ${{ secrets.GITHUB_TOKEN }}
108118
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_CCPORTED }}

firebase.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"hosting": {
3+
"public": "build",
4+
"ignore": [
5+
"firebase.json",
6+
"**/.*",
7+
"**/node_modules/**"
8+
],
9+
"rewrites": [
10+
{
11+
"source": "**",
12+
"destination": "/index.html"
13+
}
14+
]
15+
}
16+
}

src/lib/helpers.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReturnValue, UpdateItemCommand } from "@aws-sdk/client-dynamodb";
22
import type { Game } from "./types/game.js";
3-
import { SessionState } from "./state.js";
3+
import { SessionState, State } from "./state.js";
44

55
export function decamelize(string: string): string {
66
// HelloWorld -> Hello World
@@ -28,6 +28,7 @@ export async function openGame(game: Game) {
2828

2929
export async function trackClick(gameID: string): Promise<void> {
3030
try {
31+
State.localPlays += 1;
3132
const params = {
3233
TableName: 'games_list',
3334
Key: {
@@ -73,4 +74,22 @@ export async function detectAdBlockEnabled() {
7374
isAdBlockEnabled = true;
7475
}
7576
return isAdBlockEnabled;
77+
}
78+
79+
export function getTimeBetween(date1: Date, date2: Date): string {
80+
const t1 = date1.getTime();
81+
const t2 = date2.getTime();
82+
const diff = Math.abs(t2 - t1);
83+
84+
const seconds = Math.floor(diff / 1000);
85+
const minutes = Math.floor(seconds / 60);
86+
const hours = Math.floor(minutes / 60);
87+
const days = Math.floor(hours / 24);
88+
89+
// Subtract days/hours/minutes to get remainder for each unit
90+
const remHours = hours % 24;
91+
const remMinutes = minutes % 60;
92+
const remSeconds = seconds % 60;
93+
94+
return `${days}d ${remHours}h ${remMinutes}m ${remSeconds}s`;
7695
}

src/lib/loadCards.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ export async function loadGames(): Promise<Game[]> {
3838
});
3939
}
4040
}
41-
console.log(games.reduce((a, v) => a + v.clicks, 0).toLocaleString() + " total plays");
41+
SessionState.plays = games.reduce((a, v) => a + v.clicks, 0);
4242
return games;
4343
}

src/lib/state.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Servers, type Server, AHosts, findServers } from "./types/servers.js";
22
import { CognitoIdentityClient } from "@aws-sdk/client-cognito-identity";
3-
import { fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity";
3+
import { fromCognitoIdentityPool, type CognitoIdentityCredentials } from "@aws-sdk/credential-provider-cognito-identity";
44
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
55
import type { Game } from "./types/game.js";
66
import { browser } from '$app/environment';
@@ -11,9 +11,11 @@ export const SessionState = {
1111
awsReady: false,
1212
ssr: !browser,
1313
adBlockEnabled: false,
14+
credentials: null as CognitoIdentityCredentials | null,
1415
dynamoDBClient: null as DynamoDBClient | null,
1516
s3Client: null as S3Client | null,
1617
devMode: (browser && window.location.hostname === "localhost"),
18+
plays: 0
1719
}
1820

1921

@@ -27,6 +29,7 @@ type StateType = {
2729
pinnedGames: string[];
2830
games: Game[];
2931
isAHost: () => boolean;
32+
localPlays: number;
3033
};
3134

3235
function saveState() {
@@ -57,7 +60,8 @@ export const State = createState({
5760
homeView: "grid",
5861
pinnedGames: [],
5962
games: [],
60-
isAHost: () => (AHosts.some((h): boolean => h.hostname === State.currentServer.hostname))
63+
isAHost: () => (AHosts.some((h): boolean => h.hostname === State.currentServer.hostname)),
64+
localPlays: 0
6165
});
6266

6367

@@ -81,6 +85,7 @@ export async function initializeTooling() {
8185
region: "us-west-2",
8286
credentials
8387
});
88+
SessionState.credentials = await credentials();
8489
SessionState.awsReady = true;
8590
SessionState.dynamoDBClient = dynamoDBClient;
8691
SessionState.s3Client = s3Client;
@@ -123,6 +128,5 @@ async function initializeUnathenticated() {
123128
});
124129

125130
SessionState.awsReady = true;
126-
127131
return credentials;
128132
}

src/routes/+page.svelte

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import { initializeTooling, SessionState, State } from "$lib/state.js";
66
import { onMount } from "svelte";
77
import type { PageData } from "./$types.js";
8+
import { getTimeBetween } from "$lib/helpers.js";
9+
import { browser } from "$app/environment";
810
911
const { data }: { data: PageData } = $props();
1012
@@ -25,43 +27,67 @@
2527
/>
2628
</svelte:head>
2729

28-
{#if (isAHost)}
30+
{#if isAHost || SessionState.devMode}
2931
<div class="container">
3032
<div class="background"></div>
3133
<Navigation />
3234
<CardGrid {games} />
33-
<footer>
34-
<h3>
35-
<b
36-
>Can't find what you're looking for? <a
37-
href="https://discord.gg/GDEFRBTT3Z">Join the discord</a
38-
></b
39-
>
40-
</h3>
41-
<p>
42-
CCPorted is not affiliated with or endorsed by any game
43-
developers or publishers. All games are property of their
44-
respective owners.
45-
</p>
46-
<p>
47-
DMCA Requests can be sent to <a
48-
href="mailto:ccported@ccported.click"
49-
>ccported@ccported.click</a
50-
>
51-
</p>
52-
<p>
53-
Site, design, and development are protected under common law
54-
copyright; © {new Date().getFullYear()} CCPorted
55-
</p>
56-
<p>
57-
<a href="/tos/privacy_policy">Privacy Policy</a> |
58-
<a href="/tos/terms_of_service">Terms of Service</a>
59-
</p>
60-
</footer>
6135
</div>
6236
{:else}
6337
<Locked />
6438
{/if}
39+
<footer>
40+
<h3>
41+
<b
42+
>Can't find what you're looking for? <a
43+
href="https://discord.gg/GDEFRBTT3Z">Join the discord</a
44+
></b
45+
>
46+
</h3>
47+
<p>
48+
CCPorted is not affiliated with or endorsed by any game developers or
49+
publishers. All games are property of their respective owners.
50+
</p>
51+
<p>
52+
DMCA Requests can be sent to <a href="mailto:ccported@ccported.click"
53+
>ccported@ccported.click</a
54+
>
55+
</p>
56+
<p>
57+
Site, design, and development are protected under common law copyright;
58+
© {new Date().getFullYear()} CCPorted
59+
</p>
60+
<p>
61+
<a href="/tos/privacy_policy">Privacy Policy</a> |
62+
<a href="/tos/terms_of_service">Terms of Service</a>
63+
</p>
64+
<div class="information">
65+
<!-- none of this information is statefull, therefore none of it will update. this is intended behavior -->
66+
<b>Running Information:</b><br />
67+
Browser: {navigator.userAgent}<br />
68+
Host: {browser && window.location.hostname}<br />
69+
DevMode: {SessionState.devMode}<br />
70+
AdBlock: {SessionState.adBlockEnabled}<br />
71+
Current Server: {State.currentServer.name} (Loaded {State.servers
72+
.length})<br />
73+
AHost: {State.isAHost()} (Loaded {State.aHosts.length})<br />
74+
Games Loaded: {games.length} ({State.pinnedGames.length} pinned) - rendered
75+
{State.homeView}<br />
76+
Version: {State.version}<br />
77+
Logged In: {State.loggedIn}<br />
78+
SSR: {SessionState.ssr}<br />
79+
AWS Ready: {SessionState.awsReady}<br />
80+
AWS Acting: {SessionState.credentials?.identityId} | {SessionState
81+
.credentials?.accessKeyId}<br />
82+
Credentials Expires: {SessionState.credentials?.expiration?.toLocaleTimeString()}
83+
{getTimeBetween(
84+
SessionState.credentials?.expiration || new Date(),
85+
new Date(),
86+
)} <br />
87+
Plays: {SessionState.plays.toLocaleString()} ({State.localPlays.toLocaleString()}
88+
local)<br />
89+
</div>
90+
</footer>
6591

6692
<style>
6793
footer {
@@ -70,4 +96,13 @@
7096
margin: 20px 0;
7197
font-size: 14px;
7298
}
99+
.information {
100+
margin-top: 10px;
101+
font-size: 12px;
102+
color: #999;
103+
max-width: 600px;
104+
margin: auto;
105+
text-align: left;
106+
font-family: "Courier New", Courier, monospace;
107+
}
73108
</style>

0 commit comments

Comments
 (0)