1
0

chore: Update .gitignore and add get-latest-commit API endpoint

This commit is contained in:
Natsu 2024-06-17 17:16:01 +07:00
parent a5e85b7645
commit 99fa676959
Signed by: NatsumeLS
GPG Key ID: 6DB67FB460CF46C6
5 changed files with 27 additions and 28 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
/.gradle
/.idea
/.vercel
/app/.cxx
/app/build
/app/debug

2
api/.gitignore vendored
View File

@ -1,2 +0,0 @@
node_modules
package-lock.json

View File

@ -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' });
}
};

View File

@ -1,7 +0,0 @@
{
"name": "get-latest-commit",
"main": "main.js",
"dependencies": {
"node-fetch": "^3.3.2"
}
}

26
api/getLatestCommit.js Normal file
View File

@ -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 });
}
};