Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 029d73c

Browse files
committed
2.0-beta.2
1 parent eadb1de commit 029d73c

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

index.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
1-
const express = require('express');
1+
import {isExistRepo} from "./utils";
2+
23
const logger = (require("log4js")).getLogger("Backend");
34
const stats = require('./stats');
45
const conf = require('./config');
5-
const app = express();
6+
const utils = require('./utils');
7+
const app = require('express')();
68

79
logger.level = "debug";
810
app.set('views',__dirname + '/views');
911
app.set("view engine","ejs");
1012

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) {
1714
res.render('index');
1815
})
1916

20-
app.get('/user/:user/', async function (req, res) {
17+
app.get('/user/:user/', async function (req: any, res: any) {
2118
res.type('svg');
2219

2320
try {
2421
const username = req.params['user'];
25-
if (notAccess(username)) throw new Error();
22+
if (await utils.isAuthenticated(username)) throw new Error();
2623
res.render('user', await stats.getAccount(username, req.query['theme'] === 'dark'));
2724
} catch (e) {
2825
res.render('error', {dark: req.query['theme'] === 'dark'});
2926
}
3027
});
3128

32-
app.get('/repo/:user/:repo/', async function (req, res) {
29+
app.get('/repo/:user/:repo/', async function (req: any, res: any) {
3330
res.type('svg');
3431
try {
3532
const username = req.params['user'], repo = req.params['repo'];
3633

37-
if (notAccess(username) || (!repo.length)) throw new Error();
34+
if (await isExistRepo(username, repo)) throw new Error();
3835
res.render('repo', await stats.getRepository(username, repo, req.query['theme'] === 'dark'))
3936
} catch (e) {
4037
res.render('error', {dark: req.query['theme'] === 'dark'});

utils.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ export async function request(url: string): Promise<any> {
4848
return response.data;
4949
}
5050

51-
export async function requestUser(user): Promise<any> {
51+
export async function requestUser(user: string): Promise<any> {
5252
return await request(`/users/${user}`);
5353
}
5454

55-
export async function listRepos(user): Promise<object> {
56-
return Object.values(await request(`/users/${user}/repos`)).filter(repo => !repo['fork']);
55+
export async function listRepos(user: string): Promise<object> {
56+
return Object.values(await request(`/users/${user}/repos`)).filter((repo: object): boolean => !repo['fork']);
5757
}
5858

59-
export async function requestRepo(user, repo): Promise<any> {
59+
export async function requestRepo(user: string, repo: string): Promise<any> {
6060
return await request(`/repos/${user}/${repo}`);
6161
}
6262

63-
export async function requestLanguage(user, repo): Promise<any> {
63+
export async function requestLanguage(user: string, repo: string): Promise<any> {
6464
return await request(`/repos/${user}/${repo}/languages`);
6565
}
6666

67-
export function getLicense(license: object | undefined | null): string {
67+
export function getLicense(license: any): string {
6868
return license ? license['spdx_id'] : "Empty";
6969
}
7070

71-
async function _isAuthenticated(user): Promise<boolean> {
71+
async function _isAuthenticated(user: string): Promise<boolean> {
7272
user = user.trim();
7373
try {
7474
return (!!user.length) &&
@@ -80,10 +80,11 @@ async function _isAuthenticated(user): Promise<boolean> {
8080
}
8181
export const isAuthenticated = cache.wrap(_isAuthenticated);
8282

83-
async function _isExistRepo(user, repo): Promise<boolean> {
83+
async function _isExistRepo(user: string, repo: string): Promise<boolean> {
8484
user = user.trim(); repo = repo.trim();
8585
try {
86-
return await isAuthenticated(user) &&
86+
return (await isAuthenticated(user)) &&
87+
(!!repo.length) &&
8788
((await requestRepo(user, repo))['message'] !== "Not Found");
8889
} catch {
8990
return false;

0 commit comments

Comments
 (0)