use parse instead

This commit is contained in:
Namekuji 2023-05-31 01:02:41 -04:00
parent b1d0b291ff
commit c321a6ee39
No known key found for this signature in database
GPG key ID: B541BD6E646CABC7

View file

@ -10,9 +10,9 @@ import deleteFollowing from "@/services/following/delete.js";
import create from "@/services/following/create.js";
import { getUser } from "@/server/api/common/getters.js";
import { Followings, Users } from "@/models/index.js";
import { UserProfiles } from "@/models/index.js";
import config from "@/config/index.js";
import { publishMainStream } from "@/services/stream.js";
import { parse } from "@/misc/acct.js";
export const meta = {
tags: ["users"],
@ -95,17 +95,10 @@ export default define(meta, paramDef, async (ps, user) => {
if (user.isAdmin) throw new ApiError(meta.errors.adminForbidden);
if (user.movedToUri) throw new ApiError(meta.errors.alreadyMoved);
let unfiltered: string = ps.moveToAccount;
if (!unfiltered) {
throw new ApiError(meta.errors.noSuchMoveTarget);
}
const { username, host } = parse(ps.moveToAccount);
if (!host) throw new ApiError(meta.errors.notRemote);
if (unfiltered.startsWith("acct:")) unfiltered = unfiltered.substring(5);
if (unfiltered.startsWith("@")) unfiltered = unfiltered.substring(1);
if (!unfiltered.includes("@")) throw new ApiError(meta.errors.notRemote);
const userAddress: string[] = unfiltered.split("@");
const moveTo: User = await resolveUser(userAddress[0], userAddress[1]).catch(
const moveTo: User = await resolveUser(username, host).catch(
(e) => {
apiLogger.warn(`failed to resolve remote user: ${e}`);
throw new ApiError(meta.errors.noSuchMoveTarget);
@ -134,6 +127,7 @@ export default define(meta, paramDef, async (ps, user) => {
if (!toUrl) toUrl = "";
updates.movedToUri = toUrl;
updates.alsoKnownAs = user.alsoKnownAs?.concat(toUrl) ?? [toUrl];
await Users.update(user.id, updates);
const iObj = await Users.pack<true, true>(user.id, user, {