Skip to content

Commit

Permalink
fix: Fix broken user source
Browse files Browse the repository at this point in the history
  • Loading branch information
CPlusPatch committed Dec 3, 2023
1 parent 43d9be5 commit 01d2015
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
18 changes: 12 additions & 6 deletions server/api/api/v1/accounts/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ export default async (req: Request): Promise<Response> => {

const accounts = await client.user.findMany({
where: {
displayName: {
contains: q,
},
username: {
contains: q,
},
OR: [
{
displayName: {
contains: q,
},
},
{
username: {
contains: q,
},
},
],
relationshipSubjects: following
? {
some: {
Expand Down
24 changes: 20 additions & 4 deletions server/api/api/v1/accounts/update_credentials/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { getConfig } from "@config";
import { parseRequest } from "@request";
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 { sanitize } from "isomorphic-dompurify";
import { sanitizeHtml } from "@sanitization";
import { uploadFile } from "~classes/media";
import ISO6391 from "iso-639-1";
import { parseEmojis } from "~database/entities/Emoji";
import { client } from "~database/datasource";
import type { APISource } from "~types/entities/source";

export const meta = applyConfig({
allowedMethods: ["PATCH"],
Expand Down Expand Up @@ -63,6 +68,15 @@ export default async (req: Request): Promise<Response> => {
ALLOWED_ATTR: [],
});

if (!user.source) {
user.source = {
privacy: "public",
sensitive: false,
language: "en",
note: "",
};
}

if (display_name) {
// Check if within allowed display name lengths
if (
Expand Down Expand Up @@ -90,7 +104,7 @@ export default async (req: Request): Promise<Response> => {
user.displayName = sanitizedDisplayName;
}

if (note) {
if (note && user.source) {
// Check if within allowed note length
if (sanitizedNote.length > config.validation.max_note_size) {
return errorResponse(
Expand All @@ -111,6 +125,7 @@ export default async (req: Request): Promise<Response> => {
// Remove emojis
user.emojis = [];

(user.source as unknown as APISource).note = sanitizedNote;
user.note = sanitizedNote;
}

Expand Down Expand Up @@ -220,7 +235,7 @@ export default async (req: Request): Promise<Response> => {
(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 },
data: {
displayName: user.displayName,
Expand All @@ -240,7 +255,8 @@ export default async (req: Request): Promise<Response> => {
},
source: user.source || undefined,
},
include: userRelations,
});

return jsonResponse(userToAPI(user));
return jsonResponse(userToAPI(output));
};

0 comments on commit 01d2015

Please sign in to comment.