backend: fix lints in various misc modules

Mostly adding return types and also fixing a type error.
This commit is contained in:
Norm 2022-11-16 19:48:16 -05:00
parent 629b865789
commit c0d5678039
Signed by untrusted user: norm
GPG key ID: 7123E30E441E80DE
5 changed files with 9 additions and 7 deletions

View file

@ -29,7 +29,7 @@ export class Cache<T> {
return cached.value; return cached.value;
} }
public delete(key: string | null) { public delete(key: string | null): void {
this.cache.delete(key); this.cache.delete(key);
} }
@ -46,8 +46,9 @@ export class Cache<T> {
const value = await this.fetcher(key); const value = await this.fetcher(key);
// don't cache undefined // don't cache undefined
if (value !== undefined) if (value !== undefined) {
this.set(key, value); this.set(key, value);
}
return value; return value;
} }

View file

@ -3,7 +3,7 @@ import fetch from 'node-fetch';
import config from '@/config/index.js'; import config from '@/config/index.js';
import { getAgentByUrl } from './fetch.js'; import { getAgentByUrl } from './fetch.js';
export async function verifyRecaptcha(secret: string, response: string) { export async function verifyRecaptcha(secret: string, response: string): Promise<void> {
const result = await getCaptchaResponse('https://www.recaptcha.net/recaptcha/api/siteverify', secret, response).catch(e => { const result = await getCaptchaResponse('https://www.recaptcha.net/recaptcha/api/siteverify', secret, response).catch(e => {
throw new Error(`recaptcha-request-failed: ${e.message}`); throw new Error(`recaptcha-request-failed: ${e.message}`);
}); });
@ -14,7 +14,7 @@ export async function verifyRecaptcha(secret: string, response: string) {
} }
} }
export async function verifyHcaptcha(secret: string, response: string) { export async function verifyHcaptcha(secret: string, response: string): Promise<void> {
const result = await getCaptchaResponse('https://hcaptcha.com/siteverify', secret, response).catch(e => { const result = await getCaptchaResponse('https://hcaptcha.com/siteverify', secret, response).catch(e => {
throw new Error(`hcaptcha-request-failed: ${e.message}`); throw new Error(`hcaptcha-request-failed: ${e.message}`);
}); });

View file

@ -5,6 +5,7 @@ import { User } from '@/models/entities/user.js';
type NoteLike = { type NoteLike = {
userId: Note['userId']; userId: Note['userId'];
text: Note['text']; text: Note['text'];
cw: Note['cw'];
}; };
type UserLike = { type UserLike = {

View file

@ -11,12 +11,12 @@ export function isSelfHost(host: string | null): boolean {
return toPuny(config.host) === toPuny(host); return toPuny(config.host) === toPuny(host);
} }
export function extractDbHost(uri: string) { export function extractDbHost(uri: string): string {
const url = new URL(uri); const url = new URL(uri);
return toPuny(url.hostname); return toPuny(url.hostname);
} }
export function toPuny(host: string) { export function toPuny(host: string): string {
return toASCII(host.toLowerCase()); return toASCII(host.toLowerCase());
} }

View file

@ -2,7 +2,7 @@ import { createTemp } from './create-temp.js';
import { downloadUrl } from './download-url.js'; import { downloadUrl } from './download-url.js';
import { detectType } from './get-file-info.js'; import { detectType } from './get-file-info.js';
export async function detectUrlMime(url: string) { export async function detectUrlMime(url: string): Promise<string> {
const [path, cleanup] = await createTemp(); const [path, cleanup] = await createTemp();
try { try {