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