diff options
| author | Factiven <[email protected]> | 2023-09-13 00:45:53 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-13 00:45:53 +0700 |
| commit | 7327a69b55a20b99b14ee0803d6cf5f8b88c45ef (patch) | |
| tree | cbcca777593a8cc4b0282e7d85a6fc51ba517e25 /pages/api/v2/source | |
| parent | Update issue templates (diff) | |
| download | moopa-7327a69b55a20b99b14ee0803d6cf5f8b88c45ef.tar.xz moopa-7327a69b55a20b99b14ee0803d6cf5f8b88c45ef.zip | |
Update v4 - Merge pre-push to main (#71)
* Create build-test.yml
* initial v4 commit
* update: github workflow
* update: push on branch
* Update .github/ISSUE_TEMPLATE/bug_report.md
* configuring next.config.js file
Diffstat (limited to 'pages/api/v2/source')
| -rw-r--r-- | pages/api/v2/source/index.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pages/api/v2/source/index.js b/pages/api/v2/source/index.js new file mode 100644 index 0000000..51ac5ec --- /dev/null +++ b/pages/api/v2/source/index.js @@ -0,0 +1,47 @@ +import axios from "axios"; + +const CONSUMET_URI = process.env.API_URI; +const API_KEY = process.env.API_KEY; + +async function consumetSource(id) { + try { + const { data } = await axios.get( + `${CONSUMET_URI}/meta/anilist/watch/${id}` + ); + return data; + } catch (error) { + console.error(error); + return null; + } +} + +async function anifySource(providerId, watchId, episode, id, sub) { + try { + const { data } = await axios.get( + `https://api.anify.tv/sources?providerId=${providerId}&watchId=${encodeURIComponent( + watchId + )}&episode=${episode}&id=${id}&subType=${sub}&apikey=${API_KEY}` + ); + return data; + } catch (error) { + return null; + } +} + +export default async function handler(req, res) { + if (req.method !== "POST") { + return res.status(405).json({ message: "Method not allowed" }); + } + + const { source, providerId, watchId, episode, id, sub = "sub" } = req.body; + + if (source === "anify") { + const data = await anifySource(providerId, watchId, episode, id, sub); + return res.status(200).json(data); + } + + if (source === "consumet") { + const data = await consumetSource(watchId); + return res.status(200).json(data); + } +} |