Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
Signed-off-by: 0x73746F66 <[email protected]>
  • Loading branch information
0x73746F66 committed Jun 13, 2024
1 parent 06a5e22 commit 9f4d078
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 111 deletions.
15 changes: 8 additions & 7 deletions functions/github/install/[installation_id]/[code].js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function onRequestGet(context) {
if (session?.expiry <= +new Date()) {
return Response.json({ 'err': 'Expired' })
}
if (params?.code) {
if (params?.code && params?.installation_id) {
const method = "POST"
const url = new URL("https://github.com/login/oauth/access_token")

Expand All @@ -45,18 +45,19 @@ export async function onRequestGet(context) {
throw new Error(data.error)
}
if (!data?.access_token) {
console.log('installation_id', params?.installation_id, 'kid', token, 'data', data)
console.log('installationId', params.installation_id, 'kid', token, 'data', data)
throw new Error('OAuth response invalid')
}
const created = +new Date()

const info = await env.d1db.prepare('INSERT INTO integration_github (installation_id, memberEmail, access_key) VALUES (?1, ?2, ?3)')
.bind(params?.installation_id, session?.memberEmail, data.access_token)
const info = await env.d1db.prepare('INSERT INTO github_apps (installationId, memberEmail, accessToken, created, expires) VALUES (?1, ?2, ?3, ?4, ?5)')
.bind(params.installation_id, session.memberEmail, data.access_token, created, (86400000 * 365 * 10) + created)
.run()

console.log(`/github/install installation_id=${params?.installation_id} kid=${token}`, info)
console.log(`/github/install installationId=${params?.installation_id} kid=${token}`, info)

return Response.json(info)
}

return Response.json({ 'err': 'OAuth authorization code not provided' })
}
51 changes: 26 additions & 25 deletions functions/github/repos.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,37 @@ export async function onRequestGet(context) {
return Response.json({ 'err': 'Expired' })
}

const access_token = await
env.d1db.prepare("SELECT access_key FROM integration_github WHERE memberEmail = ?")
.bind(session.memberEmail)
.first('access_key')

if (!access_token) {
console.log(`integration_github kid=${token}`)
throw new Error('integration_github invalid')
}
let repos = []
try {
const fetcher = new GitHubRepoFetcher(access_token)
const github_apps = await
env.d1db.prepare("SELECT * FROM github_apps WHERE memberEmail = ?")
.bind(session.memberEmail)
.all()

for (const github_app of github_apps) {
if (!github_app.access_token) {
console.log(`github_apps kid=${token}`, github_app) //TODO remove secrets
throw new Error('github_apps invalid')
}
const fetcher = new GitHubRepoFetcher(github_app.access_token)

console.log('headers', fetcher.headers)
console.log('fetcher', fetcher.repos)

console.log('headers', fetcher.headers)
console.log('fetcher', fetcher.repos)
const details = await fetcher.getRepoDetails()

const details = await fetcher.getRepoDetails()
console.log('details', details)
console.log('fetcher', fetcher.repos)

console.log('details', details)
console.log('fetcher', fetcher.repos)
repos = repos.join(JSON.stringify(details, null, 2))

const repos = JSON.stringify(details, null, 2)
console.log('repos', repos)
}

console.log('repos', repos)

return Response.json(repos)
} catch (e) {
console.error(e)

return Response.json(e)
}
}
Expand All @@ -63,8 +66,8 @@ class GitHubRepoFetcher {
constructor(accessKey) {
this.repos = []
this.headers = {
'Authorization': `Bearer ${accessKey}`,
'Accept': 'application/vnd.github+json',
'Authorization': `Bearer ${accessKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}
this.baseUrl = "https://api.github.com"
Expand All @@ -76,7 +79,7 @@ class GitHubRepoFetcher {
if (!response.ok) {
throw new Error(`GitHubRepoFetcher error! status: ${response.status}`)
}

return response.json()
}
async getRepos() {
Expand All @@ -102,11 +105,11 @@ class GitHubRepoFetcher {
}
const file = await fileResponse.json()
const content = Buffer.from(file.content, file.encoding).toString('utf-8')

return { exists: true, content }
} catch (error) {
console.error(error)

return { exists: false, content: null }
}
}
Expand Down Expand Up @@ -142,7 +145,5 @@ class GitHubRepoFetcher {
})
}
}

return this.repos
}
}
2 changes: 1 addition & 1 deletion functions/login/[email]/[hash].js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function onRequestGet(context) {
const authn_ip = request.headers.get('cf-connecting-ip')
const authn_ua = request.headers.get('user-agent')
const issued = +new Date()
const expiry = issued + (86400 * 30) // 30 days
const expiry = issued + (86400000 * 30) // 30 days
const secret = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-1", crypto.getRandomValues(new Uint32Array(26))))).map(b => b.toString(16).padStart(2, "0")).join("")

const info = await env.d1db.prepare('INSERT INTO sessions (kid, memberEmail, expiry, issued, secret, authn_ip, authn_ua) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)')
Expand Down
76 changes: 62 additions & 14 deletions src/pages/GitHub.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,53 @@ const gh = reactive(new GitHub())
<template>
<VRow>
<VCol cols="12">
<VAlert v-if="state.error" color="error" icon="$error" title="Server Error" :text="state.error"
border="start" variant="tonal" closable close-label="Close Alert" />
<VAlert v-if="state.warning" color="warning" icon="$warning" title="Warning" :text="state.warning"
border="start" variant="tonal" closable close-label="Close Alert" />
<VAlert
v-if="state.error"
color="error"
icon="$error"
title="Server Error"
:text="state.error"
border="start"
variant="tonal"
closable
close-label="Close Alert"
/>
<VAlert
v-if="state.warning"
color="warning"
icon="$warning"
title="Warning"
:text="state.warning"
border="start"
variant="tonal"
closable
close-label="Close Alert"
/>
</VCol>
<VCol cols="12">
<VCard title="GitHub">
<VCardText>
<VBtn v-if="gh.repos.length === 0" text="Connect to GitHub" prepend-icon="mdi-github" variant="text"
:color="global.name.value === 'dark' ? '#fff' : '#272727'" @click="gh.integrate" />
<VBtn v-else text="Refresh" prepend-icon="mdi-github" variant="text"
:color="global.name.value === 'dark' ? '#fff' : '#272727'" @click="gh.refresh" />
<VBtn
v-if="gh.repos.length === 0"
text="Connect to GitHub"
prepend-icon="mdi-github"
variant="text"
:color="global.name.value === 'dark' ? '#fff' : '#272727'"
@click="gh.integrate"
/>
<VBtn
v-else
text="Refresh"
prepend-icon="mdi-github"
variant="text"
:color="global.name.value === 'dark' ? '#fff' : '#272727'"
@click="gh.refresh"
/>
</VCardText>
<VTable height="80%" fixed-header>
<VTable
height="80%"
fixed-header
>
<thead>
<tr>
<th class="text-uppercase">
Expand All @@ -115,24 +148,39 @@ const gh = reactive(new GitHub())
</thead>
<tbody>
<tr v-for="item in gh.repos" :key="item.latestCommitSHA">
<tr
v-for="item in gh.repos"
:key="item.latestCommitSHA"
>
<td :title="item.createdAt">
{{ item.fullName }}
</td>
<td class="text-center" :title="item.latestCommitSHA">
<td
class="text-center"
:title="item.latestCommitSHA"
>
{{ item.branch }}<span v-if="item.branch === item.defaultBranch"> (default)</span>
</td>
<td class="text-center">
{{ item.visibility }}
</td>
<td class="text-center" :title="item.latestCommitSHA">
<img v-if="item.avatarUrl" :src="item.avatarUrl">
<td
class="text-center"
:title="item.latestCommitSHA"
>
<img
v-if="item.avatarUrl"
:src="item.avatarUrl"
>
<span class="ms-1">{{ item.latestCommitMessage }}</span>
</td>
<td class="text-center">
{{ item.pushedAt }}
</td>
<td class="text-center" :title="item.dotfileContents">
<td
class="text-center"
:title="item.dotfileContents"
>
{{ item.dotfileExists }}
</td>
</tr>
Expand Down
58 changes: 47 additions & 11 deletions src/pages/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ const login = async () => {
<template>
<div class="auth-wrapper d-flex align-center justify-center pa-4">
<VCard class="auth-card pa-4 pt-7" max-width="448">
<VCard
class="auth-card pa-4 pt-7"
max-width="448"
>
<VCardItem class="justify-center">
<template #prepend>
<div class="d-flex">
<IconTrivialSecurity class="d-flex text-primary" width="150" />
<IconTrivialSecurity
class="d-flex text-primary"
width="150"
/>
</div>
</template>
</VCardItem>
Expand All @@ -74,34 +80,64 @@ const login = async () => {
<VForm @submit.prevent="login">
<VRow>
<VCol cols="12">
<VAlert v-if="state.error" color="error" icon="$error" title="Server Error"
:text="state.error" border="start" variant="tonal" closable close-label="Close Alert" />
<VAlert
v-if="state.error"
color="error"
icon="$error"
title="Server Error"
:text="state.error"
border="start"
variant="tonal"
closable
close-label="Close Alert"
/>
</VCol>
<!-- email -->
<VCol cols="12">
<VTextField v-model="state.email" autofocus placeholder="[email protected]" label="Email"
type="email" />
<VTextField
v-model="state.email"
autofocus
placeholder="[email protected]"
label="Email"
type="email"
/>
</VCol>
<!-- password -->
<VCol cols="12">
<VTextField v-model="state.password" required label="Password" placeholder="············"
<VTextField
v-model="state.password"
required
label="Password"
placeholder="············"
:error-messages="v$.password.$errors.map(e => e.$message)"
:type="isPasswordVisible ? 'text' : 'password'"
:append-inner-icon="isPasswordVisible ? 'bx-hide' : 'bx-show'"
@click:append-inner="isPasswordVisible = !isPasswordVisible" />
@click:append-inner="isPasswordVisible = !isPasswordVisible"
/>
</VCol>
<!-- login button -->
<VCol cols="12">
<VBtn block text="Login" type="submit" @click="v$.$validate" />
<VBtn
block
text="Login"
type="submit"
@click="v$.$validate"
/>
</VCol>
<!-- create account -->
<VCol cols="12" class="text-center text-base">
<VCol
cols="12"
class="text-center text-base"
>
<span>New on our platform?</span>
<RouterLink class="text-primary ms-2" to="/register">
<RouterLink
class="text-primary ms-2"
to="/register"
>
Create an account
</RouterLink>
</VCol>
Expand Down
Loading

0 comments on commit 9f4d078

Please sign in to comment.