Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
CRATES_PRO_HOST=http://210.28.134.203:31688
CRATES_PRO_INTERNAL_HOST=http://210.28.134.203:31688

SECRET_KEY=$YOUR_SECRET_KEY #(not prefixed with NEXT_PUBLIC_ )
# SECRET_KEY=$YOUR_SECRET_KEY #(not prefixed with NEXT_PUBLIC_ )


AUTH_HOST=true
69 changes: 67 additions & 2 deletions app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,67 @@
import { handlers } from "@/app/auth" // Referring to the auth.ts we just created
export const { GET, POST } = handlers
import { handlers } from "@/app/auth"
import { NextResponse } from 'next/server'
import { NextRequest } from 'next/server'
import { getProxyConfig } from "@/proxy-config"

const TIMEOUT_DURATION = 60000;

// 定义超时 Promise 的类型
type TimeoutPromise = Promise<never>

export async function GET(request: NextRequest): Promise<Response> {
try {
const { isEnabled } = getProxyConfig();

if (isEnabled) {
// 使用超时机制
const timeoutPromise: TimeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error('Request timeout')), TIMEOUT_DURATION)
);
const response = await Promise.race([handlers.GET(request), timeoutPromise]);
return response instanceof Response ? response : NextResponse.json(response);
} else {
// 不使用超时机制
const response = await handlers.GET(request);
return response instanceof Response ? response : NextResponse.json(response);
}
} catch (error) {
console.error('Auth GET Error:', error);
return NextResponse.json(
{
error: 'Authentication error',
details: error instanceof Error ? error.message : 'Unknown error',
timestamp: new Date().toISOString()
},
{ status: 500 }
);
}
}

export async function POST(request: NextRequest): Promise<Response> {
try {
const { isEnabled } = getProxyConfig();

if (isEnabled) {
// 使用超时机制
const timeoutPromise: TimeoutPromise = new Promise((_, reject) =>
setTimeout(() => reject(new Error('Request timeout')), TIMEOUT_DURATION)
);
const response = await Promise.race([handlers.POST(request), timeoutPromise]);
return response instanceof Response ? response : NextResponse.json(response);
} else {
// 不使用超时机制
const response = await handlers.POST(request);
return response instanceof Response ? response : NextResponse.json(response);
}
} catch (error) {
console.error('Auth POST Error:', error);
return NextResponse.json(
{
error: 'Authentication error',
details: error instanceof Error ? error.message : 'Unknown error',
timestamp: new Date().toISOString()
},
{ status: 500 }
);
}
}
31 changes: 31 additions & 0 deletions app/api/profile/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { NextResponse } from 'next/server';

export async function POST(request: Request) {
const endpoint = process.env.CRATES_PRO_INTERNAL_HOST;
const apiUrl = `${endpoint}/api/profile`;
const requestBody = await request.json();
console.log("Request Body:", requestBody);

try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json', // 确保发送 JSON
},
body: JSON.stringify({
requestBody
}), // 发送请求体
});
console.log("response in get profile info:", response);
if (!response.ok) {
return NextResponse.json({ error: 'Failed to submit data' }, { status: response.status });
}

const result = await response.json(); // 确认返回的是 JSON 格式
console.log("results:", result);
return NextResponse.json({ message: 'Submission successful', code: 2012, crates: result });
} catch (error) {
console.log(error);
return NextResponse.json({ error: 'An error occurred while submitting data.' }, { status: 500 });
}
}
3 changes: 2 additions & 1 deletion app/api/submit/route.ts → app/api/submitCrate/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NextResponse } from 'next/server';

export async function POST(request: Request) {
const apiUrl = process.env.API_URL; // 读取环境变量
const endpoint = process.env.CRATES_PRO_INTERNAL_HOST;
const apiUrl = `${endpoint}/api/submitCrate`;
const formData = await request.formData(); // 解析请求体

console.log("Request FormData:", formData);
Expand Down
35 changes: 35 additions & 0 deletions app/api/submitUserinfo/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { NextResponse } from 'next/server';


export async function POST(request: Request) {
const endpoint = process.env.CRATES_PRO_INTERNAL_HOST;
const apiUrl = `${endpoint}/api/submitUserinfo`;
const requestBody = await request.json();



console.log("Request Body new!:", requestBody);
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json', // 确保发送 JSON
'Accept': 'application/json'
},
body: JSON.stringify({
requestBody
}), // 发送 name 字段
});
console.log("response:", response);
if (!response.ok) {
return NextResponse.json({ error: 'Failed to submit data' }, { status: response.status });
}

const result = await response.json(); // 确认返回的是 JSON 格式
console.log("results:", result);
return NextResponse.json({ message: 'Submission successful', code: 2012, data: result });
} catch (error) {
console.log(error);
return NextResponse.json({ error: 'An error occurred while submitting data.' }, { status: 500 });
}
}
64 changes: 61 additions & 3 deletions app/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,65 @@

import NextAuth from "next-auth"
import GitHub from "next-auth/providers/github"
import { setupGlobalFetch } from "@/proxy-config"

// 设置全局代理(如果启用)
setupGlobalFetch();

// 打印环境变量(开发环境调试用)
console.log('Environment Config:', {
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
PROXY_ENABLED: !!process.env.HTTPS_PROXY,
PROXY_URL: process.env.HTTPS_PROXY || 'Not configured'
});

if (!process.env.AUTH_GITHUB_ID || !process.env.AUTH_GITHUB_SECRET) {
throw new Error('Missing GITHUB_ID or GITHUB_SECRET environment variable')
}

export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [GitHub],
})
providers: [
GitHub({
clientId: process.env.AUTH_GITHUB_ID,
clientSecret: process.env.AUTH_GITHUB_SECRET,
authorization: {
params: {
prompt: "consent",
access_type: "offline",
response_type: "code"
}
}
})
],
trustHost: true,
debug: true,
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
console.log('Sign in attempt:', { user, account, profile, email, credentials });

return true;
},
async redirect({ url, baseUrl }) {
console.log('Redirect:', { url, baseUrl });
return baseUrl;
},
async session({ session, user, token }) {
console.log('Session:', { session, user, token });
return session;
},
async jwt({ token, user, account, profile }) {
console.log('JWT:', { token, user, account, profile });
return token;
}
},
events: {
async signIn(message) { console.log('signIn:', message) },
async signOut(message) { console.log('signOut:', message) },
},
pages: {
signIn: '/auth/signin',
error: '/auth/error',
}
})



47 changes: 46 additions & 1 deletion app/lib/all_interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,49 @@ export interface cveListInfo {
"end_version": string,
},
]
}
}

//六、用户github信息接口
export interface userinfo {
user: {
"email": string,
"image": string,
"name": string,
}
expires: string
}


//用户个人主页接口
export interface profile {
upload_crates:
[
{
"name": string,
"time": string,
},
{
"name": string,
"time": string,
},
]

}

export interface profileResult {

"data": [
{
"name": string,
"time": string,
},
{
"name": string,
"time": string,
},
]


}


File renamed without changes.
Loading
Loading