Fixed to retrieve the template header file from gist (#316)

This commit is contained in:
tequ
2025-02-13 22:32:17 +09:00
committed by GitHub
parent 6ed0b54fc5
commit 12ebd4c1bc
2 changed files with 35 additions and 13 deletions

View File

@@ -24,19 +24,28 @@ export const fetchFiles = async (gistId: string) => {
.includes(id) .includes(id)
if (isTemplate(gistId)) { if (isTemplate(gistId)) {
// fetch headers const template = Object.values(templateFileIds).find(tmp => tmp.id === gistId)
const headerRes = await fetch( let headerFiles: Record<string, { filename: string; content: string; language: string }> =
`${process.env.NEXT_PUBLIC_COMPILE_API_BASE_URL}/api/header-files`
)
if (!headerRes.ok) throw Error('Failed to fetch headers')
const headerJson = await headerRes.json()
const headerFiles: Record<string, { filename: string; content: string; language: string }> =
{} {}
Object.entries(headerJson).forEach(([key, value]) => { if (template?.headerId) {
const fname = `${key}.h` const resHeader = await octokit.request('GET /gists/{gist_id}', { gist_id: template.headerId })
headerFiles[fname] = { filename: fname, content: value as string, language: 'C' } if (!resHeader.data.files) throw new Error('No header files could be fetched from given gist id!')
}) headerFiles = resHeader.data.files as any
} else {
// fetch headers
const headerRes = await fetch(
`${process.env.NEXT_PUBLIC_COMPILE_API_BASE_URL}/api/header-files`
)
if (!headerRes.ok) throw Error('Failed to fetch headers')
const headerJson = await headerRes.json()
const headerFiles: Record<string, { filename: string; content: string; language: string }> =
{}
Object.entries(headerJson).forEach(([key, value]) => {
const fname = `${key}.h`
headerFiles[fname] = { filename: fname, content: value as string, language: 'C' }
})
}
const files = { const files = {
...res.data.files, ...res.data.files,
...headerFiles ...headerFiles

View File

@@ -4,36 +4,49 @@ import Notary from '../../components/icons/Notary'
import Peggy from '../../components/icons/Peggy' import Peggy from '../../components/icons/Peggy'
import Starter from '../../components/icons/Starter' import Starter from '../../components/icons/Starter'
export const templateFileIds = { type Template = {
id: string
name: string
description: string
headerId?: string
icon: () => JSX.Element
}
export const templateFileIds: Record<string, Template> = {
starter: { starter: {
id: '1f8109c80f504e6326db2735df2f0ad6', // Forked id: '1f8109c80f504e6326db2735df2f0ad6', // Forked
name: 'Starter', name: 'Starter',
description: description:
'Just a basic starter with essential imports, just accepts any transaction coming through', 'Just a basic starter with essential imports, just accepts any transaction coming through',
headerId: '028e8ce6d6d674776970caf8acc77ecc',
icon: Starter icon: Starter
}, },
firewall: { firewall: {
id: '1cc30f39c8a0b9c55b88c312669ca45e', // Forked id: '1cc30f39c8a0b9c55b88c312669ca45e', // Forked
name: 'Firewall', name: 'Firewall',
description: 'This Hook essentially checks a blacklist of accounts', description: 'This Hook essentially checks a blacklist of accounts',
headerId: '028e8ce6d6d674776970caf8acc77ecc',
icon: Firewall icon: Firewall
}, },
notary: { notary: {
id: '87b6f5a8c2f5038fb0f20b8b510efa10', // Forked id: '87b6f5a8c2f5038fb0f20b8b510efa10', // Forked
name: 'Notary', name: 'Notary',
description: 'Collecting signatures for multi-sign transactions', description: 'Collecting signatures for multi-sign transactions',
headerId: '028e8ce6d6d674776970caf8acc77ecc',
icon: Notary icon: Notary
}, },
carbon: { carbon: {
id: '953662b22d065449f8ab6f69bc2afe41', // Forked id: '953662b22d065449f8ab6f69bc2afe41', // Forked
name: 'Carbon', name: 'Carbon',
description: 'Send a percentage of sum to an address', description: 'Send a percentage of sum to an address',
headerId: '028e8ce6d6d674776970caf8acc77ecc',
icon: Carbon icon: Carbon
}, },
peggy: { peggy: {
id: '049784a83fa068faf7912f663f7b6471', // Forked id: '049784a83fa068faf7912f663f7b6471', // Forked
name: 'Peggy', name: 'Peggy',
description: 'An oracle based stable coin hook', description: 'An oracle based stable coin hook',
headerId: '028e8ce6d6d674776970caf8acc77ecc',
icon: Peggy icon: Peggy
} }
} }