forked from all-in-aigc/gpts-works
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
241 additions
and
40 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,25 +1,52 @@ | ||
import { getCount, getRandRows } from "@/app/models/gpts"; | ||
import { | ||
getHotRows, | ||
getLatestRows, | ||
getRandRows, | ||
getRecommendedRows, | ||
getTotalCount, | ||
} from "@/app/models/gpts"; | ||
import { respData, respErr } from "@/app/utils/resp"; | ||
|
||
export async function POST(req: Request) { | ||
try { | ||
if (req.body) { | ||
const params = await req.json(); | ||
const { last_id, limit } = params; | ||
const { last_id, limit, tab } = params; | ||
|
||
const rows = await getRandRows(last_id, limit); | ||
const count = await getCount(); | ||
const count = await getTotalCount(); | ||
|
||
return Response.json({ | ||
code: 0, | ||
message: "ok", | ||
data: { | ||
if (tab === "latest") { | ||
const rows = await getLatestRows(last_id, limit); | ||
return respData({ | ||
rows: rows, | ||
count: count, | ||
}, | ||
}); | ||
} | ||
|
||
if (tab === "recommended") { | ||
const rows = await getRecommendedRows(last_id, limit); | ||
return respData({ | ||
rows: rows, | ||
count: count, | ||
}); | ||
} | ||
|
||
if (tab === "hot") { | ||
const rows = await getHotRows(last_id, limit); | ||
return respData({ | ||
rows: rows, | ||
count: count, | ||
}); | ||
} | ||
|
||
const rows = await getRandRows(last_id, limit); | ||
return respData({ | ||
rows: rows, | ||
count: count, | ||
}); | ||
} | ||
} catch (e) { | ||
console.log("get all gpts failed: ", e); | ||
return Response.json({ code: -1, message: e }); | ||
return respErr("get gpts failed"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Dispatch, SetStateAction } from "react"; | ||
|
||
import { Tab } from "@/app/types/tab"; | ||
|
||
interface Props { | ||
tabValue: string; | ||
setTabValue: Dispatch<SetStateAction<string>>; | ||
} | ||
|
||
export default ({ tabValue, setTabValue }: Props) => { | ||
const tabs: Tab[] = [ | ||
{ | ||
name: "hot", | ||
title: "Hot 🔥", | ||
}, | ||
{ | ||
name: "recommended", | ||
title: "Recommended", | ||
}, | ||
{ | ||
name: "latest", | ||
title: "Latest", | ||
}, | ||
{ | ||
name: "random", | ||
title: "Random", | ||
}, | ||
]; | ||
|
||
return ( | ||
<section className="relative mt-4"> | ||
<div className="mx-auto max-w-7xl px-2 py-4 md:px-8 md:py-4 text-center"> | ||
<div | ||
role="tablist" | ||
className="tabs tabs-boxed tabs-sm md:tabs-md inline-block mx-auto" | ||
> | ||
{tabs.map((tab: Tab, idx: number) => { | ||
return ( | ||
<a | ||
role="tab" | ||
key={idx} | ||
className={`tab ${ | ||
tabValue === tab.name ? "bg-primary text-white" : "" | ||
}`} | ||
onClick={() => setTabValue(tab.name)} | ||
> | ||
{tab.title} | ||
</a> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
</section> | ||
); | ||
}; |
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
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 |
---|---|---|
|
@@ -11,4 +11,5 @@ export interface Gpts { | |
updated_at: string; | ||
detail?: any; | ||
visit_url?: string; | ||
rating?: number; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface Tab { | ||
name: string; | ||
title: string; | ||
icon?: JSX.Element; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export function respData(data: any) { | ||
return respJson(0, "ok", data); | ||
} | ||
|
||
export function respOk() { | ||
return respJson(0, "ok"); | ||
} | ||
|
||
export function respErr(message: string) { | ||
return respJson(-1, message); | ||
} | ||
|
||
export function respJson(code: number, message: string, data?: any) { | ||
let json = { | ||
code: code, | ||
message: message, | ||
data: data, | ||
}; | ||
if (data) { | ||
json["data"] = data; | ||
} | ||
|
||
return Response.json(json); | ||
} |
File renamed without changes.
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
Oops, something went wrong.