-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactoring to move to app router #96
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f71095e
refactoring to move to app router and other reasons
thomasdavis 0b88c5e
updated package.lock
thomasdavis 4c0c7e2
Update apps/registry/lib/getResumeGist.js
thomasdavis 9f17434
Update apps/registry/pages/api/[payload].js
thomasdavis ee53c63
Update apps/registry/lib/generateResume.js
thomasdavis 103cf02
Update apps/registry/lib/generateResume.js
thomasdavis 596b829
fix problem by coderabbit
thomasdavis 4bf25f4
update readme
thomasdavis 162732d
fix lint
thomasdavis a7e671d
remove ruby from build
thomasdavis 8adcf9a
fix registry port
thomasdavis dd0d614
updated clicky id and ai model
thomasdavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use template literals for string concatenation.
Committable suggestion