-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring to move to app router (#96)
* refactoring to move to app router and other reasons * updated package.lock * Update apps/registry/lib/getResumeGist.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update apps/registry/pages/api/[payload].js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update apps/registry/lib/generateResume.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update apps/registry/lib/generateResume.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix problem by coderabbit * update readme * fix lint * remove ruby from build * fix registry port * updated clicky id and ai model --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f60a1aa
commit a958ca1
Showing
25 changed files
with
782 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export const ERROR_CODES = Object.freeze({ | ||
INVALID_USERNAME: 'INVALID_USERNAME', | ||
NON_EXISTENT_GIST: 'NON_EXISTENT_GIST', | ||
GIST_UNKNOWN_ERROR: 'GIST_UNKNOWN_ERROR', | ||
RESUME_SCHEMA_ERROR: 'RESUME_SCHEMA_ERROR', | ||
TEMPLATE_MISSING: 'TEMPLATE_MISSING', | ||
UNKNOWN_TEMPLATE_ERROR: 'UNKNOWN_TEMPLATE_ERROR', | ||
INVALID_EXTENSION: 'INVALID_EXTENSION', | ||
UNKNOWN_FORMATTER: 'UNKNOWN_FORMATTER', | ||
RESUME_NOT_VALID_JSON: 'RESUME_NOT_VALID_JSON', | ||
}); | ||
|
||
export const ERROR_CODE_MESSAGES = Object.freeze({ | ||
INVALID_USERNAME: 'This is not a valid Github username', | ||
NON_EXISTENT_GIST: | ||
'You have no gists named resume.json or your gist is private', | ||
GIST_UNKNOWN_ERROR: 'Cannot fetch gist, no idea why', | ||
RESUME_SCHEMA_ERROR: | ||
'Your resume does not conform to the schema, visit https://jsonresume.org/schema/ to double check why. But the error message below should contain all the information you need.', | ||
TEMPLATE_MISSING: | ||
'This theme is currently unsupported. Please visit this Github issue to request it https://github.com/jsonresume/jsonresume.org/issues/36 (unfortunately we have recently (11/2023) disabled a bunch of legacy themes due to critical flaws in them, please request if you would like them back.)', | ||
UNKNOWN_TEMPLATE_ERROR: | ||
'Cannot format resume, no idea why #likely-a-validation-error', | ||
INVALID_EXTENSION: `We only support the following extensions: ${[...[]].join( | ||
', ' | ||
)}`, | ||
UNKNOWN_FORMATTER: | ||
'This is a valid extension but we do not have a formatter for it. Please visit github issues.', | ||
RESUME_NOT_VALID_JSON: | ||
'Your resume is not valid JSON. Find an online JSON validator to help you debug this.', | ||
}); | ||
|
||
const buildError = (error, extra) => { | ||
return { | ||
error: { | ||
code: error, | ||
message: ERROR_CODE_MESSAGES[error], | ||
extra, | ||
}, | ||
}; | ||
}; | ||
|
||
export default buildError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import qr from './qr'; | ||
import template from './template'; | ||
import txt from './text'; | ||
import tex from './tex'; | ||
import json from './json'; | ||
import yaml from './yaml'; | ||
|
||
const formatters = { | ||
qr, | ||
json, | ||
tex, | ||
txt, | ||
template, | ||
yaml, | ||
}; | ||
|
||
export default formatters; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import schema from './schema'; | ||
import buildError, { ERROR_CODES } from './error/buildError'; | ||
import getResumeGist from './getResumeGist'; | ||
import formatters from './formatters/formatters'; | ||
|
||
const Validator = require('jsonschema').Validator; | ||
|
||
const { createClient } = require('@supabase/supabase-js'); | ||
|
||
const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co'; | ||
const supabaseKey = process.env.SUPABASE_KEY; | ||
const supabase = createClient(supabaseUrl, supabaseKey); | ||
|
||
const EXTENSIONS = new Set(['qr', 'json', 'tex', 'txt', 'template', 'yaml']); | ||
|
||
const generateResume = async (username, extension = 'template', query = {}) => { | ||
const { theme } = query; | ||
const formatter = formatters[extension]; | ||
|
||
if (!EXTENSIONS.has(extension)) { | ||
return buildError(ERROR_CODES.INVALID_EXTENSION); | ||
} | ||
|
||
if (!formatter) { | ||
return buildError(ERROR_CODES.UNKNOWN_FORMATTER); | ||
} | ||
|
||
// retrieve the users github gist | ||
const { error: gistError, resume } = await getResumeGist(username); | ||
|
||
if (gistError) { | ||
return buildError(gistError); | ||
} | ||
|
||
const v = new Validator(); | ||
const validation = v.validate(resume, schema); | ||
|
||
if (!validation.valid) { | ||
return buildError(ERROR_CODES.RESUME_SCHEMA_ERROR, { | ||
validation: validation.errors, | ||
}); | ||
} | ||
|
||
let selectedTheme = theme || resume.meta?.theme || 'elegant'; | ||
|
||
selectedTheme = selectedTheme.toLowerCase(); | ||
|
||
// @todo - using as a resume cache for extra features | ||
(async () => { | ||
try { | ||
await supabase | ||
.from('resumes') | ||
.upsert( | ||
{ | ||
username, | ||
resume: JSON.stringify(resume), | ||
updated_at: new Date(), | ||
}, | ||
{ onConflict: 'username' } | ||
) | ||
.select(); | ||
} catch (error) { | ||
console.error('Failed to cache resume:', error); | ||
} | ||
})(); | ||
|
||
const options = { ...query, theme: selectedTheme, username }; | ||
|
||
let formatted = {}; | ||
|
||
try { | ||
formatted = await formatter.format(resume, options); | ||
} catch (e) { | ||
console.error(e); | ||
// @todo - do this better | ||
if (e.message === 'theme-missing') { | ||
return buildError(ERROR_CODES.TEMPLATE_MISSING); | ||
} | ||
|
||
return buildError(ERROR_CODES.UNKNOWN_TEMPLATE_ERROR); | ||
} | ||
|
||
return { content: formatted.content, headers: formatted.headers || [] }; | ||
}; | ||
|
||
export default generateResume; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import axios from 'axios'; | ||
import { find } from 'lodash'; | ||
import buildError, { ERROR_CODES } from './error/buildError'; | ||
|
||
const GITHUB_TOKEN = process.env.GITHUB_TOKEN; | ||
|
||
const getResumeGist = async (username) => { | ||
let gistData = null; | ||
try { | ||
gistData = await axios.get( | ||
`https://api.github.com/users/${username}/gists?per_page=100`, | ||
{ | ||
headers: { | ||
...(GITHUB_TOKEN ? { Authorization: 'Bearer ' + GITHUB_TOKEN } : {}), // If we have no token and are in development, we can still make some requests. | ||
}, | ||
} | ||
); | ||
} catch (e) { | ||
console.log(e); | ||
return buildError(ERROR_CODES.INVALID_USERNAME); | ||
} | ||
|
||
if (!gistData.data) { | ||
return buildError(ERROR_CODES.GIST_UNKNOWN_ERROR); | ||
} | ||
|
||
const resumeUrl = find(gistData.data, (f) => { | ||
return f.files['resume.json']; | ||
}); | ||
|
||
if (!resumeUrl) { | ||
return buildError(ERROR_CODES.NON_EXISTENT_GIST); | ||
} | ||
|
||
const gistId = resumeUrl.id; | ||
|
||
let resumeRes = {}; | ||
|
||
try { | ||
const fullResumeGistUrl = `https://gist.githubusercontent.com/${username}/${gistId}/raw?cachebust=${new Date().getTime()}`; | ||
|
||
resumeRes = await axios({ | ||
method: 'GET', | ||
headers: { 'content-type': 'application/json' }, | ||
url: fullResumeGistUrl, | ||
}); | ||
} catch (e) { | ||
return buildError(ERROR_CODES.GIST_UNKNOWN_ERROR); | ||
} | ||
|
||
return { resume: resumeRes.data }; | ||
}; | ||
|
||
export default getResumeGist; |
Oops, something went wrong.