Skip to content

Commit 13704cc

Browse files
eslint
1 parent 7e83566 commit 13704cc

File tree

5 files changed

+23
-31
lines changed

5 files changed

+23
-31
lines changed

src/lib/authorization.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { connect, dbSelect, dbUpdate } from "../lib/database.js";
1+
import { dbSelect, dbUpdate } from "../lib/database.js";
22
import { logger } from "./logger.js";
33
import { credentialTypes } from "../interfaces/admin.js";
44
import { registeredTableFields } from "../interfaces/database.js";
@@ -23,23 +23,18 @@ const isPubkeyValid = async (req: Request, checkAdminPrivileges :boolean = false
2323
return false;
2424
}
2525

26-
let pubkey = req.body.pubkey || req.session.identifier;
27-
26+
const pubkey = req.body.pubkey || req.session.identifier;
2827
logger.info("Checking if pubkey is allowed ->", pubkey)
2928

30-
const conn = await connect("IsAuthorizedPubkey");
31-
3229
let queryString : string = "SELECT hex FROM registered WHERE hex = ?";
3330
if (checkAdminPrivileges) queryString = "SELECT hex FROM registered WHERE allowed = 1 and hex = ?";
3431
try{
3532

36-
let result = await dbSelect(queryString, "hex", [pubkey], registeredTableFields)
33+
const result = await dbSelect(queryString, "hex", [pubkey], registeredTableFields)
3734
if (result == "") {
3835
return false;
3936
}
40-
4137
if (req.session.identifier) return true;
42-
4338
return await verifyNIP07login(req);
4439

4540
}catch (error) {
@@ -56,7 +51,7 @@ const isPubkeyValid = async (req: Request, checkAdminPrivileges :boolean = false
5651
*/
5752
const isUserPasswordValid = async (username:string, password:string): Promise<boolean> => {
5853
try{
59-
let userDBPassword = await dbSelect("SELECT password FROM registered WHERE username = ?",
54+
const userDBPassword = await dbSelect("SELECT password FROM registered WHERE username = ?",
6055
"password",
6156
[username],
6257
registeredTableFields)
@@ -81,9 +76,9 @@ const checkAuthkey = async (req: Request) : Promise<boolean> =>{
8176
logger.warn("Unauthorized request, no authorization header");
8277
return false
8378
}
84-
let hashedAuthkey = await hashString(req.headers.authorization, 'authkey');
79+
const hashedAuthkey = await hashString(req.headers.authorization, 'authkey');
8580
try{
86-
let hex = await dbSelect("SELECT hex FROM registered WHERE authkey = ? and allowed = ?", "hex", [hashedAuthkey,"1"], registeredTableFields)
81+
const hex = await dbSelect("SELECT hex FROM registered WHERE authkey = ? and allowed = ?", "hex", [hashedAuthkey,"1"], registeredTableFields)
8782
if (hex == ""){
8883
logger.warn("Unauthorized request, authkey not found")
8984
return false;}
@@ -118,7 +113,7 @@ const generateCredentials = async (type: credentialTypes, returnHashed: boolean
118113
try {
119114

120115
const credential = crypto.randomBytes(20).toString('hex');
121-
let hashedCredential = await hashString(credential, type);
116+
const hashedCredential = await hashString(credential, type);
122117
const update = await dbUpdate("registered", type, hashedCredential, "hex", pubkey);
123118
if (update){
124119
logger.debug("New credential generated and saved to database");

src/lib/hash.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const validateHash = async (input:string, hash:string): Promise<boolean> => {
101101
hash = hash.replace(/^\$2y(.+)$/i, '$2a$1'); // PHP old hashes compatibility
102102

103103
try{
104-
let result = await bcrypt.compare(input, hash);
104+
const result = await bcrypt.compare(input, hash);
105105
logger.debug("Hash validation result", result);
106106
return result;
107107
}catch (error) {

src/lib/redis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { LightningUsernameResult } from "../interfaces/lightning.js";
77
//Redis configuration
88
const redisClient = createClient();
99
(async (): Promise<void> => {
10-
redisClient.on("error", (error: any) =>{
10+
redisClient.on("error", (error: Error) =>{
1111
logger.error(`There is a problem connecting to redis server, is redis-server package installed on your system? : ${error}`);
1212
process.exit(1);
1313
});

src/lib/server.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
2-
//General server functions
3-
4-
import config from "config";
51
import { logger } from "./logger.js";
6-
import fs from "fs";
72
import path from 'path';
83
import url from 'url';
94
import markdownit from 'markdown-it';
105
import { Application } from "express";
6+
import { Request } from "express";
117

12-
const getClientIp = (req: any) =>{
8+
const getClientIp = (req: Request) =>{
139

1410
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
15-
if (ip.substr(0, 7) == "::ffff:") {
16-
ip = ip.substr(7)
11+
if (typeof ip === 'string' && ip.startsWith("::ffff:")) {
12+
ip = ip.substring(7);
1713
}
1814
return ip;
1915
};
2016

21-
function format(seconds:number):string{
17+
const format = (seconds:number):string =>{
2218
function pad(s: number){
23-
return (s < 10 ? '0' : '') + s;
19+
return (s < 10 ? '0' : '') + s;
2420
}
25-
var hours = Math.floor(seconds / (60*60));
26-
var minutes = Math.floor(seconds % (60*60) / 60);
27-
var seconds = Math.floor(seconds % 60);
21+
const hours = Math.floor(seconds / (60*60));
22+
const minutes = Math.floor(seconds % (60*60) / 60);
23+
const secs = Math.floor(seconds % 60);
2824

29-
return pad(hours) + ':' + pad(minutes) + ':' + pad(seconds);
30-
}
25+
return pad(hours) + ':' + pad(minutes) + ':' + pad(secs);
26+
}
27+
3128
const currDir = (fileUrl:string) : string =>{
3229
const __filename = url.fileURLToPath(fileUrl);
3330
return path.dirname(__filename);

src/lib/session.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { rateLimit } from 'express-rate-limit'
99

1010
declare module 'express-session' {
1111
interface Session {
12-
identifier: string;
12+
identifier: string;
1313
authkey: string;
14-
}
14+
}
1515
}
1616

1717
const initSession = async (app:Application): Promise<void> => {

0 commit comments

Comments
 (0)