fix(federation): 🐛 Correctly validate outbound Collections

This commit is contained in:
Jesse Wierzbinski 2024-08-26 19:34:21 +02:00
parent 42e198ca0e
commit 334c429bfa
No known key found for this signature in database
4 changed files with 7 additions and 10 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -110,7 +110,7 @@
"@oclif/core": "^4.0.19", "@oclif/core": "^4.0.19",
"@sentry/bun": "^8.26.0", "@sentry/bun": "^8.26.0",
"@tufjs/canonical-json": "^2.0.0", "@tufjs/canonical-json": "^2.0.0",
"@versia/federation": "^0.1.0-rc.0", "@versia/federation": "^0.1.0-rc.1",
"altcha-lib": "^0.5.1", "altcha-lib": "^0.5.1",
"blurhash": "^2.0.5", "blurhash": "^2.0.5",
"bullmq": "^5.12.10", "bullmq": "^5.12.10",

View file

@ -1,6 +1,6 @@
import { apiRoute, applyConfig, handleZodError } from "@/api"; import { apiRoute, applyConfig, handleZodError } from "@/api";
import { zValidator } from "@hono/zod-validator"; import { zValidator } from "@hono/zod-validator";
import type { Entity } from "@versia/federation/types"; import type { Collection } from "@versia/federation/types";
import { and, count, eq, inArray } from "drizzle-orm"; import { and, count, eq, inArray } from "drizzle-orm";
import { z } from "zod"; import { z } from "zod";
import { db } from "~/drizzle/db"; import { db } from "~/drizzle/db";
@ -108,14 +108,9 @@ export default apiRoute((app) =>
).toString() ).toString()
: null, : null,
items: notes.map((note) => note.toVersia()), items: notes.map((note) => note.toVersia()),
}; } satisfies Collection;
const { headers } = await author.sign( const { headers } = await author.sign(json, context.req.url, "GET");
// @ts-expect-error To fix when I add collections to versia-api
json as Entity,
context.req.url,
"GET",
);
return context.json(json, 200, headers.toJSON()); return context.json(json, 200, headers.toJSON());
}, },

View file

@ -1,6 +1,7 @@
import type { Hono } from "@hono/hono"; import type { Hono } from "@hono/hono";
import type { RouterRoute } from "@hono/hono/types"; import type { RouterRoute } from "@hono/hono/types";
import type { import type {
Collection,
Delete, Delete,
Follow, Follow,
FollowAccept, FollowAccept,
@ -61,4 +62,5 @@ export type KnownEntity =
| FollowReject | FollowReject
| Unfollow | Unfollow
| Delete | Delete
| LikeExtension; | LikeExtension
| Collection;