mirror of
https://github.com/versia-pub/server.git
synced 2025-12-07 00:48:18 +01:00
fix: Fix broken user source
This commit is contained in:
parent
43d9be5440
commit
01d20153e6
|
|
@ -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: {
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue