From 1d301d72ae6c6b5f41e26594d1a7f002125d869c Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Wed, 9 Apr 2025 02:15:00 +0200 Subject: [PATCH] fix: :rotating_light: Fix DeepSource linter warnings --- api/api/v1/statuses/[id]/index.ts | 2 +- api/api/v1/statuses/index.ts | 2 +- api/users/[uuid]/index.ts | 2 +- api/well-known/webfinger/index.ts | 14 +++++++------- bun.lock | 10 +++++----- classes/database/user.ts | 9 +++------ classes/functions/status.ts | 8 +++----- classes/inbox/processor.ts | 24 ++++++++++++++---------- packages/sdk/http.ts | 2 +- packages/sdk/regex.ts | 6 +++--- 10 files changed, 39 insertions(+), 40 deletions(-) diff --git a/api/api/v1/statuses/[id]/index.ts b/api/api/v1/statuses/[id]/index.ts index 52d65441..a6fa0873 100644 --- a/api/api/v1/statuses/[id]/index.ts +++ b/api/api/v1/statuses/[id]/index.ts @@ -242,7 +242,7 @@ export default apiRoute((app) => { : undefined; const parsedMentions = statusText - ? await parseTextMentions(statusText, user) + ? await parseTextMentions(statusText) : []; const parsedEmojis = statusText diff --git a/api/api/v1/statuses/index.ts b/api/api/v1/statuses/index.ts index 0c6c0dc5..a65b893f 100644 --- a/api/api/v1/statuses/index.ts +++ b/api/api/v1/statuses/index.ts @@ -192,7 +192,7 @@ export default apiRoute((app) => : undefined; const parsedMentions = status - ? await parseTextMentions(status, user) + ? await parseTextMentions(status) : []; const parsedEmojis = status diff --git a/api/users/[uuid]/index.ts b/api/users/[uuid]/index.ts index a03d9eb4..c4c2ad22 100644 --- a/api/users/[uuid]/index.ts +++ b/api/users/[uuid]/index.ts @@ -43,7 +43,7 @@ export default apiRoute((app) => }), handleZodError, ), - // @ts-expect-error + // @ts-expect-error idk why this is happening and I don't care async (context) => { const { uuid } = context.req.valid("param"); diff --git a/api/well-known/webfinger/index.ts b/api/well-known/webfinger/index.ts index 60da40a4..158164b5 100644 --- a/api/well-known/webfinger/index.ts +++ b/api/well-known/webfinger/index.ts @@ -8,6 +8,7 @@ import { import { getLogger } from "@logtape/logtape"; import { User } from "@versia/kit/db"; import { Users } from "@versia/kit/tables"; +import { FederationRequester } from "@versia/sdk/http"; import { and, eq, isNull } from "drizzle-orm"; import { describeRoute } from "hono-openapi"; import { resolver, validator } from "hono-openapi/zod"; @@ -84,13 +85,12 @@ export default apiRoute((app) => if (config.federation.bridge) { try { - activityPubUrl = - await User.federationRequester.resolveWebFinger( - user.data.username, - config.http.base_url.host, - "application/activity+json", - config.federation.bridge.url.origin, - ); + activityPubUrl = await FederationRequester.resolveWebFinger( + user.data.username, + config.http.base_url.host, + "application/activity+json", + config.federation.bridge.url.origin, + ); } catch (e) { const error = e as ApiError; diff --git a/bun.lock b/bun.lock index 53a168db..6d699e09 100644 --- a/bun.lock +++ b/bun.lock @@ -95,10 +95,6 @@ "@badgateway/oauth2-client": "^2.4.2", }, }, - "packages/federation": { - "name": "@versia/sdk", - "version": "0.0.1", - }, "packages/plugin-kit": { "name": "@versia/kit", "version": "0.0.0", @@ -109,6 +105,10 @@ "zod-validation-error": "^3.3.0", }, }, + "packages/sdk": { + "name": "@versia/sdk", + "version": "0.0.1", + }, }, "trustedDependencies": [ "sharp", @@ -574,7 +574,7 @@ "@versia/kit": ["@versia/kit@workspace:packages/plugin-kit"], - "@versia/sdk": ["@versia/sdk@workspace:packages/federation"], + "@versia/sdk": ["@versia/sdk@workspace:packages/sdk"], "@vitejs/plugin-vue": ["@vitejs/plugin-vue@5.2.3", "", { "peerDependencies": { "vite": "^5.0.0 || ^6.0.0", "vue": "^3.2.25" } }, "sha512-IYSLEQj4LgZZuoVpdSUCw3dIynTWQgPlaRP6iAvMle4My0HdYwr5g5wQAfwOeHQBmYwEkqF70nRpSilr6PoUDg=="], diff --git a/classes/database/user.ts b/classes/database/user.ts index 4458936c..d57f6236 100644 --- a/classes/database/user.ts +++ b/classes/database/user.ts @@ -347,13 +347,10 @@ export class User extends BaseInterface { hostname: string, ): Promise { try { - return User.federationRequester.resolveWebFinger( - username, - hostname, - ); + return FederationRequester.resolveWebFinger(username, hostname); } catch { try { - return User.federationRequester.resolveWebFinger( + return FederationRequester.resolveWebFinger( username, hostname, "application/activity+json", @@ -854,7 +851,7 @@ export class User extends BaseInterface { const user = await User.insert({ id: randomUUIDv7(), - username: username, + username, displayName: username, password: options?.password ? await bunPassword.hash(options.password) diff --git a/classes/functions/status.ts b/classes/functions/status.ts index 3992df86..68827dc5 100644 --- a/classes/functions/status.ts +++ b/classes/functions/status.ts @@ -3,6 +3,7 @@ import { sanitizeHtml, sanitizeHtmlInline } from "@/sanitization"; import markdownItTaskLists from "@hackmd/markdown-it-task-lists"; import { type Note, User, db } from "@versia/kit/db"; import { Instances, Users } from "@versia/kit/tables"; +import { FederationRequester } from "@versia/sdk/http"; import { and, eq, inArray, isNull, or, sql } from "drizzle-orm"; import linkifyHtml from "linkify-html"; import { @@ -222,10 +223,7 @@ export const findManyNotes = async ( * @param text The text to parse mentions from. * @returns An array of users mentioned in the text. */ -export const parseTextMentions = async ( - text: string, - author: User, -): Promise => { +export const parseTextMentions = async (text: string): Promise => { const mentionedPeople = [...text.matchAll(mentionValidator)]; if (mentionedPeople.length === 0) { return []; @@ -276,7 +274,7 @@ export const parseTextMentions = async ( // Resolve remote mentions not in database for (const person of notFoundRemoteUsers) { - const url = await (await author.federationRequester).resolveWebFinger( + const url = await FederationRequester.resolveWebFinger( person[1] ?? "", person[2] ?? "", ); diff --git a/classes/inbox/processor.ts b/classes/inbox/processor.ts index 44bfb815..3baaf383 100644 --- a/classes/inbox/processor.ts +++ b/classes/inbox/processor.ts @@ -185,19 +185,19 @@ export class InboxProcessor { await Note.fromVersia(n); }) .on(VersiaEntities.Follow, (f) => { - this.processFollowRequest(f); + InboxProcessor.processFollowRequest(f); }) .on(VersiaEntities.FollowAccept, (f) => { - this.processFollowAccept(f); + InboxProcessor.processFollowAccept(f); }) .on(VersiaEntities.FollowReject, (f) => { - this.processFollowReject(f); + InboxProcessor.processFollowReject(f); }) .on(VersiaEntities.Like, (l) => { - this.processLikeRequest(l); + InboxProcessor.processLikeRequest(l); }) .on(VersiaEntities.Delete, (d) => { - this.processDelete(d); + InboxProcessor.processDelete(d); }) .on(VersiaEntities.User, async (u) => { await User.fromVersia(u); @@ -216,7 +216,7 @@ export class InboxProcessor { * @param {VersiaFollow} follow - The Follow entity to process. * @returns {Promise} */ - private async processFollowRequest( + private static async processFollowRequest( follow: VersiaEntities.Follow, ): Promise { const author = await User.resolve(follow.data.author); @@ -264,7 +264,7 @@ export class InboxProcessor { * @param {VersiaFollowAccept} followAccept - The FollowAccept entity to process. * @returns {Promise} */ - private async processFollowAccept( + private static async processFollowAccept( followAccept: VersiaEntities.FollowAccept, ): Promise { const author = await User.resolve(followAccept.data.author); @@ -299,7 +299,7 @@ export class InboxProcessor { * @param {VersiaFollowReject} followReject - The FollowReject entity to process. * @returns {Promise} */ - private async processFollowReject( + private static async processFollowReject( followReject: VersiaEntities.FollowReject, ): Promise { const author = await User.resolve(followReject.data.author); @@ -334,7 +334,9 @@ export class InboxProcessor { * @param {VersiaDelete} delete_ - The Delete entity to process. * @returns {Promise} */ // JS doesn't allow the use of `delete` as a variable name - public async processDelete(delete_: VersiaEntities.Delete): Promise { + public static async processDelete( + delete_: VersiaEntities.Delete, + ): Promise { const toDelete = delete_.data.deleted; const author = delete_.data.author @@ -403,7 +405,9 @@ export class InboxProcessor { * @param {VersiaLikeExtension} like - The Like entity to process. * @returns {Promise} */ - private async processLikeRequest(like: VersiaEntities.Like): Promise { + private static async processLikeRequest( + like: VersiaEntities.Like, + ): Promise { const author = await User.resolve(like.data.author); const likedNote = await Note.resolve(like.data.liked); diff --git a/packages/sdk/http.ts b/packages/sdk/http.ts index 65b2b2ae..86e8a43b 100644 --- a/packages/sdk/http.ts +++ b/packages/sdk/http.ts @@ -158,7 +158,7 @@ export class FederationRequester { * Attempt to resolve a webfinger URL to a User * @returns {Promise} The resolved User or null if not found */ - public async resolveWebFinger( + public static async resolveWebFinger( username: string, hostname: string, contentType = "application/json", diff --git a/packages/sdk/regex.ts b/packages/sdk/regex.ts index e08de1ad..602eccfc 100644 --- a/packages/sdk/regex.ts +++ b/packages/sdk/regex.ts @@ -10,7 +10,7 @@ import { oneOrMore, } from "magic-regexp"; -export const semverRegex: RegExp = new RegExp( +export const semverRegex = new RegExp( /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm, ); @@ -57,8 +57,8 @@ export const emojiRegex: RegExp = createRegExp( // This will accept a lot of stuff that isn't an ISO string // but ISO validation is incredibly complex so fuck it export const isISOString = (val: string | Date): boolean => { - const d = new Date(val); - return !Number.isNaN(d.valueOf()); + const date = new Date(val); + return !Number.isNaN(date.valueOf()); }; export const ianaTimezoneRegex = /^(?:[A-Za-z]+(?:\/[A-Za-z_]+)+|UTC)$/;