diff --git a/nuxt.config.ts b/nuxt.config.ts index ea64a0c6..a0b36957 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -131,7 +131,8 @@ export default defineNuxtConfig({ github: { // my GH ID id: 'MDQ6VXNlcjI4NzA2Mzcy', - // fetching GH repos in build and sponsors when deployed + // fetching GH repos in build + sponsors when deployed + // as well as updating my GH status token: '', // oauth flow clientSecret: '', diff --git a/server/api/update-location.post.ts b/server/api/update-location.post.ts index 93a62d64..55938f3b 100644 --- a/server/api/update-location.post.ts +++ b/server/api/update-location.post.ts @@ -62,9 +62,35 @@ export default defineEventHandler(async event => { await sanity.client.create({ _type: 'location', ...locationData }) } + try { + const emoji = locationData.city.includes('Edinburgh') + ? '🏠' + : locationData.region === 'Scotland' + ? '🏴󠁧󠁢󠁳󠁣󠁴󠁿' + : locationData.countryCode + ? String.fromCodePoint(...[...locationData.countryCode.toUpperCase()].map(char => char.charCodeAt(0) + 127397)) + : '🌍' + await updateGitHubStatus(config.github.token, emoji) + } + catch (error) { + console.error('Failed to update GitHub status:', error) + } + return null }) +async function updateGitHubStatus (token: string, emoji: string) { + await query(token, ` + mutation { + changeUserStatus(input: { + emoji: "${emoji}", + }) { + status { emoji } + } + } + `) +} + type BigDataResponse = { city: string locality?: string