-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (45 loc) · 1.67 KB
/
app.js
File metadata and controls
56 lines (45 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const express = require('express');
const path = require('path');
const axios = require('axios');
const app = express();
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, 'public')));
async function countFilesInRepository(owner, repo, path) {
const apiUrl = `https://api.github.com/repos/${owner}/${repo}/contents/${path}`;
try {
const response = await axios.get(apiUrl);
return response.data.length;
} catch (err) {
console.error('Error fetching repository contents:', err);
throw err;
}
}
async function countFilesAnime(ownerA, repoA, pathA) {
const apiUrl = `https://api.github.com/repos/${ownerA}/${repoA}/contents/${pathA}`;
try {
const response = await axios.get(apiUrl);
return response.data.length;
} catch (err) {
console.error('Error fetching repository contents:', err);
throw err;
}
}
app.get('/', async (req, res) => {
const owner = 'Sstudios-Dev';
const repo = 'image-core';
const path = 'src/img';
const ownerA = 'Sstudios-Dev';
const repoA = 'image-core';
const pathA = 'src/img-anime';
try {
const totalFiles = await countFilesInRepository(owner, repo, path);
const totalFilesAnime = await countFilesAnime(ownerA, repoA, pathA);
res.render('index', { totalFiles, totalFilesAnime });
} catch (err) {
console.error('Error counting files in repository:', err);
res.status(500).send('Error counting files');
}
});
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}`));