Typescript v5 + eslint 8.57 WIP
This commit also improves some type handling in the project.
This commit is contained in:
@ -65,8 +65,8 @@ export class LivechatProsodyAuth {
|
||||
private readonly _prosodyDomain: string
|
||||
private _userTokensEnabled: boolean
|
||||
private readonly _tokensPath: string
|
||||
private readonly _passwords: Map<string, Password> = new Map()
|
||||
private readonly _tokensInfoByJID: Map<string, LivechatTokenInfos | undefined> = new Map()
|
||||
private readonly _passwords = new Map<string, Password>()
|
||||
private readonly _tokensInfoByJID = new Map<string, LivechatTokenInfos | undefined>()
|
||||
private readonly _secretKey: string
|
||||
protected readonly _logger: {
|
||||
debug: (s: string) => void
|
||||
@ -122,8 +122,8 @@ export class LivechatProsodyAuth {
|
||||
const nickname: string | undefined = await getUserNickname(this._options, user)
|
||||
return {
|
||||
jid: normalizedUsername + '@' + this._prosodyDomain,
|
||||
password: password,
|
||||
nickname: nickname,
|
||||
password,
|
||||
nickname,
|
||||
type: 'peertube'
|
||||
}
|
||||
}
|
||||
@ -136,7 +136,7 @@ export class LivechatProsodyAuth {
|
||||
if (this._userTokensEnabled) {
|
||||
try {
|
||||
const tokensInfo = await this._getTokensInfoForJID(normalizedUsername + '@' + this._prosodyDomain)
|
||||
if (!tokensInfo || !tokensInfo.tokens.length) {
|
||||
if (!tokensInfo?.tokens.length) {
|
||||
return false
|
||||
}
|
||||
// Checking that the user is valid:
|
||||
@ -159,7 +159,7 @@ export class LivechatProsodyAuth {
|
||||
if (this._userTokensEnabled) {
|
||||
try {
|
||||
const tokensInfo = await this._getTokensInfoForJID(normalizedUsername + '@' + this._prosodyDomain)
|
||||
if (!tokensInfo || !tokensInfo.tokens.length) {
|
||||
if (!tokensInfo?.tokens.length) {
|
||||
return false
|
||||
}
|
||||
// Checking that the user is valid:
|
||||
@ -247,7 +247,7 @@ export class LivechatProsodyAuth {
|
||||
}
|
||||
const nickname: string | undefined = await getUserNickname(this._options, user)
|
||||
const jid = normalizedUsername + '@' + this._prosodyDomain
|
||||
const token = await this._createToken(user.id, jid, label)
|
||||
const token = await this._createToken(user.id as number, jid, label)
|
||||
|
||||
token.nickname = nickname
|
||||
return token
|
||||
@ -279,7 +279,7 @@ export class LivechatProsodyAuth {
|
||||
return false
|
||||
}
|
||||
|
||||
await this._saveTokens(user.id, jid, tokensInfo.tokens.filter(t => t.id !== id))
|
||||
await this._saveTokens(user.id as number, jid, tokensInfo.tokens.filter(t => t.id !== id))
|
||||
return true
|
||||
}
|
||||
|
||||
@ -293,8 +293,8 @@ export class LivechatProsodyAuth {
|
||||
|
||||
const password = generatePassword(20)
|
||||
this._passwords.set(normalizedUsername, {
|
||||
password: password,
|
||||
validity: validity
|
||||
password,
|
||||
validity
|
||||
})
|
||||
return password
|
||||
}
|
||||
@ -330,7 +330,7 @@ export class LivechatProsodyAuth {
|
||||
const user = await this._options.peertubeHelpers.user.loadById(userId)
|
||||
if (!user || user.blocked) { return false }
|
||||
return true
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -381,7 +381,7 @@ export class LivechatProsodyAuth {
|
||||
this._tokensInfoByJID.set(jid, undefined)
|
||||
return undefined
|
||||
}
|
||||
throw err
|
||||
throw err as Error
|
||||
}
|
||||
}
|
||||
|
||||
@ -456,7 +456,7 @@ export class LivechatProsodyAuth {
|
||||
const decipher = createDecipheriv(algorithm, this._secretKey, iv)
|
||||
|
||||
// FIXME: dismiss the "as any" below (dont understand why Typescript is not happy without)
|
||||
return decipher.update(encrypted as any, outputEncoding, inputEncoding) + decipher.final(inputEncoding)
|
||||
return decipher.update(encrypted.toString(), outputEncoding, inputEncoding) + decipher.final(inputEncoding)
|
||||
}
|
||||
|
||||
public static singleton (): LivechatProsodyAuth {
|
||||
|
@ -39,7 +39,7 @@ function startProsodyCertificatesRenewCheck (options: RegisterServerOptions, con
|
||||
}, checkInterval)
|
||||
|
||||
renew = {
|
||||
timer: timer
|
||||
timer
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
|
||||
}
|
||||
|
||||
return {
|
||||
dir: dir,
|
||||
dir,
|
||||
pid: path.resolve(dir, 'prosody.pid'),
|
||||
error: path.resolve(dir, 'prosody.err'),
|
||||
log: path.resolve(dir, 'prosody.log'),
|
||||
@ -217,7 +217,7 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
|
||||
? settings['chat-terms']
|
||||
: undefined
|
||||
|
||||
let useExternal: boolean = false
|
||||
let useExternal = false
|
||||
try {
|
||||
const oidcs = ExternalAuthOIDC.allSingletons()
|
||||
for (const oidc of oidcs) {
|
||||
@ -377,7 +377,7 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
|
||||
config.useBotsVirtualHost(paths.botAvatars, paths.botAvatarsFiles)
|
||||
bots.moderation = await BotConfiguration.singleton().getModerationBotGlobalConf()
|
||||
if (bots.moderation?.connection?.password && typeof bots.moderation.connection.password === 'string') {
|
||||
valuesToHideInDiagnostic.set('BotPassword', bots.moderation.connection.password)
|
||||
valuesToHideInDiagnostic.set('BotPassword', bots.moderation.connection.password as string)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import { getProsodyDomain } from './domain'
|
||||
import { getUserNameByChannelId } from '../../database/channel'
|
||||
import { BotConfiguration } from '../../configuration/bot'
|
||||
|
||||
interface Affiliations { [jid: string]: 'outcast' | 'none' | 'member' | 'admin' | 'owner' }
|
||||
type Affiliations = Record<string, 'outcast' | 'none' | 'member' | 'admin' | 'owner'>
|
||||
|
||||
async function _getCommonAffiliations (options: RegisterServerOptions, _prosodyDomain: string): Promise<Affiliations> {
|
||||
const r: Affiliations = {}
|
||||
|
@ -97,7 +97,7 @@ abstract class ProsodyConfigBlock {
|
||||
if (!this.entries.has(name)) {
|
||||
this.entries.set(name, [])
|
||||
}
|
||||
let entry = this.entries.get(name) as ConfigEntryValue
|
||||
let entry = this.entries.get(name) ?? []
|
||||
if (!Array.isArray(entry)) {
|
||||
entry = [entry]
|
||||
}
|
||||
@ -112,7 +112,7 @@ abstract class ProsodyConfigBlock {
|
||||
if (!this.entries.has(name)) {
|
||||
return
|
||||
}
|
||||
let entry = this.entries.get(name) as ConfigEntryValue
|
||||
let entry = this.entries.get(name) ?? []
|
||||
if (!Array.isArray(entry)) {
|
||||
entry = [entry]
|
||||
}
|
||||
|
@ -139,9 +139,9 @@ async function prosodyCtl (
|
||||
reject(new Error('Missing prosodyctl command executable'))
|
||||
return
|
||||
}
|
||||
let d: string = ''
|
||||
let e: string = ''
|
||||
let m: string = ''
|
||||
let d = ''
|
||||
let e = ''
|
||||
let m = ''
|
||||
const cmdArgs = [
|
||||
...filePaths.execCtlArgs,
|
||||
'--config',
|
||||
@ -196,7 +196,7 @@ async function prosodyCtl (
|
||||
// (else it can cause trouble by cleaning AppImage extract too soon)
|
||||
spawned.on('close', (code) => {
|
||||
resolve({
|
||||
code: code,
|
||||
code,
|
||||
stdout: d,
|
||||
sterr: e,
|
||||
message: m
|
||||
@ -399,8 +399,8 @@ async function ensureProsodyRunning (
|
||||
})
|
||||
}
|
||||
logger.info('Waiting for the prosody process to launch')
|
||||
let count: number = 0
|
||||
let processStarted: boolean = false
|
||||
let count = 0
|
||||
let processStarted = false
|
||||
while (!processStarted && count < 5) {
|
||||
count++
|
||||
await sleep(500)
|
||||
@ -418,8 +418,8 @@ async function ensureProsodyRunning (
|
||||
return
|
||||
}
|
||||
logger.info('Prosody is running')
|
||||
await startProsodyLogRotate(options, filePaths)
|
||||
await startProsodyCertificatesRenewCheck(options, config)
|
||||
startProsodyLogRotate(options, filePaths)
|
||||
startProsodyCertificatesRenewCheck(options, config)
|
||||
}
|
||||
|
||||
async function ensureProsodyNotRunning (options: RegisterServerOptions): Promise<void> {
|
||||
|
@ -10,7 +10,7 @@ import { reloadProsody } from './ctl'
|
||||
type Rotate = (file: string, options: {
|
||||
count?: number
|
||||
compress?: boolean
|
||||
}, cb: Function) => void
|
||||
}, cb: (err: any) => void) => void
|
||||
const rotate: Rotate = require('log-rotate')
|
||||
|
||||
interface ProsodyLogRotate {
|
||||
@ -27,9 +27,10 @@ async function _rotate (options: RegisterServerOptions, path: string): Promise<v
|
||||
rotate(path, { count: 14, compress: false }, (err: any) => {
|
||||
if (err) {
|
||||
options.peertubeHelpers.logger.error('Failed to rotate file ' + path, err)
|
||||
return resolve()
|
||||
resolve()
|
||||
return
|
||||
}
|
||||
return resolve()
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
return p
|
||||
@ -79,7 +80,7 @@ function startProsodyLogRotate (options: RegisterServerOptions, paths: ProsodyFi
|
||||
}, checkInterval)
|
||||
|
||||
logRotate = {
|
||||
timer: timer,
|
||||
timer,
|
||||
lastRotation: Date.now()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user