Merged type fixes

This commit is contained in:
mrfry 2022-03-22 11:23:17 +01:00
commit 85b5acc692
22 changed files with 583 additions and 150 deletions

View file

@ -1,3 +1,23 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
const DbStruct = {
msgs: {
tableStruct: {

View file

@ -1,3 +1,23 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
import { Server as socket, Socket } from 'socket.io'
import utils from '../../../utils/utils'
@ -179,15 +199,8 @@ function setup(data: SubmoduleData): void {
})
app.get('/hasNewMsg', (req: Request, res) => {
let userid: any = req.query.userid
if (!userid || isNaN(userid)) {
res.json({
success: false,
msg: 'Query "userid" (number) is required!',
})
return
}
userid = parseInt(userid)
const user: User = req.session.user
const userid: number = user.id
const groups = dbtools
.runStatement(

View file

@ -1,3 +1,23 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
import { Response } from 'express'
import logger from '../../../utils/logger'

View file

@ -1,3 +1,23 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
import { v4 as uuidv4 } from 'uuid'
import logger from '../../../utils/logger'
@ -175,7 +195,7 @@ function setup(data: SubmoduleData): void {
app.get('/forumEntries', (req: Request, res) => {
logger.LogReq(req)
const forumName: any = req.query.forumName
const forumName: string = req.query.forumName
if (!forumName) {
res.json({
success: false,
@ -251,7 +271,7 @@ function setup(data: SubmoduleData): void {
forumDir
)
const user: User = req.session.user
const admins: any = utils.FileExists(adminUsersFile)
const admins: string[] = utils.FileExists(adminUsersFile)
? utils.ReadJSON(adminUsersFile)
: []
@ -260,7 +280,7 @@ function setup(data: SubmoduleData): void {
date: utils.GetDateString(),
user: user.id,
title: title,
admin: admins.includes(user.id),
admin: admins.includes(user.id.toString()),
commentCount: 0,
}
@ -290,7 +310,7 @@ function setup(data: SubmoduleData): void {
) => {
logger.LogReq(req)
const { postKey } = req.body
const forumName: any = req.body.forumName
const forumName = req.body.forumName
if (!forumName) {
res.json({
success: false,
@ -334,7 +354,7 @@ function setup(data: SubmoduleData): void {
) => {
logger.LogReq(req)
const forumName: any = req.body.forumName
const forumName = req.body.forumName
if (!forumName) {
res.json({
success: false,
@ -347,7 +367,7 @@ function setup(data: SubmoduleData): void {
forumDir
)
const user: User = req.session.user
const admins: any = utils.FileExists(adminUsersFile)
const admins: string[] = utils.FileExists(adminUsersFile)
? utils.ReadJSON(adminUsersFile)
: []
const { type, path, postKey } = req.body
@ -373,7 +393,7 @@ function setup(data: SubmoduleData): void {
date: utils.GetDateString(),
user: user.id,
content: content,
admin: admins.includes(user.id),
admin: admins.includes(user.id.toString()),
}
if (!postData.comments) {
postData.comments = []
@ -418,7 +438,7 @@ function setup(data: SubmoduleData): void {
) => {
logger.LogReq(req)
const forumName: any = req.body.forumName
const forumName = req.body.forumName
if (!forumName) {
res.json({
success: false,

View file

@ -1,3 +1,23 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
import fs from 'fs'
import { Response } from 'express'
import { fork, ChildProcess } from 'child_process'
@ -137,7 +157,7 @@ function getDetailedRes(questionDbs: QuestionDb[]) {
})
}
function getMotd(version: any, motd: string) {
function getMotd(version: string, motd: string) {
if (version) {
if (version.startsWith('2.0.')) {
if (utils.FileExists(oldMotdFile)) {
@ -485,7 +505,7 @@ function setup(data: SubmoduleData): Submodule {
app.get('/allqr.txt', function (req: Request, res: Response) {
logger.LogReq(req)
const db: any = req.query.db
const db: string = req.query.db
let stringifiedData = ''
res.setHeader('content-type', 'text/plain; charset=utf-8')
@ -728,7 +748,7 @@ function setup(data: SubmoduleData): Submodule {
utils.WriteFile('[]', registeredScriptsFile)
}
const ua: any = req.headers['user-agent']
const ua: string = req.headers['user-agent']
const registeredScripts: RegisteredUserEntry[] = utils.ReadJSON(
registeredScriptsFile
)
@ -739,7 +759,7 @@ function setup(data: SubmoduleData): Submodule {
})
if (index === -1) {
const x: any = {
const x: RegisteredUserEntry = {
cid: cid,
version: version,
installSource: installSource,
@ -975,7 +995,7 @@ function setup(data: SubmoduleData): Submodule {
// TODO: get status of it cleaning
logger.LogReq(req)
const user: User = req.session.user
const status: any = req.query.status
const status: string = req.query.status
if (status) {
if (!questionCleaner) {

View file

@ -1,6 +1,27 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
import logger from '../../../utils/logger'
import utils from '../../../utils/utils'
import { Request, SubmoduleData, User } from '../../../types/basicTypes'
import type { Request, SubmoduleData, User } from '../../../types/basicTypes'
import type { Response } from 'express'
const quickVoteResultsDir = 'stats/qvote'
const quickVotes = 'stats/qvote/votes.json'
@ -20,9 +41,9 @@ interface QuickVote {
function setup(data: SubmoduleData): void {
const { app /* userDB, url, publicdirs, moduleSpecificData */ } = data
app.get('/quickvote', (req: Request, res: any) => {
app.get('/quickvote', (req: Request, res: Response) => {
const key = req.query.key.toString()
const val: any = req.query.val
const val: string = req.query.val
const user: User = req.session.user
if (!key || !val) {

View file

@ -1,3 +1,23 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
import logger from '../../../utils/logger'
import utils from '../../../utils/utils'
import { Request, SubmoduleData, User } from '../../../types/basicTypes'
@ -40,10 +60,10 @@ function mergeObjSum(a: Subjects, b: Subjects) {
function setup(data: SubmoduleData): void {
const { app /* userDB, url, publicdirs, moduleSpecificData */ } = data
app.get('/ranklist', (req: Request, res: any) => {
app.get('/ranklist', (req: Request, res) => {
logger.LogReq(req)
let result: IdStats
const querySince: any = req.query.since
const querySince: string = req.query.since
const user: User = req.session.user
if (!querySince) {

View file

@ -1,3 +1,23 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
import { Response } from 'express'
import logger from '../../../utils/logger'
@ -59,7 +79,7 @@ function setup(data: SubmoduleData): void {
app.get('/voteTodo', (req: Request, res: Response) => {
logger.LogReq(req)
const userId = req.session.user.id
const id: any = req.query.id
const id: string = req.query.id
const todos: Todos = utils.ReadJSON(todosFile)
if (!id) {

View file

@ -1,3 +1,23 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
import fs from 'fs'
import logger from '../../../utils/logger'
@ -112,7 +132,7 @@ function setup(data: SubmoduleData): void {
utils.CreatePath(userFilesDir, true)
}
const subdir: any = req.query.subdir
const subdir: string = req.query.subdir
if (subdir) {
const result = listDir(publicDir, subdir, userFilesDir)
@ -138,43 +158,46 @@ function setup(data: SubmoduleData): void {
}
})
app.post('/deleteUserFile', (req: Request, res) => {
logger.LogReq(req)
const dir: any = req.body.dir
const fname: any = req.body.fname
if (!dir || !fname) {
app.post(
'/deleteUserFile',
(req: Request<{ dir: string; fname: string }>, res) => {
logger.LogReq(req)
const dir: string = req.body.dir
const fname: string = req.body.fname
if (!dir || !fname) {
res.json({
success: false,
msg: `'dir' or 'fname' is undefined!`,
})
return
}
const safeDir = dir.replace(/\.+/g, '').replace(/\/+/g, '')
const safeFname = fname.replace(/\.+/g, '.').replace(/\/+/g, '')
const filePath = userFilesDir + '/' + safeDir + '/' + safeFname
if (!utils.FileExists(filePath)) {
res.json({
success: false,
msg: `path does not exists!`,
})
return
}
utils.deleteFile(filePath)
const usersFile = userFilesDir + '/' + safeDir + '/' + dataFileName
const users = utils.ReadJSON(usersFile)
delete users[safeFname]
utils.WriteFile(JSON.stringify(users), usersFile)
res.json({
success: false,
msg: `'dir' or 'fname' is undefined!`,
success: true,
})
return
}
const safeDir = dir.replace(/\.+/g, '').replace(/\/+/g, '')
const safeFname = fname.replace(/\.+/g, '.').replace(/\/+/g, '')
const filePath = userFilesDir + '/' + safeDir + '/' + safeFname
)
if (!utils.FileExists(filePath)) {
res.json({
success: false,
msg: `path does not exists!`,
})
return
}
utils.deleteFile(filePath)
const usersFile = userFilesDir + '/' + safeDir + '/' + dataFileName
const users = utils.ReadJSON(usersFile)
delete users[safeFname]
utils.WriteFile(JSON.stringify(users), usersFile)
res.json({
success: true,
})
})
app.post('/newUserDir', (req: Request, res) => {
app.post('/newUserDir', (req: Request<{ name: string }>, res) => {
logger.LogReq(req)
const name: any = req.body.name
const name: string = req.body.name
if (!name) {
res.json({
success: false,
@ -198,7 +221,7 @@ function setup(data: SubmoduleData): void {
})
})
app.post('/uploadUserFile', (req: Request, res) => {
app.post('/uploadUserFile', (req: Request<{ dir: string }>, res) => {
logger.LogReq(req)
const user: User = req.session.user
@ -241,7 +264,7 @@ function setup(data: SubmoduleData): void {
})
})
app.post('/voteFile', (req: Request, res) => {
app.post('/voteFile', (req: Request<{ path: string; to: string }>, res) => {
logger.LogReq(req)
const user: User = req.session.user
// { path: 'userFiles/test/2021-04-28_10-59.png', to: 'up' } 19

View file

@ -1,9 +1,34 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
import { v4 as uuidv4 } from 'uuid'
import type { Database } from 'better-sqlite3'
import logger from '../../../utils/logger'
import utils from '../../../utils/utils'
import { Request, SubmoduleData, User } from '../../../types/basicTypes'
import {
Request,
SubmoduleData,
User,
Submodule,
} from '../../../types/basicTypes'
import dbtools from '../../../utils/dbtools'
const minimumAlowwedSessions = 2 // how many sessions are allowed for a user
@ -38,7 +63,7 @@ function BackupDB(usersDbBackupPath: string, userDB: Database) {
})
}
function setup(data: SubmoduleData): any {
function setup(data: SubmoduleData): Submodule {
const { app, userDB, url /* publicdirs, moduleSpecificData */ } = data
let domain: any = url.split('.') // [ "https://api", "frylabs", "net" ]
domain.shift() // [ "frylabs", "net" ]

View file

@ -1,4 +1,22 @@
export interface Users {}
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
const DBStruct = {
users: {