Handle delivered JSONs as opaque objects to remove the need for repeated serialization
ci/woodpecker/tag/ociImageTag Pipeline was successful Details

This commit is contained in:
Natty 2024-12-19 17:26:02 +01:00
parent dc058741d1
commit c9feae3a28
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
5 changed files with 17 additions and 23 deletions

View File

@ -169,7 +169,7 @@ export async function magApGet(userId: string, url: string): Promise<any> {
});
}
export async function magApPost(userId: string, url: string, body: any): Promise<any> {
export async function magApPost(userId: string, url: string, body: string): Promise<any> {
logger.debug(`AP POST to: ${url}`);
return await rpcCall("/ap/post", {
user_id: userId,

View File

@ -18,14 +18,14 @@ import {endedPollNotification} from "./processors/ended-poll-notification.js";
import {queueLogger} from "./logger.js";
import {getJobInfo} from "./get-job-info.js";
import {
backgroundQueue,
dbQueue,
deliverQueue,
endedPollNotificationQueue,
inboxQueue,
objectStorageQueue,
systemQueue,
webhookDeliverQueue,
backgroundQueue,
dbQueue,
deliverQueue,
endedPollNotificationQueue,
inboxQueue,
objectStorageQueue,
systemQueue,
webhookDeliverQueue,
} from "./queues.js";
import type {ThinUser} from "./types.js";
@ -165,7 +165,7 @@ export function deliver(user: ThinUser, content: unknown, to: string | null) {
user: {
id: user.id,
},
content,
content: JSON.stringify(content, null, 2),
to,
};

View File

@ -13,8 +13,6 @@ import type Bull from "bull";
const logger = new Logger("deliver");
let latest: string | null = null;
export default async (job: Bull.Job<DeliverJobData>) => {
let host: string;
try {
@ -29,10 +27,6 @@ export default async (job: Bull.Job<DeliverJobData>) => {
if (await shouldSkipInstance(puny)) return "skip";
try {
if (latest !== (latest = JSON.stringify(job.data.content, null, 2))) {
logger.debug(`delivering ${latest}`);
}
await request(job.data.user, job.data.to, job.data.content);
// Update stats

View File

@ -1,15 +1,15 @@
import type { DriveFile } from "@/models/entities/drive-file.js";
import type { Note } from "@/models/entities/note";
import type { User } from "@/models/entities/user.js";
import type { Webhook } from "@/models/entities/webhook";
import type { IActivity } from "@/remote/activitypub/type.js";
import type {DriveFile} from "@/models/entities/drive-file.js";
import type {Note} from "@/models/entities/note";
import type {User} from "@/models/entities/user.js";
import type {Webhook} from "@/models/entities/webhook";
import type {IActivity} from "@/remote/activitypub/type.js";
import type httpSignature from "@peertube/http-signature";
export type DeliverJobData = {
/** Actor */
user: ThinUser;
/** Activity */
content: unknown;
content: string;
/** inbox URL to deliver */
to: string;
};

View File

@ -1,7 +1,7 @@
import type {User} from "@/models/entities/user.js";
import {magApGet, magApPost} from "@/mag/rpc-client.js";
export default async (user: { id: User["id"] }, url: string, body: any) => {
export default async (user: { id: User["id"] }, url: string, body: string) => {
return await magApPost(user.id, url, body);
};