Skip to content

Commit

Permalink
feat: build error
Browse files Browse the repository at this point in the history
  • Loading branch information
nakasyou committed Feb 11, 2024
1 parent ad470bc commit cfe7ebd
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 573 deletions.
6 changes: 2 additions & 4 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { defineConfig } from 'astro/config';
import deno from "./integrations/cf-pages";
import solidJs from "@astrojs/solid-js";
import tailwind from "@astrojs/tailwind";
import svelte from "@astrojs/svelte";
import { passthroughImageService } from 'astro/config';
import sitemap from "@astrojs/sitemap";
import cloudflare from '@astrojs/cloudflare'

// https://astro.build/config
export default defineConfig({
output: "server",
site: "https://nanoha.pages.dev",
adapter: process.env.IS_CF ? cloudflare({

}) : deno(),
adapter: cloudflare(),
integrations: [tailwind({}), solidJs(), svelte(), sitemap()],
image: {
service: passthroughImageService()
Expand Down
Binary file modified bun.lockb
Binary file not shown.
53 changes: 0 additions & 53 deletions integrations/cf-pages/const/compatibleNodeModules.ts

This file was deleted.

35 changes: 0 additions & 35 deletions integrations/cf-pages/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions integrations/cf-pages/server/_worker.js

This file was deleted.

13 changes: 0 additions & 13 deletions integrations/cf-pages/server/server.ts

This file was deleted.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@astrojs/sitemap": "^3.0.5",
"@astrojs/svelte": "latest",
"@astrojs/tailwind": "5.1.0",
"@astrojs/vercel": "7.0.2",
"@solid-primitives/keyed": "^1.2.0",
"@tabler/icons": "^2.47.0",
"@tabler/icons-solidjs": "^2.36.0",
Expand All @@ -29,7 +28,6 @@
"classnames": "^2.3.2",
"dexie": "^3.2.4",
"fflate": "^0.8.0",
"googleapis": "^133.0.0",
"mikanui": "^0.1.12",
"sharp": "0.33.0-alpha.6",
"solid-js": "^1.7.12",
Expand Down
12 changes: 2 additions & 10 deletions src/pages/api/[...path].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type { APIRoute } from 'astro'
import { Hono } from 'hono'
import { getCookie, setCookie } from 'hono/cookie'
import { parse, safeParse } from 'valibot'
import { makeOauth2Client, type Credentials, accessTokenResponseSchema, fetchUserInfo } from '../../utils/google-oauth'
import { google } from 'googleapis'
import { makeOauth2Client, type Credentials, credentialsSchema, fetchUserInfo } from '../../utils/google-oauth'

const app = new Hono<{
Variables: {
Expand All @@ -19,7 +18,7 @@ const googleRoutes = app.basePath('/google')
error: 'NOT_LOGINED'
}, 400)
}
const credentials = safeParse(accessTokenResponseSchema, JSON.parse(credentialsText))
const credentials = safeParse(credentialsSchema, JSON.parse(credentialsText))
if (!credentials.success) {
return c.json({
error: 'NOT_LOGINED'
Expand All @@ -36,13 +35,6 @@ const googleRoutes = app.basePath('/google')
data: userInfo.data
} : {})})
})
.get('/get-nnote', async c => {
const driveClient = google.drive({ version: 'v2', auth: c.var.googleOauthClient })

const list = await driveClient.files.list()

return c.json(list)
})

export type Routes = typeof app | typeof googleRoutes

Expand Down
20 changes: 7 additions & 13 deletions src/utils/google-oauth/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { google } from "googleapis"
import { number, object, parse, string, type Output, type BaseSchema, any, type Input, safeParse } from "valibot"
import { number, object, parse, string, type Output, type BaseSchema, any, type Input, safeParse, optional } from "valibot"

export const redirectUri = new URL('/google-oauth/callback', import.meta.env.DEV ? (import.meta.env.DEV_SITE ?? 'http://localhost:4321') : import.meta.env.SITE).href

export const makeOauth2Client = () => new google.auth.OAuth2({
clientId: import.meta.env.GOOGLE_OAUTH_CLIENT_ID,
clientSecret: import.meta.env.GOOGLE_OAUTH_CLIENT_SECRET,
redirectUri
})

export const accessTokenResponseSchema = object({
export const credentialsSchema = object({
access_token: string(),
expires_in: number(),
refresh_token: optional(string()),
scope: string(),
token_type: string(),
id_token: string()
id_token: string(),
})

export type Credentials = Output<typeof accessTokenResponseSchema>
export type Credentials = Output<typeof credentialsSchema>

export const createAuthRedirectURL = (scopes: string[]) => {
const params = new URLSearchParams()
Expand Down Expand Up @@ -53,8 +47,8 @@ export const fetchAccessToken = async (callbackCode: string) => {
method: 'POST'
})
const json = await fetch(req).then(res => res.json())
console.log(json)
return parse(accessTokenResponseSchema, json)

return parse(credentialsSchema, json)
}

type FetchResult <Schema extends BaseSchema> = {
Expand Down
Loading

0 comments on commit cfe7ebd

Please sign in to comment.