From b6c45a9049cce8ba8dcd43bb3d5a4f8379af3b4a Mon Sep 17 00:00:00 2001 From: Guus van Meerveld Date: Wed, 13 Mar 2024 11:49:29 +0100 Subject: [PATCH] basic client that can fetch trending page --- bruno/Invidious/Trending.bru | 11 +++++ bruno/Piped/Trending.bru | 15 ++++++ bruno/bruno.json | 5 ++ package.json | 4 +- src/app/(trending)/Video.tsx | 19 +++++++ src/app/{ => (trending)}/page.tsx | 3 +- src/app/layout.tsx | 17 ++++--- src/client/adapters/index.ts | 16 ++++++ src/client/adapters/invidious/index.ts | 47 ++++++++++++++++++ src/client/adapters/invidious/transformer.ts | 23 +++++++++ .../adapters/invidious/typings/thumbnail.ts | 12 +++++ .../adapters/invidious/typings/trending.ts | 28 +++++++++++ src/client/adapters/piped/index.ts | 38 ++++++++++++++ src/client/adapters/piped/transformer.ts | 35 +++++++++++++ src/client/adapters/piped/typings/trending.ts | 19 +++++++ src/client/index.ts | 49 +++++++++++++++++++ src/client/typings/thumbnail.ts | 3 ++ src/client/typings/trending.ts | 17 +++++++ src/typings/component.ts | 3 ++ yarn.lock | 10 ++++ 20 files changed, 364 insertions(+), 10 deletions(-) create mode 100644 bruno/Invidious/Trending.bru create mode 100644 bruno/Piped/Trending.bru create mode 100644 bruno/bruno.json create mode 100644 src/app/(trending)/Video.tsx rename src/app/{ => (trending)}/page.tsx (69%) create mode 100644 src/client/adapters/index.ts create mode 100644 src/client/adapters/invidious/index.ts create mode 100644 src/client/adapters/invidious/transformer.ts create mode 100644 src/client/adapters/invidious/typings/thumbnail.ts create mode 100644 src/client/adapters/invidious/typings/trending.ts create mode 100644 src/client/adapters/piped/index.ts create mode 100644 src/client/adapters/piped/transformer.ts create mode 100644 src/client/adapters/piped/typings/trending.ts create mode 100644 src/client/index.ts create mode 100644 src/client/typings/thumbnail.ts create mode 100644 src/client/typings/trending.ts create mode 100644 src/typings/component.ts diff --git a/bruno/Invidious/Trending.bru b/bruno/Invidious/Trending.bru new file mode 100644 index 0000000..9e42450 --- /dev/null +++ b/bruno/Invidious/Trending.bru @@ -0,0 +1,11 @@ +meta { + name: Trending + type: http + seq: 1 +} + +get { + url: https://invidious.drgns.space/api/v1/trending + body: none + auth: none +} diff --git a/bruno/Piped/Trending.bru b/bruno/Piped/Trending.bru new file mode 100644 index 0000000..83e7269 --- /dev/null +++ b/bruno/Piped/Trending.bru @@ -0,0 +1,15 @@ +meta { + name: Trending + type: http + seq: 1 +} + +get { + url: https://pipedapi.kavin.rocks/trending?region=NL + body: none + auth: none +} + +query { + region: NL +} diff --git a/bruno/bruno.json b/bruno/bruno.json new file mode 100644 index 0000000..3160fcf --- /dev/null +++ b/bruno/bruno.json @@ -0,0 +1,5 @@ +{ + "version": "1", + "name": "MaterialTube", + "type": "collection" +} \ No newline at end of file diff --git a/package.json b/package.json index 50f633e..3800c69 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,12 @@ "dependencies": { "@nextui-org/react": "^2.2.10", "framer-motion": "^11.0.12", + "ky": "^1.2.2", "next": "14.1.3", "next-pwa": "^5.6.0", "react": "^18", - "react-dom": "^18" + "react-dom": "^18", + "zod": "^3.22.4" }, "devDependencies": { "@types/next-pwa": "^5.6.9", diff --git a/src/app/(trending)/Video.tsx b/src/app/(trending)/Video.tsx new file mode 100644 index 0000000..049892d --- /dev/null +++ b/src/app/(trending)/Video.tsx @@ -0,0 +1,19 @@ +"use client"; + +import Client from "@/client"; +import { ApiType } from "@/client/adapters"; +import { Component } from "@/typings/component"; +import { useEffect } from "react"; + +export const Video: Component = ({}) => { + useEffect(() => { + const client = new Client([ + { baseUrl: "https://invidious.drgns.space", type: ApiType.Invidious }, + { baseUrl: "https://pipedapi.kavin.rocks", type: ApiType.Piped } + ]); + + client.getTrending("US").then(console.log); + }, []); + + return <>; +}; diff --git a/src/app/page.tsx b/src/app/(trending)/page.tsx similarity index 69% rename from src/app/page.tsx rename to src/app/(trending)/page.tsx index e7d4c01..4068cd6 100644 --- a/src/app/page.tsx +++ b/src/app/(trending)/page.tsx @@ -1,9 +1,10 @@ import { Button } from "@nextui-org/button"; +import { Video } from "./Video"; export default function Home() { return ( <> - +