mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 22:09:16 +01:00
refactor: ♻️ Always use explicit types in every function
This commit is contained in:
parent
54cea29ce9
commit
c1dcdc78ae
62 changed files with 359 additions and 226 deletions
|
|
@ -261,7 +261,7 @@ export const parseTextMentions = async (
|
|||
|
||||
const baseUrlHost = new URL(config.http.base_url).host;
|
||||
|
||||
const isLocal = (host?: string) => host === baseUrlHost || !host;
|
||||
const isLocal = (host?: string): boolean => host === baseUrlHost || !host;
|
||||
|
||||
const foundUsers = await db
|
||||
.select({
|
||||
|
|
@ -326,7 +326,7 @@ export const parseTextMentions = async (
|
|||
return finalList;
|
||||
};
|
||||
|
||||
export const replaceTextMentions = (text: string, mentions: User[]) => {
|
||||
export const replaceTextMentions = (text: string, mentions: User[]): string => {
|
||||
let finalText = text;
|
||||
for (const mention of mentions) {
|
||||
const user = mention.data;
|
||||
|
|
@ -405,7 +405,7 @@ export const contentToHtml = async (
|
|||
htmlContent = linkifyHtml(htmlContent, {
|
||||
defaultProtocol: "https",
|
||||
validate: {
|
||||
email: () => false,
|
||||
email: (): false => false,
|
||||
},
|
||||
target: "_blank",
|
||||
rel: "nofollow noopener noreferrer",
|
||||
|
|
@ -414,11 +414,11 @@ export const contentToHtml = async (
|
|||
return htmlContent;
|
||||
};
|
||||
|
||||
export const markdownParse = async (content: string) => {
|
||||
export const markdownParse = async (content: string): Promise<string> => {
|
||||
return (await getMarkdownRenderer()).render(content);
|
||||
};
|
||||
|
||||
export const getMarkdownRenderer = () => {
|
||||
export const getMarkdownRenderer = (): MarkdownIt => {
|
||||
const renderer = MarkdownIt({
|
||||
html: true,
|
||||
linkify: true,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import {
|
|||
Tokens,
|
||||
type Users,
|
||||
} from "@versia/kit/tables";
|
||||
import { type InferSelectModel, eq, sql } from "drizzle-orm";
|
||||
import { type InferSelectModel, type SQL, eq, sql } from "drizzle-orm";
|
||||
import type { ApplicationType } from "~/classes/database/application.ts";
|
||||
import type { EmojiWithInstance } from "~/classes/database/emoji.ts";
|
||||
import type { Token } from "./token.ts";
|
||||
|
|
@ -80,7 +80,13 @@ export const userExtras = {
|
|||
),
|
||||
};
|
||||
|
||||
export const userExtrasTemplate = (name: string) => ({
|
||||
export const userExtrasTemplate = (
|
||||
name: string,
|
||||
): {
|
||||
followerCount: SQL.Aliased<unknown>;
|
||||
followingCount: SQL.Aliased<unknown>;
|
||||
statusCount: SQL.Aliased<unknown>;
|
||||
} => ({
|
||||
// @ts-expect-error sql is a template tag, so it gets confused when we use it as a function
|
||||
followerCount: sql([
|
||||
`(SELECT COUNT(*) FROM "Relationships" "relationships" WHERE ("relationships"."ownerId" = "${name}".id AND "relationships"."following" = true))`,
|
||||
|
|
@ -214,7 +220,8 @@ export const retrieveToken = async (
|
|||
|
||||
return (
|
||||
(await db.query.Tokens.findFirst({
|
||||
where: (tokens, { eq }) => eq(tokens.accessToken, accessToken),
|
||||
where: (tokens, { eq }): SQL | undefined =>
|
||||
eq(tokens.accessToken, accessToken),
|
||||
})) ?? null
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue