mirror of
https://github.com/System-End/site.git
synced 2026-04-19 22:05:11 +00:00
Merge branch 'main' into main
This commit is contained in:
commit
92a3b7b655
4 changed files with 149 additions and 1 deletions
|
|
@ -37,6 +37,7 @@
|
|||
"animated-value": "^0.2.4",
|
||||
"animejs": "^3.2.2",
|
||||
"axios": "^1.6.7",
|
||||
"camelcase": "^8.0.0",
|
||||
"cookies-next": "^4.0.0",
|
||||
"country-list": "^2.3.0",
|
||||
"country-list-js": "^3.1.8",
|
||||
|
|
|
|||
104
pages/api/bin/wokwi/new.js
Normal file
104
pages/api/bin/wokwi/new.js
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
import AirtablePlus from "airtable-plus"
|
||||
|
||||
const createProject = async (partsList=[]) => {
|
||||
const airtable = new AirtablePlus({
|
||||
apiKey: process.env.AIRTABLE_API_KEY,
|
||||
baseID: 'appKjALSnOoA0EmPk',
|
||||
tableName: 'Supported Parts'
|
||||
})
|
||||
|
||||
const parts = [
|
||||
{ "type": "board-pi-pico-w", "id": "pico", "top": 0, "left": 0, "attrs": {} }
|
||||
]
|
||||
|
||||
await Promise.all(partsList.map(async (part) => {
|
||||
const airPart = await airtable.read({
|
||||
filterByFormula: `{Wokwi Name}= "${part}"`,
|
||||
maxRecords: 1
|
||||
})
|
||||
return airPart[0].fields['Wokwi Name'].split(',').forEach((name, i) => {
|
||||
parts.push({
|
||||
type: name,
|
||||
id: name + '-' + i,
|
||||
left: i * 100, // this is roughtly the width of most parts
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
||||
const body = JSON.stringify({
|
||||
name: "The Bin!",
|
||||
unlisted: false,
|
||||
files: [{
|
||||
name: "help.md",
|
||||
content: `# Welcome to The Bin! 🦝
|
||||
|
||||
Now that you've thrown some parts into The Bin, it's time to turn that trash into treasure! 🗑️➡️💎
|
||||
|
||||
Wire up your parts and write some code to make them work together.
|
||||
|
||||
If you'd like a tutorial, check out some sample projects:
|
||||
https://jams.hackclub.com/tags/the-bin
|
||||
|
||||
You can get help by chatting with other high schoolers on the Hack Club Slack in the #electronics channel:
|
||||
👉 https://hackclub.com/slack 👈
|
||||
|
||||
Once you're ready build your design IRL, click the "Share" button and submit your design:
|
||||
https://hackclub.com/bin/submit
|
||||
`
|
||||
},
|
||||
{
|
||||
name: "sketch.ino",
|
||||
content: `// Now turn this trash into treasure!
|
||||
// Want some help? You can chat with us on the Hack Club Slack in the #electronics channel
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial1.begin(115200);
|
||||
Serial1.println("Hello, Raspberry Pi Pico W!");
|
||||
}
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
delay(1); // this speeds up the simulation
|
||||
}`
|
||||
}, {
|
||||
name: "diagram.json",
|
||||
content: JSON.stringify({
|
||||
"version": 1,
|
||||
"author": "The Bin - Hack Club",
|
||||
"editor": "wokwi",
|
||||
"parts": parts,
|
||||
"connections": [["pico:GP0", "$serialMonitor:RX", "", []], ["pico:GP1", "$serialMonitor:TX", "", []]], "dependencies": {}
|
||||
}, null, 2)
|
||||
}],
|
||||
})
|
||||
|
||||
const response = await fetch('https://wokwi.com/api/projects/save', {
|
||||
method: 'POST',
|
||||
cors: 'no-cors',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Referer': 'https://wokwi.com/projects/new/pi-pico-w',
|
||||
'User-Agent': 'Hack Club - contact max@hackclub.com for any complaints!'
|
||||
},
|
||||
body
|
||||
}).catch((e) => {
|
||||
console.log(e)
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
const { projectId } = data
|
||||
|
||||
return `https://wokwi.com/projects/${projectId}`
|
||||
}
|
||||
|
||||
export default async function handler(req, res) {
|
||||
if (req.method === 'POST') {
|
||||
const { parts } = req.body
|
||||
|
||||
const shareLink = await createProject(parts)
|
||||
if (shareLink) {
|
||||
res.status(200).json({ shareLink })
|
||||
} else {
|
||||
res.status(500).json({ error: 'Failed to create project' })
|
||||
}
|
||||
}
|
||||
}
|
||||
29
pages/api/bin/wokwi/parts.js
Normal file
29
pages/api/bin/wokwi/parts.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import AirtablePlus from "airtable-plus"
|
||||
import camelcase from "camelcase"
|
||||
|
||||
const camelizeObject = (obj) => {
|
||||
Object.keys(obj).forEach(key => {
|
||||
obj[camelcase(key)] = obj[key]
|
||||
if (key !== camelcase(key)) {
|
||||
delete obj[key]
|
||||
}
|
||||
})
|
||||
return obj
|
||||
}
|
||||
|
||||
const wokwiParts = async () => {
|
||||
const airtable = new AirtablePlus({
|
||||
apiKey: process.env.AIRTABLE_API_KEY,
|
||||
baseID: 'appKjALSnOoA0EmPk',
|
||||
tableName: 'Supported Parts'
|
||||
})
|
||||
|
||||
const records = await airtable.read()
|
||||
const parts = records.map(record => camelizeObject(record.fields))
|
||||
return parts
|
||||
}
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const data = await wokwiParts()
|
||||
res.status(200).json(data)
|
||||
}
|
||||
16
yarn.lock
16
yarn.lock
|
|
@ -3216,6 +3216,11 @@ camelcase@^5.3.1:
|
|||
resolved "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz"
|
||||
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
|
||||
|
||||
camelcase@^8.0.0:
|
||||
version "8.0.0"
|
||||
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-8.0.0.tgz#c0d36d418753fb6ad9c5e0437579745c1c14a534"
|
||||
integrity sha512-8WB3Jcas3swSvjIeA2yvCJ+Miyz5l1ZmB6HFb9R1317dt9LCQoswg/BGrmAmkWVEszSrrg4RwmO46qIm2OEnSA==
|
||||
|
||||
camelize@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/camelize/-/camelize-1.0.1.tgz#89b7e16884056331a35d6b5ad064332c91daa6c3"
|
||||
|
|
@ -8239,7 +8244,16 @@ string-hash@1.1.3:
|
|||
resolved "https://registry.yarnpkg.com/string-hash/-/string-hash-1.1.3.tgz#e8aafc0ac1855b4666929ed7dd1275df5d6c811b"
|
||||
integrity sha512-kJUvRUFK49aub+a7T1nNE66EJbZBMnBgoC1UbCZ5n6bsZKBRga4KgBRTMn/pFkeCZSYtNeSyMxPDM0AXWELk2A==
|
||||
|
||||
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
|
||||
"string-width-cjs@npm:string-width@^4.2.0":
|
||||
version "4.2.3"
|
||||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
|
||||
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
|
||||
dependencies:
|
||||
emoji-regex "^8.0.0"
|
||||
is-fullwidth-code-point "^3.0.0"
|
||||
strip-ansi "^6.0.1"
|
||||
|
||||
string-width@^4.1.0:
|
||||
version "4.2.3"
|
||||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
|
||||
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue