refactor: 🔥 Remove dead code

This commit is contained in:
Jesse Wierzbinski 2024-05-07 03:13:37 +00:00
parent 592f7c0ac2
commit 7b05a34cce
No known key found for this signature in database
36 changed files with 32 additions and 1692 deletions

View file

@ -1,90 +0,0 @@
import type { InferSelectModel } from "drizzle-orm";
import type * as Lysand from "lysand-types";
import { db } from "~drizzle/db";
import { LysandObjects } from "~drizzle/schema";
import { findFirstUser } from "./User";
export type LysandObject = InferSelectModel<typeof LysandObjects>;
/**
* Represents a Lysand object in the database.
*/
export const createFromObject = async (
object: Lysand.Entity,
authorUri: string,
) => {
const foundObject = await db.query.LysandObjects.findFirst({
where: (o, { eq }) => eq(o.remoteId, object.id),
with: {
author: true,
},
});
if (foundObject) {
return foundObject;
}
const author = await findFirstUser({
where: (user, { eq }) => eq(user.uri, authorUri),
});
return await db.insert(LysandObjects).values({
authorId: author?.id,
createdAt: new Date(object.created_at).toISOString(),
extensions: object.extensions,
remoteId: object.id,
type: object.type,
uri: object.uri,
// Rest of data (remove id, author, created_at, extensions, type, uri)
extraData: Object.fromEntries(
Object.entries(object).filter(
([key]) =>
![
"id",
"author",
"created_at",
"extensions",
"type",
"uri",
].includes(key),
),
),
});
};
export const toLysand = (lyObject: LysandObject): Lysand.Entity => {
return {
id: lyObject.remoteId || lyObject.id,
created_at: new Date(lyObject.createdAt).toISOString(),
type: lyObject.type,
uri: lyObject.uri,
...(lyObject.extraData as object),
// @ts-expect-error Assume stored JSON is valid
extensions: lyObject.extensions as object,
};
};
export const isPublication = (lyObject: LysandObject): boolean => {
return lyObject.type === "Note" || lyObject.type === "Patch";
};
export const isAction = (lyObject: LysandObject): boolean => {
return [
"Like",
"Follow",
"Dislike",
"FollowAccept",
"FollowReject",
"Undo",
"Announce",
].includes(lyObject.type);
};
export const isActor = (lyObject: LysandObject): boolean => {
return lyObject.type === "User";
};
export const isExtension = (lyObject: LysandObject): boolean => {
return lyObject.type === "Extension";
};

View file

@ -1,123 +0,0 @@
import { config } from "config-manager";
// import { Worker } from "bullmq";
/* export const federationWorker = new Worker(
"federation",
async job => {
await job.updateProgress(0);
switch (job.name) {
case "federation": {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const statusId = job.data.id as string;
const status = await client.status.findUnique({
where: { id: statusId },
include: statusAndUserRelations,
});
if (!status) return;
// Only get remote users that follow the author of the status, and the remote mentioned users
const peopleToSendTo = await client.user.findMany({
where: {
OR: [
["public", "unlisted", "private"].includes(
status.visibility
)
? {
relationships: {
some: {
subjectId: status.authorId,
following: true,
},
},
instanceId: {
not: null,
},
}
: {},
// Mentioned users
{
id: {
in: status.mentions.map(m => m.id),
},
instanceId: {
not: null,
},
},
],
},
});
let peopleDone = 0;
// Spawn sendToServer job for each user
for (const person of peopleToSendTo) {
await federationQueue.add("sendToServer", {
id: statusId,
user: person,
});
peopleDone++;
await job.updateProgress(
Math.round((peopleDone / peopleToSendTo.length) * 100)
);
}
break;
}
case "sendToServer": {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const statusId = job.data.id as string;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const user = job.data.user as User;
const status = await client.status.findUnique({
where: { id: statusId },
include: statusAndUserRelations,
});
if (!status) return;
const response = await federateStatusTo(
status,
status.author,
user
);
if (response.status !== 200) {
throw new Error(
`Federation error: ${response.status} ${response.statusText}`
);
}
break;
}
}
await job.updateProgress(100);
return true;
},
{
connection: {
host: config.redis.queue.host,
port: config.redis.queue.port,
password: config.redis.queue.password,
db: config.redis.queue.database || undefined,
},
removeOnComplete: {
count: 400,
},
removeOnFail: {
count: 3000,
},
}
); */
export const addStatusFederationJob = async (statusId: string) => {
/* await federationQueue.add("federation", {
id: statusId,
}); */
};

View file

@ -647,10 +647,3 @@ export const federateNote = async (note: Note) => {
}
}
};
export const isFavouritedBy = async (status: Status, user: UserType) => {
return !!(await db.query.Likes.findFirst({
where: (like, { and, eq }) =>
and(eq(like.likerId, user.id), eq(like.likedId, status.id)),
}));
};

View file

@ -34,11 +34,6 @@ export type UserWithRelations = UserType & {
statusCount: number;
};
export type UserWithRelationsAndRelationships = UserWithRelations & {
relationships: InferSelectModel<typeof Relationships>[];
relationshipSubjects: InferSelectModel<typeof Relationships>[];
};
export const userRelations: {
instance: true;
emojis: {
@ -99,16 +94,6 @@ export interface AuthData {
application: Application | null;
}
export const getFromRequest = async (req: Request): Promise<AuthData> => {
// Check auth token
const token = req.headers.get("Authorization")?.split(" ")[1] || "";
const { user, application } =
await retrieveUserAndApplicationFromToken(token);
return { user, token, application };
};
export const getFromHeader = async (value: string): Promise<AuthData> => {
const token = value.split(" ")[1];
@ -388,15 +373,6 @@ export const resolveWebFinger = async (
return User.resolve(relevantLink.href);
};
/**
* Parses mentions from a list of URIs
*/
export const parseMentionsUris = async (
mentions: string[],
): Promise<User[]> => {
return await User.manyFromSql(inArray(Users.uri, mentions));
};
/**
* Retrieves a user from a token.
* @param access_token The access token to retrieve the user from.