-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move github file retrieval logic to API call
Signed-off-by: tylerslaton <[email protected]>
- Loading branch information
1 parent
fd99e5b
commit fcee05b
Showing
5 changed files
with
73 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const base64Decode = (base64: string): string => { | ||
const text = atob(base64); | ||
const bytes = new Uint8Array(text.length); | ||
for (let i = 0; i < text.length; i++) { | ||
bytes[i] = text.charCodeAt(i); | ||
} | ||
const decoder = new TextDecoder('utf-8'); | ||
return decoder.decode(bytes); | ||
} |
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
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,31 @@ | ||
import { Octokit } from '@octokit/core'; | ||
|
||
export default defineEventHandler(async (event) => { | ||
const query = getQuery(event); | ||
const { owner, repo, path } = query; | ||
const octokit = new Octokit({ | ||
auth: useRuntimeConfig().githubToken, | ||
}); | ||
|
||
try { | ||
const response = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { | ||
owner: owner?.toString() ?? '', | ||
repo: repo?.toString() ?? '', | ||
path: path?.toString() ?? '', | ||
headers: { | ||
'X-GitHub-Api-Version': '2022-11-28' | ||
} | ||
}); | ||
|
||
if (!response.data.content) { | ||
throw createError({ | ||
statusCode: 404, | ||
statusMessage: `file not found`, | ||
}); | ||
} | ||
|
||
return response.data.content; | ||
} catch (error) { | ||
throw error; | ||
} | ||
}); |