|
1 | | -const express = require('express'); |
| 1 | +import {isExistRepo} from "./utils"; |
| 2 | + |
2 | 3 | const logger = (require("log4js")).getLogger("Backend"); |
3 | 4 | const stats = require('./stats'); |
4 | 5 | const conf = require('./config'); |
5 | | -const app = express(); |
| 6 | +const utils = require('./utils'); |
| 7 | +const app = require('express')(); |
6 | 8 |
|
7 | 9 | logger.level = "debug"; |
8 | 10 | app.set('views',__dirname + '/views'); |
9 | 11 | app.set("view engine","ejs"); |
10 | 12 |
|
11 | | - |
12 | | -const notAccess = (username) => { |
13 | | - return ( ! username ) || (! ( conf.requires.includes("*") || conf.requires.includes(username))); |
14 | | -} |
15 | | - |
16 | | -app.get('/', function(req, res) { |
| 13 | +app.get('/', function(req: any, res: any) { |
17 | 14 | res.render('index'); |
18 | 15 | }) |
19 | 16 |
|
20 | | -app.get('/user/:user/', async function (req, res) { |
| 17 | +app.get('/user/:user/', async function (req: any, res: any) { |
21 | 18 | res.type('svg'); |
22 | 19 |
|
23 | 20 | try { |
24 | 21 | const username = req.params['user']; |
25 | | - if (notAccess(username)) throw new Error(); |
| 22 | + if (await utils.isAuthenticated(username)) throw new Error(); |
26 | 23 | res.render('user', await stats.getAccount(username, req.query['theme'] === 'dark')); |
27 | 24 | } catch (e) { |
28 | 25 | res.render('error', {dark: req.query['theme'] === 'dark'}); |
29 | 26 | } |
30 | 27 | }); |
31 | 28 |
|
32 | | -app.get('/repo/:user/:repo/', async function (req, res) { |
| 29 | +app.get('/repo/:user/:repo/', async function (req: any, res: any) { |
33 | 30 | res.type('svg'); |
34 | 31 | try { |
35 | 32 | const username = req.params['user'], repo = req.params['repo']; |
36 | 33 |
|
37 | | - if (notAccess(username) || (!repo.length)) throw new Error(); |
| 34 | + if (await isExistRepo(username, repo)) throw new Error(); |
38 | 35 | res.render('repo', await stats.getRepository(username, repo, req.query['theme'] === 'dark')) |
39 | 36 | } catch (e) { |
40 | 37 | res.render('error', {dark: req.query['theme'] === 'dark'}); |
|
0 commit comments