fix: Fix broken user source

This commit is contained in:
Jesse Wierzbinski 2023-12-02 22:56:23 -10:00
parent 43d9be5440
commit 01d20153e6
No known key found for this signature in database
2 changed files with 32 additions and 10 deletions

View file

@ -48,12 +48,18 @@ export default async (req: Request): Promise<Response> => {
const accounts = await client.user.findMany({ const accounts = await client.user.findMany({
where: { where: {
displayName: { OR: [
contains: q, {
}, displayName: {
username: { contains: q,
contains: q, },
}, },
{
username: {
contains: q,
},
},
],
relationshipSubjects: following relationshipSubjects: following
? { ? {
some: { some: {

View file

@ -1,7 +1,11 @@
import { getConfig } from "@config"; import { getConfig } from "@config";
import { parseRequest } from "@request"; import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response"; import { errorResponse, jsonResponse } from "@response";
import { getFromRequest, userToAPI } from "~database/entities/User"; import {
getFromRequest,
userRelations,
userToAPI,
} from "~database/entities/User";
import { applyConfig } from "@api"; import { applyConfig } from "@api";
import { sanitize } from "isomorphic-dompurify"; import { sanitize } from "isomorphic-dompurify";
import { sanitizeHtml } from "@sanitization"; import { sanitizeHtml } from "@sanitization";
@ -9,6 +13,7 @@ import { uploadFile } from "~classes/media";
import ISO6391 from "iso-639-1"; import ISO6391 from "iso-639-1";
import { parseEmojis } from "~database/entities/Emoji"; import { parseEmojis } from "~database/entities/Emoji";
import { client } from "~database/datasource"; import { client } from "~database/datasource";
import type { APISource } from "~types/entities/source";
export const meta = applyConfig({ export const meta = applyConfig({
allowedMethods: ["PATCH"], allowedMethods: ["PATCH"],
@ -63,6 +68,15 @@ export default async (req: Request): Promise<Response> => {
ALLOWED_ATTR: [], ALLOWED_ATTR: [],
}); });
if (!user.source) {
user.source = {
privacy: "public",
sensitive: false,
language: "en",
note: "",
};
}
if (display_name) { if (display_name) {
// Check if within allowed display name lengths // Check if within allowed display name lengths
if ( if (
@ -90,7 +104,7 @@ export default async (req: Request): Promise<Response> => {
user.displayName = sanitizedDisplayName; user.displayName = sanitizedDisplayName;
} }
if (note) { if (note && user.source) {
// Check if within allowed note length // Check if within allowed note length
if (sanitizedNote.length > config.validation.max_note_size) { if (sanitizedNote.length > config.validation.max_note_size) {
return errorResponse( return errorResponse(
@ -111,6 +125,7 @@ export default async (req: Request): Promise<Response> => {
// Remove emojis // Remove emojis
user.emojis = []; user.emojis = [];
(user.source as unknown as APISource).note = sanitizedNote;
user.note = sanitizedNote; user.note = sanitizedNote;
} }
@ -220,7 +235,7 @@ export default async (req: Request): Promise<Response> => {
(emoji, index, self) => self.findIndex(e => e.id === emoji.id) === index (emoji, index, self) => self.findIndex(e => e.id === emoji.id) === index
); );
await client.user.update({ const output = await client.user.update({
where: { id: user.id }, where: { id: user.id },
data: { data: {
displayName: user.displayName, displayName: user.displayName,
@ -240,7 +255,8 @@ export default async (req: Request): Promise<Response> => {
}, },
source: user.source || undefined, source: user.source || undefined,
}, },
include: userRelations,
}); });
return jsonResponse(userToAPI(user)); return jsonResponse(userToAPI(output));
}; };