mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(federation): ♻️ More federation logic cleanup
This commit is contained in:
parent
83399ba5f1
commit
0ae9cfe26c
10 changed files with 124 additions and 133 deletions
|
|
@ -117,6 +117,10 @@ export default apiRoute((app) =>
|
|||
|
||||
const uri = await User.webFinger(manager, username, domain);
|
||||
|
||||
if (!uri) {
|
||||
return context.json({ error: "Account not found" }, 404);
|
||||
}
|
||||
|
||||
const foundAccount = await User.resolve(uri);
|
||||
|
||||
if (foundAccount) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
import { apiRoute, applyConfig, auth, userAddressValidator } from "@/api";
|
||||
import {
|
||||
apiRoute,
|
||||
applyConfig,
|
||||
auth,
|
||||
parseUserAddress,
|
||||
userAddressValidator,
|
||||
} from "@/api";
|
||||
import { createRoute } from "@hono/zod-openapi";
|
||||
import { User } from "@versia/kit/db";
|
||||
import { RolePermissions, Users } from "@versia/kit/tables";
|
||||
|
|
@ -77,19 +83,21 @@ export default apiRoute((app) =>
|
|||
return context.json({ error: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
const [username, host] = q.replace(/^@/, "").split("@");
|
||||
const { username, domain } = parseUserAddress(q);
|
||||
|
||||
const accounts: User[] = [];
|
||||
|
||||
if (resolve && username && host) {
|
||||
if (resolve && domain) {
|
||||
const manager = await (self ?? User).getFederationRequester();
|
||||
|
||||
const uri = await User.webFinger(manager, username, host);
|
||||
const uri = await User.webFinger(manager, username, domain);
|
||||
|
||||
const resolvedUser = await User.resolve(uri);
|
||||
if (uri) {
|
||||
const resolvedUser = await User.resolve(uri);
|
||||
|
||||
if (resolvedUser) {
|
||||
accounts.push(resolvedUser);
|
||||
if (resolvedUser) {
|
||||
accounts.push(resolvedUser);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
accounts.push(
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ export default apiRoute((app) =>
|
|||
}
|
||||
|
||||
if (note.author.isLocal() && user.isLocal()) {
|
||||
await note.author.createNotification("reblog", user, newReblog);
|
||||
await note.author.notify("reblog", user, newReblog);
|
||||
}
|
||||
|
||||
return context.json(await finalNewReblog.toApi(user), 201);
|
||||
|
|
|
|||
|
|
@ -163,17 +163,19 @@ export default apiRoute((app) =>
|
|||
|
||||
const uri = await User.webFinger(manager, username, domain);
|
||||
|
||||
const newUser = await User.resolve(uri);
|
||||
if (uri) {
|
||||
const newUser = await User.resolve(uri);
|
||||
|
||||
if (newUser) {
|
||||
return context.json(
|
||||
{
|
||||
accounts: [newUser.toApi()],
|
||||
statuses: [],
|
||||
hashtags: [],
|
||||
},
|
||||
200,
|
||||
);
|
||||
if (newUser) {
|
||||
return context.json(
|
||||
{
|
||||
accounts: [newUser.toApi()],
|
||||
statuses: [],
|
||||
hashtags: [],
|
||||
},
|
||||
200,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue