Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
# Ignore credentials
private_credentials.json
.env
.vercel
21 changes: 21 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

Getting the Vercel server function in api/uploadqrdata.ts to run proved
difficult because of the different resolution strategies used by vite
(the loader for the front-end) and by vercel's loader.

During development, run

```
npm run dev
```

in one terminal, this will serve the frontend at `localhost:5173`.

In another terminal, run
```
vercel dev --listen 3000
```
which will run the vercel function backend on port 3000.
`vite.config.ts` contains the necessary proxy setup to forward
`localhost:5173/api` to `localhost:3000/api`.

15 changes: 15 additions & 0 deletions api/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

// Database tables
export const matchScoutTable = "MatchData";
export const pitScoutTable = "PitData";
export const eventInfoTable = "Event";
export const teamInfoTable = "Team";
export const robotPhotoTable = "RobotPhoto";

// Storage buckets
export const robotPhotoBucket = "robot-photos";

// Event information.
export const defaultEventId = "2025vagle2";
// Flag to force override to the default event. Useful if you are playing two tournaments on the same day.
export const useDefaultEvent = true;
5 changes: 5 additions & 0 deletions api/supabase-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

import { createClient } from '@supabase/supabase-js'

export const projectId = "oltmplswnrxlhmordqki"
export const supabase = createClient("https://" + projectId + ".supabase.co", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9sdG1wbHN3bnJ4bGhtb3JkcWtpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTk5NDg1ODAsImV4cCI6MjA3NTUyNDU4MH0.K78JxtZvx2QUS2B8YimMjYzA5f5olHag-3QVoM6-Or0");
13 changes: 13 additions & 0 deletions api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"allowImportingTsExtensions": true,
"noEmit": true,
"strict": true,
"esModuleInterop": true
},
"include": ["./**/*.ts", "../src/**/*.ts"]
}

53 changes: 53 additions & 0 deletions api/uploadqrdata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { VercelRequest, VercelResponse } from '@vercel/node';
import { matchScoutTable } from "./constants";
import { supabase } from './supabase-client';

// invocation is /api/uploadqrdata?data=....
export default async function handler(req: VercelRequest, res: VercelResponse) {
const { data } = req.query;

if (!data || typeof data !== 'string') {
res.status(400).send('Missing or invalid data parameter');
return;
}

try {
const submitData = JSON.parse(decodeURIComponent(data));

console.log("Submitting");
console.log(submitData);
const { error } = await supabase.from(matchScoutTable).insert(submitData);

if (error) {
res.status(200).send(`
<html>
<head>
<title>Data Processing Error</title>
</head>
<body>
<h1>An error occurred submitting the data to the database.</h1>
<pre>{error}</pre>
</body>
</html>
`);
} else {
const sd = submitData;
res.status(200).send(`
<html>
<head>
<title>Data Processed</title>
</head>
<body>
<h1>Data successfully processed.</h1>
<p>Scout name: ${sd['prematch.scout_name']}</p>
<p>Scout team: ${sd['prematch.scout_team']}</p>
<p>Match number : ${sd['prematch.match_number']}</p>
</body>
</html>
`);
}
} catch (error) {
console.error('Error processing data:', error);
res.status(500).send('Error processing data');
}
}
Loading