From 99fa6769593368c460c55c883bac1e03058e82f1 Mon Sep 17 00:00:00 2001 From: Natsu Date: Mon, 17 Jun 2024 17:16:01 +0700 Subject: [PATCH] chore: Update .gitignore and add get-latest-commit API endpoint --- .gitignore | 1 + api/.gitignore | 2 -- api/get-latest-commit/main.js | 19 ------------------- api/get-latest-commit/package.json | 7 ------- api/getLatestCommit.js | 26 ++++++++++++++++++++++++++ 5 files changed, 27 insertions(+), 28 deletions(-) delete mode 100644 api/.gitignore delete mode 100644 api/get-latest-commit/main.js delete mode 100644 api/get-latest-commit/package.json create mode 100644 api/getLatestCommit.js diff --git a/.gitignore b/.gitignore index 9b4acfc..77d2714 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.gradle /.idea +/.vercel /app/.cxx /app/build /app/debug diff --git a/api/.gitignore b/api/.gitignore deleted file mode 100644 index d5f19d8..0000000 --- a/api/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -package-lock.json diff --git a/api/get-latest-commit/main.js b/api/get-latest-commit/main.js deleted file mode 100644 index 2de3712..0000000 --- a/api/get-latest-commit/main.js +++ /dev/null @@ -1,19 +0,0 @@ -const fetch = require('node-fetch'); - -module.exports = async (req, res) => { - const username = 'NatsumeLS'; - const repo = 'Gakumas-Localify-EN'; - const apiUrl = `https://api.github.com/repos/${username}/${repo}/commits?per_page=1`; - - try { - const response = await fetch(apiUrl); - const data = await response.json(); - const latestCommitHash = data[0].sha; - - res.setHeader('Content-Type', 'application/json'); - res.setHeader('Cache-Control', 'no-cache'); - res.status(200).json({ hash: latestCommitHash }); - } catch (error) { - res.status(500).json({ error: 'Failed to fetch latest commit hash' }); - } -}; diff --git a/api/get-latest-commit/package.json b/api/get-latest-commit/package.json deleted file mode 100644 index b69fbba..0000000 --- a/api/get-latest-commit/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "get-latest-commit", - "main": "main.js", - "dependencies": { - "node-fetch": "^3.3.2" - } -} diff --git a/api/getLatestCommit.js b/api/getLatestCommit.js new file mode 100644 index 0000000..d5b5b0f --- /dev/null +++ b/api/getLatestCommit.js @@ -0,0 +1,26 @@ +// api/getLatestCommit.js + +const fetch = require('node-fetch'); + +module.exports = async (req, res) => { + const username = 'NatsumeLS'; + const repo = 'Gakumas-Localify-EN'; + + try { + const response = await fetch(`https://api.github.com/repos/${username}/${repo}/commits`); + if (!response.ok) { + throw new Error(`GitHub API returned status ${response.status}`); + } + + const commits = await response.json(); + if (commits.length === 0) { + res.status(404).json({ error: 'No commits found' }); + return; + } + + const latestCommit = commits[0].sha; + res.status(200).json({ latestCommit }); + } catch (error) { + res.status(500).json({ error: error.message }); + } +};