Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
547 changes: 197 additions & 350 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli/user/refetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const refetchUserCommand = defineCommand(
const spinner = ora("Refetching user").start();

try {
await User.fromVersia(user.uri);
await User.fromVersia(user.reference);
} catch (error) {
spinner.fail(
`Failed to refetch user ${chalk.gray(user.data.username)}`,
Expand Down
2 changes: 1 addition & 1 deletion cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const retrieveUser = async (
): Promise<User | null> => {
const { username, domain } = parseUserAddress(usernameOrHandle);

const instance = domain ? await Instance.resolveFromHost(domain) : null;
const instance = domain ? await Instance.resolve(domain) : null;

const user = await User.fromSql(
and(
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
default = pkgs.mkShell rec {
libPath = with pkgs;
lib.makeLibraryPath [
vips
stdenv.cc.cc.lib
];

LD_LIBRARY_PATH = "${libPath}";

buildInputs = with pkgs; [
bun
vips
nodePackages.typescript
nodePackages.typescript-language-server
nix-ld
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"hono-openapi": "~1.1.2",
"hono-rate-limiter": "~0.5.1",
"html-to-text": "~9.0.5",
"ioredis": "~5.8.2",
"ioredis": "5.9.2",
"ip-matching": "~2.1.2",
"iso-639-1": "~3.1.5",
"linkify-html": "~4.3.2",
Expand Down Expand Up @@ -158,6 +158,7 @@
"dependencies": {
"@bull-board/api": "catalog:",
"@bull-board/hono": "catalog:",
"@clerc/core": "catalog:",
"@clerc/plugin-completions": "catalog:",
"@clerc/plugin-friendly-error": "catalog:",
"@clerc/plugin-help": "catalog:",
Expand All @@ -180,7 +181,6 @@
"blurhash": "catalog:",
"bullmq": "catalog:",
"chalk": "catalog:",
"@clerc/core": "catalog:",
"confbox": "catalog:",
"drizzle-orm": "catalog:",
"feed": "catalog:",
Expand Down Expand Up @@ -216,5 +216,8 @@
"zod": "catalog:",
"zod-openapi": "catalog:",
"zod-validation-error": "catalog:"
},
"patchedDependencies": {
"bun-bagel@1.2.0": "patches/bun-bagel@1.2.0.patch"
}
}
2 changes: 1 addition & 1 deletion packages/api/routes/api/v1/accounts/[id]/refetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default apiRoute((app) =>
throw new ApiError(400, "Cannot refetch a local user");
}

const newUser = await User.fromVersia(otherUser.uri);
const newUser = await User.fromVersia(otherUser.reference);

return context.json(newUser.toApi(false), 200);
},
Expand Down
14 changes: 8 additions & 6 deletions packages/api/routes/api/v1/accounts/lookup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Account as AccountSchema,
RolePermission,
} from "@versia/client/schemas";
import * as VersiaEntities from "@versia/sdk/entities";
import { config } from "@versia-server/config";
import { ApiError } from "@versia-server/kit";
import { apiRoute, auth, handleZodError } from "@versia-server/kit/api";
Expand Down Expand Up @@ -73,7 +74,7 @@ export default apiRoute((app) =>

// User is remote
// Try to fetch it from database
const instance = await Instance.resolveFromHost(domain);
const instance = await Instance.resolve(domain);

if (!instance) {
return context.json(
Expand All @@ -100,13 +101,14 @@ export default apiRoute((app) =>
throw ApiError.accountNotFound();
}

const foundAccount = await User.resolve(uri);
const accountData = await Instance.federationRequester.fetchSigned(
uri,
VersiaEntities.User,
);

if (foundAccount) {
return context.json(foundAccount.toApi(), 200);
}
const foundAccount = await User.fromVersia(accountData, instance);

throw ApiError.accountNotFound();
return context.json(foundAccount.toApi(), 200);
},
),
);
19 changes: 14 additions & 5 deletions packages/api/routes/api/v1/accounts/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
RolePermission,
zBoolean,
} from "@versia/client/schemas";
import * as VersiaEntities from "@versia/sdk/entities";
import { ApiError } from "@versia-server/kit";
import { apiRoute, auth, handleZodError } from "@versia-server/kit/api";
import { User } from "@versia-server/kit/db";
import { Instance, User } from "@versia-server/kit/db";
import { parseUserAddress } from "@versia-server/kit/parsers";
import { Users } from "@versia-server/kit/tables";
import { eq, ilike, not, or, sql } from "drizzle-orm";
Expand Down Expand Up @@ -88,14 +89,22 @@ export default apiRoute((app) =>
const accounts: User[] = [];

if (resolve && domain) {
const instance = await Instance.resolve(domain);
const uri = await User.webFinger(username, domain);

if (uri) {
const resolvedUser = await User.resolve(uri);
const accountData =
await Instance.federationRequester.fetchSigned(
uri,
VersiaEntities.User,
);

if (resolvedUser) {
accounts.push(resolvedUser);
}
const foundAccount = await User.fromVersia(
accountData,
instance,
);

accounts.push(foundAccount);
}
} else {
accounts.push(
Expand Down
33 changes: 21 additions & 12 deletions packages/api/routes/api/v2/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
userAddressRegex,
zBoolean,
} from "@versia/client/schemas";
import * as VersiaEntities from "@versia/sdk/entities";
import { config } from "@versia-server/config";
import { ApiError } from "@versia-server/kit";
import { apiRoute, auth, handleZodError } from "@versia-server/kit/api";
import { db, Note, User } from "@versia-server/kit/db";
import { db, Instance, Note, User } from "@versia-server/kit/db";
import { parseUserAddress } from "@versia-server/kit/parsers";
import { searchManager } from "@versia-server/kit/search";
import { Instances, Notes, Users } from "@versia-server/kit/tables";
Expand Down Expand Up @@ -187,21 +188,29 @@ export default apiRoute((app) =>
}

if (resolve && domain) {
const instance = await Instance.resolve(domain);
const uri = await User.webFinger(username, domain);

if (uri) {
const newUser = await User.resolve(uri);

if (newUser) {
return context.json(
{
accounts: [newUser.toApi()],
statuses: [],
hashtags: [],
},
200,
const accountData =
await Instance.federationRequester.fetchSigned(
uri,
VersiaEntities.User,
);
}

const newUser = await User.fromVersia(
accountData,
instance,
);

return context.json(
{
accounts: [newUser.toApi()],
statuses: [],
hashtags: [],
},
200,
);
}
}
}
Expand Down
84 changes: 0 additions & 84 deletions packages/api/routes/likes/[uuid]/index.ts

This file was deleted.

78 changes: 0 additions & 78 deletions packages/api/routes/notes/[uuid]/index.ts

This file was deleted.

Loading
Loading