mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
fix: 🚨 Fix DeepSource linter warnings
This commit is contained in:
parent
45e5460975
commit
1d301d72ae
|
|
@ -242,7 +242,7 @@ export default apiRoute((app) => {
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const parsedMentions = statusText
|
const parsedMentions = statusText
|
||||||
? await parseTextMentions(statusText, user)
|
? await parseTextMentions(statusText)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const parsedEmojis = statusText
|
const parsedEmojis = statusText
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ export default apiRoute((app) =>
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const parsedMentions = status
|
const parsedMentions = status
|
||||||
? await parseTextMentions(status, user)
|
? await parseTextMentions(status)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const parsedEmojis = status
|
const parsedEmojis = status
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ export default apiRoute((app) =>
|
||||||
}),
|
}),
|
||||||
handleZodError,
|
handleZodError,
|
||||||
),
|
),
|
||||||
// @ts-expect-error
|
// @ts-expect-error idk why this is happening and I don't care
|
||||||
async (context) => {
|
async (context) => {
|
||||||
const { uuid } = context.req.valid("param");
|
const { uuid } = context.req.valid("param");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import {
|
||||||
import { getLogger } from "@logtape/logtape";
|
import { getLogger } from "@logtape/logtape";
|
||||||
import { User } from "@versia/kit/db";
|
import { User } from "@versia/kit/db";
|
||||||
import { Users } from "@versia/kit/tables";
|
import { Users } from "@versia/kit/tables";
|
||||||
|
import { FederationRequester } from "@versia/sdk/http";
|
||||||
import { and, eq, isNull } from "drizzle-orm";
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
import { describeRoute } from "hono-openapi";
|
import { describeRoute } from "hono-openapi";
|
||||||
import { resolver, validator } from "hono-openapi/zod";
|
import { resolver, validator } from "hono-openapi/zod";
|
||||||
|
|
@ -84,13 +85,12 @@ export default apiRoute((app) =>
|
||||||
|
|
||||||
if (config.federation.bridge) {
|
if (config.federation.bridge) {
|
||||||
try {
|
try {
|
||||||
activityPubUrl =
|
activityPubUrl = await FederationRequester.resolveWebFinger(
|
||||||
await User.federationRequester.resolveWebFinger(
|
user.data.username,
|
||||||
user.data.username,
|
config.http.base_url.host,
|
||||||
config.http.base_url.host,
|
"application/activity+json",
|
||||||
"application/activity+json",
|
config.federation.bridge.url.origin,
|
||||||
config.federation.bridge.url.origin,
|
);
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e as ApiError;
|
const error = e as ApiError;
|
||||||
|
|
||||||
|
|
|
||||||
10
bun.lock
10
bun.lock
|
|
@ -95,10 +95,6 @@
|
||||||
"@badgateway/oauth2-client": "^2.4.2",
|
"@badgateway/oauth2-client": "^2.4.2",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"packages/federation": {
|
|
||||||
"name": "@versia/sdk",
|
|
||||||
"version": "0.0.1",
|
|
||||||
},
|
|
||||||
"packages/plugin-kit": {
|
"packages/plugin-kit": {
|
||||||
"name": "@versia/kit",
|
"name": "@versia/kit",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
|
|
@ -109,6 +105,10 @@
|
||||||
"zod-validation-error": "^3.3.0",
|
"zod-validation-error": "^3.3.0",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"packages/sdk": {
|
||||||
|
"name": "@versia/sdk",
|
||||||
|
"version": "0.0.1",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"trustedDependencies": [
|
"trustedDependencies": [
|
||||||
"sharp",
|
"sharp",
|
||||||
|
|
@ -574,7 +574,7 @@
|
||||||
|
|
||||||
"@versia/kit": ["@versia/kit@workspace:packages/plugin-kit"],
|
"@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=="],
|
"@vitejs/plugin-vue": ["@vitejs/plugin-vue@5.2.3", "", { "peerDependencies": { "vite": "^5.0.0 || ^6.0.0", "vue": "^3.2.25" } }, "sha512-IYSLEQj4LgZZuoVpdSUCw3dIynTWQgPlaRP6iAvMle4My0HdYwr5g5wQAfwOeHQBmYwEkqF70nRpSilr6PoUDg=="],
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -347,13 +347,10 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
||||||
hostname: string,
|
hostname: string,
|
||||||
): Promise<URL | null> {
|
): Promise<URL | null> {
|
||||||
try {
|
try {
|
||||||
return User.federationRequester.resolveWebFinger(
|
return FederationRequester.resolveWebFinger(username, hostname);
|
||||||
username,
|
|
||||||
hostname,
|
|
||||||
);
|
|
||||||
} catch {
|
} catch {
|
||||||
try {
|
try {
|
||||||
return User.federationRequester.resolveWebFinger(
|
return FederationRequester.resolveWebFinger(
|
||||||
username,
|
username,
|
||||||
hostname,
|
hostname,
|
||||||
"application/activity+json",
|
"application/activity+json",
|
||||||
|
|
@ -854,7 +851,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
||||||
|
|
||||||
const user = await User.insert({
|
const user = await User.insert({
|
||||||
id: randomUUIDv7(),
|
id: randomUUIDv7(),
|
||||||
username: username,
|
username,
|
||||||
displayName: username,
|
displayName: username,
|
||||||
password: options?.password
|
password: options?.password
|
||||||
? await bunPassword.hash(options.password)
|
? await bunPassword.hash(options.password)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { sanitizeHtml, sanitizeHtmlInline } from "@/sanitization";
|
||||||
import markdownItTaskLists from "@hackmd/markdown-it-task-lists";
|
import markdownItTaskLists from "@hackmd/markdown-it-task-lists";
|
||||||
import { type Note, User, db } from "@versia/kit/db";
|
import { type Note, User, db } from "@versia/kit/db";
|
||||||
import { Instances, Users } from "@versia/kit/tables";
|
import { Instances, Users } from "@versia/kit/tables";
|
||||||
|
import { FederationRequester } from "@versia/sdk/http";
|
||||||
import { and, eq, inArray, isNull, or, sql } from "drizzle-orm";
|
import { and, eq, inArray, isNull, or, sql } from "drizzle-orm";
|
||||||
import linkifyHtml from "linkify-html";
|
import linkifyHtml from "linkify-html";
|
||||||
import {
|
import {
|
||||||
|
|
@ -222,10 +223,7 @@ export const findManyNotes = async (
|
||||||
* @param text The text to parse mentions from.
|
* @param text The text to parse mentions from.
|
||||||
* @returns An array of users mentioned in the text.
|
* @returns An array of users mentioned in the text.
|
||||||
*/
|
*/
|
||||||
export const parseTextMentions = async (
|
export const parseTextMentions = async (text: string): Promise<User[]> => {
|
||||||
text: string,
|
|
||||||
author: User,
|
|
||||||
): Promise<User[]> => {
|
|
||||||
const mentionedPeople = [...text.matchAll(mentionValidator)];
|
const mentionedPeople = [...text.matchAll(mentionValidator)];
|
||||||
if (mentionedPeople.length === 0) {
|
if (mentionedPeople.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
|
|
@ -276,7 +274,7 @@ export const parseTextMentions = async (
|
||||||
|
|
||||||
// Resolve remote mentions not in database
|
// Resolve remote mentions not in database
|
||||||
for (const person of notFoundRemoteUsers) {
|
for (const person of notFoundRemoteUsers) {
|
||||||
const url = await (await author.federationRequester).resolveWebFinger(
|
const url = await FederationRequester.resolveWebFinger(
|
||||||
person[1] ?? "",
|
person[1] ?? "",
|
||||||
person[2] ?? "",
|
person[2] ?? "",
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -185,19 +185,19 @@ export class InboxProcessor {
|
||||||
await Note.fromVersia(n);
|
await Note.fromVersia(n);
|
||||||
})
|
})
|
||||||
.on(VersiaEntities.Follow, (f) => {
|
.on(VersiaEntities.Follow, (f) => {
|
||||||
this.processFollowRequest(f);
|
InboxProcessor.processFollowRequest(f);
|
||||||
})
|
})
|
||||||
.on(VersiaEntities.FollowAccept, (f) => {
|
.on(VersiaEntities.FollowAccept, (f) => {
|
||||||
this.processFollowAccept(f);
|
InboxProcessor.processFollowAccept(f);
|
||||||
})
|
})
|
||||||
.on(VersiaEntities.FollowReject, (f) => {
|
.on(VersiaEntities.FollowReject, (f) => {
|
||||||
this.processFollowReject(f);
|
InboxProcessor.processFollowReject(f);
|
||||||
})
|
})
|
||||||
.on(VersiaEntities.Like, (l) => {
|
.on(VersiaEntities.Like, (l) => {
|
||||||
this.processLikeRequest(l);
|
InboxProcessor.processLikeRequest(l);
|
||||||
})
|
})
|
||||||
.on(VersiaEntities.Delete, (d) => {
|
.on(VersiaEntities.Delete, (d) => {
|
||||||
this.processDelete(d);
|
InboxProcessor.processDelete(d);
|
||||||
})
|
})
|
||||||
.on(VersiaEntities.User, async (u) => {
|
.on(VersiaEntities.User, async (u) => {
|
||||||
await User.fromVersia(u);
|
await User.fromVersia(u);
|
||||||
|
|
@ -216,7 +216,7 @@ export class InboxProcessor {
|
||||||
* @param {VersiaFollow} follow - The Follow entity to process.
|
* @param {VersiaFollow} follow - The Follow entity to process.
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
private async processFollowRequest(
|
private static async processFollowRequest(
|
||||||
follow: VersiaEntities.Follow,
|
follow: VersiaEntities.Follow,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const author = await User.resolve(follow.data.author);
|
const author = await User.resolve(follow.data.author);
|
||||||
|
|
@ -264,7 +264,7 @@ export class InboxProcessor {
|
||||||
* @param {VersiaFollowAccept} followAccept - The FollowAccept entity to process.
|
* @param {VersiaFollowAccept} followAccept - The FollowAccept entity to process.
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
private async processFollowAccept(
|
private static async processFollowAccept(
|
||||||
followAccept: VersiaEntities.FollowAccept,
|
followAccept: VersiaEntities.FollowAccept,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const author = await User.resolve(followAccept.data.author);
|
const author = await User.resolve(followAccept.data.author);
|
||||||
|
|
@ -299,7 +299,7 @@ export class InboxProcessor {
|
||||||
* @param {VersiaFollowReject} followReject - The FollowReject entity to process.
|
* @param {VersiaFollowReject} followReject - The FollowReject entity to process.
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
private async processFollowReject(
|
private static async processFollowReject(
|
||||||
followReject: VersiaEntities.FollowReject,
|
followReject: VersiaEntities.FollowReject,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const author = await User.resolve(followReject.data.author);
|
const author = await User.resolve(followReject.data.author);
|
||||||
|
|
@ -334,7 +334,9 @@ export class InboxProcessor {
|
||||||
* @param {VersiaDelete} delete_ - The Delete entity to process.
|
* @param {VersiaDelete} delete_ - The Delete entity to process.
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/ // JS doesn't allow the use of `delete` as a variable name
|
*/ // JS doesn't allow the use of `delete` as a variable name
|
||||||
public async processDelete(delete_: VersiaEntities.Delete): Promise<void> {
|
public static async processDelete(
|
||||||
|
delete_: VersiaEntities.Delete,
|
||||||
|
): Promise<void> {
|
||||||
const toDelete = delete_.data.deleted;
|
const toDelete = delete_.data.deleted;
|
||||||
|
|
||||||
const author = delete_.data.author
|
const author = delete_.data.author
|
||||||
|
|
@ -403,7 +405,9 @@ export class InboxProcessor {
|
||||||
* @param {VersiaLikeExtension} like - The Like entity to process.
|
* @param {VersiaLikeExtension} like - The Like entity to process.
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
private async processLikeRequest(like: VersiaEntities.Like): Promise<void> {
|
private static async processLikeRequest(
|
||||||
|
like: VersiaEntities.Like,
|
||||||
|
): Promise<void> {
|
||||||
const author = await User.resolve(like.data.author);
|
const author = await User.resolve(like.data.author);
|
||||||
const likedNote = await Note.resolve(like.data.liked);
|
const likedNote = await Note.resolve(like.data.liked);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ export class FederationRequester {
|
||||||
* Attempt to resolve a webfinger URL to a User
|
* Attempt to resolve a webfinger URL to a User
|
||||||
* @returns {Promise<User | null>} The resolved User or null if not found
|
* @returns {Promise<User | null>} The resolved User or null if not found
|
||||||
*/
|
*/
|
||||||
public async resolveWebFinger(
|
public static async resolveWebFinger(
|
||||||
username: string,
|
username: string,
|
||||||
hostname: string,
|
hostname: string,
|
||||||
contentType = "application/json",
|
contentType = "application/json",
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
oneOrMore,
|
oneOrMore,
|
||||||
} from "magic-regexp";
|
} 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,
|
/^(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
|
// This will accept a lot of stuff that isn't an ISO string
|
||||||
// but ISO validation is incredibly complex so fuck it
|
// but ISO validation is incredibly complex so fuck it
|
||||||
export const isISOString = (val: string | Date): boolean => {
|
export const isISOString = (val: string | Date): boolean => {
|
||||||
const d = new Date(val);
|
const date = new Date(val);
|
||||||
return !Number.isNaN(d.valueOf());
|
return !Number.isNaN(date.valueOf());
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ianaTimezoneRegex = /^(?:[A-Za-z]+(?:\/[A-Za-z_]+)+|UTC)$/;
|
export const ianaTimezoneRegex = /^(?:[A-Za-z]+(?:\/[A-Za-z_]+)+|UTC)$/;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue