-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from hanbings/main
整体重构(WIP)
- Loading branch information
Showing
34 changed files
with
571 additions
and
542 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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
export default class Message<T> { | ||
constructor( | ||
public status: number, | ||
public message: string, | ||
public data: T | ||
) { | ||
} | ||
export default interface Message<T> { | ||
status: number, | ||
message: string, | ||
data: T, | ||
} |
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 |
---|---|---|
@@ -1,21 +1,13 @@ | ||
export class Token { | ||
constructor( | ||
// TOKEN | ||
public token: string, | ||
// 所属账号 | ||
public belong: string, | ||
// TOKEN 类型 | ||
public type: TokenType, | ||
// 创建时间 | ||
public created: number, | ||
// 失效时间 | ||
public expire: number | ||
) { | ||
} | ||
export interface Token { | ||
token: string, | ||
belong: string, | ||
type: TokenType, | ||
created: number, | ||
expire: number, | ||
} | ||
|
||
export enum TokenType { | ||
OAUTH_TOKEN = "oauth_token", | ||
ACCOUNT_API_KEY = "account_api_key", | ||
EMAIL_VERIFY_CODE = "email_verify_code" | ||
EMAIL_VERIFY_CODE = "email_verify_code", | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {Generated} from "kysely"; | ||
import {Generated} from "kysely" | ||
|
||
export class RepositoryTable { | ||
constructor( | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {Generated} from "kysely"; | ||
import {Generated} from "kysely" | ||
|
||
export class StatisticTable { | ||
constructor( | ||
|
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 |
---|---|---|
@@ -1,38 +1,46 @@ | ||
import type {NextApiRequest, NextApiResponse} from 'next' | ||
import Message from "@/common/message"; | ||
import CacheService from "@/services/cache"; | ||
import {Token} from "@/common/token"; | ||
import DatabaseService from "@/services/database"; | ||
import {Repository} from "@/common/repository"; | ||
import {Account} from "@/common/account"; | ||
import CacheService from "@/services/cache" | ||
import {Token} from "@/common/token" | ||
import DatabaseService from "@/services/database" | ||
import {Repository} from "@/common/repository" | ||
import {Account} from "@/common/account" | ||
import Message from "@/common/message" | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<{}>) { | ||
if (req.method === 'GET') { | ||
// 查询 Token | ||
const header = req.headers['authorization']; | ||
export default async function handler(req: NextApiRequest, res: NextApiResponse<Message<any>>) { | ||
if (req.method !== 'GET') { | ||
res.status(400).json({status: 400, message: 'request method not match.', data: null}) | ||
return | ||
} | ||
|
||
if (header === undefined || header === null) { | ||
res.status(400).json(new Message(400, 'token is invalid.', null)); | ||
return; | ||
} | ||
// 查询 Token | ||
const header = req.headers['authorization']; | ||
|
||
if (header === undefined || header === null) { | ||
res.status(400).json({status: 400, message: 'token is invalid.', data: null}) | ||
return | ||
} | ||
|
||
const tokens = new CacheService<Token>(); | ||
const token = await tokens.get(header as string) as Token; | ||
const tokens = new CacheService<Token>() | ||
const token = await tokens.get(header as string) as Token | ||
|
||
// 查询账号信息 | ||
const accounts = new DatabaseService<Account>(); | ||
const id = token.belong; | ||
const account = await accounts.readAccountById(id); | ||
// 查询账号信息 | ||
const accounts = new DatabaseService<Account>() | ||
const id = token.belong | ||
const account = await accounts.readAccountById(id) | ||
|
||
// 查询仓库列表 | ||
const repositories = new DatabaseService<Repository>(); | ||
const repos = await repositories.readRepositoryByAccount(id); | ||
// 查询仓库列表 | ||
const repositories = new DatabaseService<Repository>() | ||
const repos = await repositories.readRepositoryByAccount(id) | ||
|
||
res.status(200).json(new Message(200, 'success.', | ||
{ | ||
res.status(200).json( | ||
{ | ||
status: 200, | ||
message: 'success.', | ||
data: { | ||
id: id, | ||
account: account.length !== 0 ? account[0] : {}, | ||
repositories: repos | ||
})); | ||
} else res.status(400).json(new Message(400, 'request method not match.', null)); | ||
repositories: repos, | ||
} | ||
} | ||
); | ||
} |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import {NextApiRequest, NextApiResponse} from "next"; | ||
import {NextApiRequest, NextApiResponse} from "next" | ||
import Message from "@/common/message"; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<{}>) { | ||
if (req.method === 'GET') { | ||
res.status(200).json(new Message(200, 'OK', null)); | ||
} else res.status(400).json(new Message(400, 'request method not match.', null)); | ||
export default async function handler(req: NextApiRequest, res: NextApiResponse<Message<any>>) { | ||
if (req.method !== 'GET') { | ||
res.status(400).json({status: 400, message: 'request method not match.', data: null}) | ||
return | ||
} | ||
|
||
res.status(200).json({status: 200, message: 'OK', data: null}) | ||
} |
Oops, something went wrong.