mirror of
https://github.com/System-End/site.git
synced 2026-04-19 18:35:12 +00:00
big ol' mess of ZIP
This commit is contained in:
parent
597f889119
commit
20ee1c8be7
5 changed files with 156 additions and 4 deletions
|
|
@ -25,6 +25,12 @@
|
||||||
"@octokit/auth-app": "^6.0.1",
|
"@octokit/auth-app": "^6.0.1",
|
||||||
"@octokit/core": "^5.1.0",
|
"@octokit/core": "^5.1.0",
|
||||||
"@octokit/rest": "^20.0.2",
|
"@octokit/rest": "^20.0.2",
|
||||||
|
"@tracespace/core": "^5.0.0-alpha.0",
|
||||||
|
"@tracespace/identify-layers": "^5.0.0-alpha.0",
|
||||||
|
"@tracespace/parser": "^5.0.0-next.0",
|
||||||
|
"@tracespace/plotter": "^5.0.0-alpha.0",
|
||||||
|
"@tracespace/renderer": "^5.0.0-alpha.0",
|
||||||
|
"@tracespace/xml-id": "^4.2.7",
|
||||||
"add": "^2.0.6",
|
"add": "^2.0.6",
|
||||||
"airtable-plus": "^1.0.4",
|
"airtable-plus": "^1.0.4",
|
||||||
"animated-value": "^0.2.4",
|
"animated-value": "^0.2.4",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import {GenerateSVG} from "./svg/[file]";
|
||||||
|
|
||||||
export const FetchProject = async (name) => {
|
export const FetchProject = async (name) => {
|
||||||
const readme = await fetch(`https://raw.githubusercontent.com/hackclub/OnBoard/main/projects/${name}/README.md`)
|
const readme = await fetch(`https://raw.githubusercontent.com/hackclub/OnBoard/main/projects/${name}/README.md`)
|
||||||
const text = await readme.text()
|
const text = await readme.text()
|
||||||
|
|
@ -18,10 +20,11 @@ export const FetchProject = async (name) => {
|
||||||
frontmatter[key] = value
|
frontmatter[key] = value
|
||||||
}
|
}
|
||||||
// check for a "thumbnail.png" file in the project directory
|
// check for a "thumbnail.png" file in the project directory
|
||||||
console.log(`https://github.com/snoglobe/OnBoard/raw/main/projects/${name}/thumbnail.png`)
|
//console.log(`https://github.com/snoglobe/OnBoard/raw/main/projects/${name}/thumbnail.png`)
|
||||||
/*const thumbnail = await fetch(`https://github.com/snoglobe/OnBoard/raw/main/projects/${name}/thumbnail.png`, {mode: 'no-cors'})
|
/*const thumbnail = await fetch(`https://github.com/snoglobe/OnBoard/raw/main/projects/${name}/thumbnail.png`, {mode: 'no-cors'})*/
|
||||||
console.log(thumbnail)*/
|
/*console.log(thumbnail)*/
|
||||||
const image = /*thumbnail.ok ?*/ `https://github.com/snoglobe/OnBoard/raw/main/projects/${name}/thumbnail.png` /*: await get_fallback_image(`https://github.com/hackclub/OnBoard/raw/main/projects/${project.name}`)*/
|
const image = /*thumbnail.ok ? `https://github.com/snoglobe/OnBoard/raw/main/projects/${name}/thumbnail.png`
|
||||||
|
:*/ `data:image/svg+xml;utf8,${GenerateSVG(`https://github.com/snoglobe/OnBoard/raw/main/projects/${name}/gerber.zip`).top}`
|
||||||
console.log("done")
|
console.log("done")
|
||||||
return({
|
return({
|
||||||
project_name: name ?? null,
|
project_name: name ?? null,
|
||||||
|
|
|
||||||
63
pages/api/board/svg/[file].js
Normal file
63
pages/api/board/svg/[file].js
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
import JSZip from "jszip";
|
||||||
|
import {read, plot, renderLayers, renderBoard, stringifySvg} from '@tracespace/core'
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
export const GenerateSVG = async (zipFile) => {
|
||||||
|
const zip = new JSZip();
|
||||||
|
const data = await fetch(zipFile)
|
||||||
|
.then((res) => res.arrayBuffer());
|
||||||
|
let files = [];
|
||||||
|
await zip.loadAsync(data).then(function (zip) {
|
||||||
|
Object.keys(zip.files).forEach(function (filename) {
|
||||||
|
zip.files[filename].async('uint8array').then(function (fileData) {
|
||||||
|
filename = filename.replace(/\//g, '_');
|
||||||
|
const extension = filename.split('.').pop().toLowerCase();
|
||||||
|
if (extension === 'gbr' || // gerber
|
||||||
|
extension === 'drl' || // drillfile
|
||||||
|
extension === 'gko' || // gerber board outline
|
||||||
|
extension === 'gbl' || // gerber bottom layer
|
||||||
|
extension === 'gbp' || // gerber bottom paste
|
||||||
|
extension === 'gbs' || // gerber bottom solder mask
|
||||||
|
extension === 'gbo' || // gerber bottom silk
|
||||||
|
extension === 'gtl' || // gerber top layer
|
||||||
|
extension === 'gto' || // gerber top silk
|
||||||
|
extension === 'gts' // gerber top soldermask
|
||||||
|
) {
|
||||||
|
console.log(filename)
|
||||||
|
files.push(filename);
|
||||||
|
fs.writeFileSync(filename, fileData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// wait for files to be written
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, 100); // very hacky but works!!!!
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(files)
|
||||||
|
|
||||||
|
const readResult = await read(files)
|
||||||
|
const plotResult = plot(readResult)
|
||||||
|
const renderLayersResult = renderLayers(plotResult)
|
||||||
|
const renderBoardResult = renderBoard(renderLayersResult)
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
fs.unlinkSync(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
top: stringifySvg(renderBoardResult.top),
|
||||||
|
bottom: stringifySvg(renderBoardResult.bottom),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function handler(req, res) {
|
||||||
|
const { file } = req.query
|
||||||
|
if (!file) {
|
||||||
|
return res.status(400).json({ status: 400, error: 'Must provide file' })
|
||||||
|
}
|
||||||
|
const svg = await GenerateSVG(file)
|
||||||
|
return res.status(200).json(svg)
|
||||||
|
}
|
||||||
|
|
@ -245,6 +245,8 @@ export async function getStaticProps() {
|
||||||
const projectData = data.map(async project => {
|
const projectData = data.map(async project => {
|
||||||
/*const url = getUrl({req: context.req})
|
/*const url = getUrl({req: context.req})
|
||||||
console.log(url)*/
|
console.log(url)*/
|
||||||
|
// 100ms delay to avoid rate limiting
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 100))
|
||||||
return FetchProject(project.name)
|
return FetchProject(project.name)
|
||||||
})
|
})
|
||||||
let projects = await Promise.all(projectData)
|
let projects = await Promise.all(projectData)
|
||||||
|
|
|
||||||
78
yarn.lock
78
yarn.lock
|
|
@ -2239,6 +2239,62 @@
|
||||||
"@theme-ui/css" "0.14.7"
|
"@theme-ui/css" "0.14.7"
|
||||||
"@theme-ui/mdx" "0.14.7"
|
"@theme-ui/mdx" "0.14.7"
|
||||||
|
|
||||||
|
"@tracespace/core@^5.0.0-alpha.0":
|
||||||
|
version "5.0.0-alpha.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@tracespace/core/-/core-5.0.0-alpha.0.tgz#e889229e07ee589658eaece51f2f4af5708fe658"
|
||||||
|
integrity sha512-OG2IPCT8nDoB0brIGhXaMpT0xqyvj0oKhnrjIA3fhFeiLZueSmn47xB0lqHXt/ZQze0NQZO6NtXCqAy2J7UQPA==
|
||||||
|
dependencies:
|
||||||
|
"@tracespace/identify-layers" "5.0.0-alpha.0"
|
||||||
|
"@tracespace/parser" "5.0.0-alpha.0"
|
||||||
|
"@tracespace/plotter" "5.0.0-alpha.0"
|
||||||
|
"@tracespace/renderer" "5.0.0-alpha.0"
|
||||||
|
"@tracespace/xml-id" "5.0.0-alpha.0"
|
||||||
|
|
||||||
|
"@tracespace/identify-layers@5.0.0-alpha.0", "@tracespace/identify-layers@^5.0.0-alpha.0":
|
||||||
|
version "5.0.0-alpha.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@tracespace/identify-layers/-/identify-layers-5.0.0-alpha.0.tgz#a7822a423b2783b5416aa33a5fdde6a47181825e"
|
||||||
|
integrity sha512-4cu0fB+QwVSQ+CvDzFaF7E4ixOacxinuluxY8hxE1Whzm87MwmYsUVFPaY32xARcY++meTdjbWG9Kd+DyOOA6Q==
|
||||||
|
|
||||||
|
"@tracespace/parser@5.0.0-alpha.0":
|
||||||
|
version "5.0.0-alpha.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@tracespace/parser/-/parser-5.0.0-alpha.0.tgz#839a072db1ba8de779acdd4f58556cf7b164f319"
|
||||||
|
integrity sha512-Y+WDUXDXugUEpGn3x6tT80aUTk0vu5W052JVuJfouSXxs70uX6zKF1rsfA6aP8YiFGtQUHCgecrvuO0sec3pDg==
|
||||||
|
dependencies:
|
||||||
|
"@types/moo" "^0.5.5"
|
||||||
|
"@types/unist" "^2.0.6"
|
||||||
|
|
||||||
|
"@tracespace/parser@^5.0.0-next.0":
|
||||||
|
version "5.0.0-next.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@tracespace/parser/-/parser-5.0.0-next.0.tgz#1bbcc4dc8fccb73df2c2e9dddaa78578a9031d0a"
|
||||||
|
integrity sha512-4auyyBTLGRbHXHClr5Gqbv/UNXR8KwMa59XTUtQojPIvX3SVapRQYfbJb1bNqMtpOoeLDVZjFF6h0WgL0ZFrjQ==
|
||||||
|
dependencies:
|
||||||
|
"@types/moo" "^0.5.0"
|
||||||
|
"@types/unist" "^2.0.3"
|
||||||
|
moo "^0.5.1"
|
||||||
|
|
||||||
|
"@tracespace/plotter@5.0.0-alpha.0", "@tracespace/plotter@^5.0.0-alpha.0":
|
||||||
|
version "5.0.0-alpha.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@tracespace/plotter/-/plotter-5.0.0-alpha.0.tgz#c987154ad7d2dd7475c7e7a2ca43c5e0dd148f07"
|
||||||
|
integrity sha512-vYTOclcTXhNtlTLz/gVwAAsuAMvHE/7AGpZ7tbfmZWDiCjiq+7YLQB+5e1lCvG/QE3ggNBpuT1rQQkEPj+yezA==
|
||||||
|
dependencies:
|
||||||
|
"@tracespace/parser" "5.0.0-alpha.0"
|
||||||
|
"@types/unist" "^2.0.6"
|
||||||
|
|
||||||
|
"@tracespace/renderer@5.0.0-alpha.0", "@tracespace/renderer@^5.0.0-alpha.0":
|
||||||
|
version "5.0.0-alpha.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@tracespace/renderer/-/renderer-5.0.0-alpha.0.tgz#c5778da337d3d06cbea4add661f488e1d99f44dd"
|
||||||
|
integrity sha512-juLVp880nVNXlEqRdl20mN2HYYluz4mhATzha2oDqOjot0qzWHWG/2ZJ9QLSfArbhB5V+YKZFuQeemfsvZ5+vw==
|
||||||
|
dependencies:
|
||||||
|
"@tracespace/parser" "5.0.0-alpha.0"
|
||||||
|
"@tracespace/plotter" "5.0.0-alpha.0"
|
||||||
|
"@tracespace/xml-id" "5.0.0-alpha.0"
|
||||||
|
"@types/hast" "^2.3.4"
|
||||||
|
|
||||||
|
"@tracespace/xml-id@5.0.0-alpha.0":
|
||||||
|
version "5.0.0-alpha.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@tracespace/xml-id/-/xml-id-5.0.0-alpha.0.tgz#79fb8b5a9d08078189f045a23a3e0c3d1ac720ad"
|
||||||
|
integrity sha512-+RTkH5Ar3U4nhF7LLhIbSpDKUAo3NFRDXNN/Pm5YMgjBCX/jDj8YsvaldOPwccDKFJR2RQIyLB85kWZXp7iR7A==
|
||||||
|
|
||||||
"@tracespace/xml-id@^4.2.7":
|
"@tracespace/xml-id@^4.2.7":
|
||||||
version "4.2.7"
|
version "4.2.7"
|
||||||
resolved "https://registry.yarnpkg.com/@tracespace/xml-id/-/xml-id-4.2.7.tgz#8754d7eefd58e5eba5121c3d9e6f18432c05063e"
|
resolved "https://registry.yarnpkg.com/@tracespace/xml-id/-/xml-id-4.2.7.tgz#8754d7eefd58e5eba5121c3d9e6f18432c05063e"
|
||||||
|
|
@ -2319,6 +2375,13 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/unist" "*"
|
"@types/unist" "*"
|
||||||
|
|
||||||
|
"@types/hast@^2.3.4":
|
||||||
|
version "2.3.10"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/hast/-/hast-2.3.10.tgz#5c9d9e0b304bbb8879b857225c5ebab2d81d7643"
|
||||||
|
integrity sha512-McWspRw8xx8J9HurkVBfYj0xKoE25tOFlHGdx4MJ5xORQrMGZNqJhVQWaIbm6Oyla5kYOXtDiopzKRJzEOkwJw==
|
||||||
|
dependencies:
|
||||||
|
"@types/unist" "^2"
|
||||||
|
|
||||||
"@types/hast@^3.0.0":
|
"@types/hast@^3.0.0":
|
||||||
version "3.0.4"
|
version "3.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/@types/hast/-/hast-3.0.4.tgz#1d6b39993b82cea6ad783945b0508c25903e15aa"
|
resolved "https://registry.yarnpkg.com/@types/hast/-/hast-3.0.4.tgz#1d6b39993b82cea6ad783945b0508c25903e15aa"
|
||||||
|
|
@ -2352,6 +2415,11 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/unist" "*"
|
"@types/unist" "*"
|
||||||
|
|
||||||
|
"@types/moo@^0.5.0", "@types/moo@^0.5.5":
|
||||||
|
version "0.5.9"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/moo/-/moo-0.5.9.tgz#940c6870d85e8eb26b94797ea1b7d4099d099b2a"
|
||||||
|
integrity sha512-ZsFVecFi66jGQ6L41TonEaBhsIVeVftTz6iQKWTctzacHhzYHWvv9S0IyAJi4BhN7vb9qCQ3+kpStP2vbZqmDg==
|
||||||
|
|
||||||
"@types/ms@*":
|
"@types/ms@*":
|
||||||
version "0.7.34"
|
version "0.7.34"
|
||||||
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433"
|
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433"
|
||||||
|
|
@ -2404,6 +2472,11 @@
|
||||||
resolved "https://registry.npmjs.org/@types/unist/-/unist-2.0.3.tgz"
|
resolved "https://registry.npmjs.org/@types/unist/-/unist-2.0.3.tgz"
|
||||||
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==
|
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==
|
||||||
|
|
||||||
|
"@types/unist@^2", "@types/unist@^2.0.6":
|
||||||
|
version "2.0.10"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.10.tgz#04ffa7f406ab628f7f7e97ca23e290cd8ab15efc"
|
||||||
|
integrity sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==
|
||||||
|
|
||||||
"@types/unist@^3.0.0":
|
"@types/unist@^3.0.0":
|
||||||
version "3.0.2"
|
version "3.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-3.0.2.tgz#6dd61e43ef60b34086287f83683a5c1b2dc53d20"
|
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-3.0.2.tgz#6dd61e43ef60b34086287f83683a5c1b2dc53d20"
|
||||||
|
|
@ -6460,6 +6533,11 @@ minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6:
|
||||||
resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.0.4.tgz#dbce03740f50a4786ba994c1fb908844d27b038c"
|
resolved "https://registry.yarnpkg.com/minipass/-/minipass-7.0.4.tgz#dbce03740f50a4786ba994c1fb908844d27b038c"
|
||||||
integrity sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==
|
integrity sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==
|
||||||
|
|
||||||
|
moo@^0.5.1:
|
||||||
|
version "0.5.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/moo/-/moo-0.5.2.tgz#f9fe82473bc7c184b0d32e2215d3f6e67278733c"
|
||||||
|
integrity sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==
|
||||||
|
|
||||||
ms@2.0.0:
|
ms@2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue