refactor (backend): port publishNoteUpdatesStream to backend-rs

This commit is contained in:
naskya 2024-07-25 06:39:40 +09:00
parent 3f1cf90ff3
commit 7d2e98963d
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
9 changed files with 38 additions and 25 deletions

View file

@ -1117,6 +1117,8 @@ export declare function publishToModerationStream(moderatorId: string, report: A
export declare function publishToNotesStream(note: Note): Promise<void>
export declare function publishToNoteUpdatesStream(note: Note): Promise<void>
export interface PugArgs {
img: string | null
title: string

View file

@ -424,6 +424,7 @@ module.exports.publishToDriveFolderStream = nativeBinding.publishToDriveFolderSt
module.exports.publishToGroupChatStream = nativeBinding.publishToGroupChatStream
module.exports.publishToModerationStream = nativeBinding.publishToModerationStream
module.exports.publishToNotesStream = nativeBinding.publishToNotesStream
module.exports.publishToNoteUpdatesStream = nativeBinding.publishToNoteUpdatesStream
module.exports.PushNotificationKind = nativeBinding.PushNotificationKind
module.exports.PushSubscriptionType = nativeBinding.PushSubscriptionType
module.exports.RelayStatus = nativeBinding.RelayStatus

View file

@ -6,6 +6,7 @@ pub mod custom_emoji;
pub mod drive;
pub mod group_chat;
pub mod moderation;
pub mod note_edit;
pub mod notes;
use crate::{
@ -30,6 +31,7 @@ pub enum Stream {
note_id: String,
},
Notes,
NoteEdit,
UserList {
list_id: String,
},
@ -86,6 +88,7 @@ pub async fn publish_to_stream(
Stream::User { user_id } => format!("user:{user_id}"),
Stream::Channel { channel_id } => format!("channelStream:{channel_id}"),
Stream::Note { note_id } => format!("noteStream:{note_id}"),
Stream::NoteEdit => format!("noteUpdatesStream"),
Stream::Notes => "notesStream".to_owned(),
Stream::UserList { list_id } => format!("userListStream:{list_id}"),
Stream::Main { user_id } => format!("mainStream:{user_id}"),

View file

@ -0,0 +1,18 @@
use crate::{
model::entity::note,
service::stream::{publish_to_stream, Error, Stream},
};
// for napi export
// https://github.com/napi-rs/napi-rs/issues/2060
type Note = note::Model;
#[macros::export(js_name = "publishToNoteUpdatesStream")]
pub async fn publish(note: &Note) -> Result<(), Error> {
publish_to_stream(
&Stream::NoteEdit,
Some("updated"),
Some(serde_json::to_string(note)?),
)
.await
}

View file

@ -18,7 +18,6 @@ export const DB_MAX_NOTE_TEXT_LENGTH = 100000;
*/
export const DB_MAX_IMAGE_COMMENT_LENGTH = 8192;
export const MAX_NOTE_TEXT_LENGTH = Math.min(
config.maxNoteLength ?? 3000,
DB_MAX_NOTE_TEXT_LENGTH,

View file

@ -44,9 +44,5 @@ export default define(meta, paramDef, async (ps, user) => {
return 204;
}
return translate(
note.text,
note.lang as string | null,
ps.targetLang,
);
return translate(note.text, note.lang as string | null, ps.targetLang);
});

View file

@ -6,11 +6,7 @@ import type S3 from "aws-sdk/clients/s3.js"; // TODO: migrate to SDK v3
import sharp from "sharp";
import { IsNull } from "typeorm";
import { publishMainStream } from "@/services/stream.js";
import {
fetchMeta,
genId,
publishToDriveFileStream,
} from "backend-rs";
import { fetchMeta, genId, publishToDriveFileStream } from "backend-rs";
import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
import { contentDisposition } from "@/misc/content-disposition.js";
import { getFileInfo } from "@/misc/get-file-info.js";

View file

@ -1,8 +1,5 @@
import * as mfm from "mfm-js";
import {
publishNoteStream,
publishNoteUpdatesStream,
} from "@/services/stream.js";
import { publishNoteStream } from "@/services/stream.js";
import DeliverManager from "@/remote/activitypub/deliver-manager.js";
import renderNote from "@/remote/activitypub/renderer/note.js";
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
@ -21,7 +18,7 @@ import {
import type { DriveFile } from "@/models/entities/drive-file.js";
import { In } from "typeorm";
import type { ILocalUser, IRemoteUser } from "@/models/entities/user.js";
import { genId } from "backend-rs";
import { genId, publishToNoteUpdatesStream } from "backend-rs";
import type { IPoll } from "@/models/entities/poll.js";
import { deliverToRelays } from "../relay.js";
import renderUpdate from "@/remote/activitypub/renderer/update.js";
@ -194,7 +191,7 @@ export default async function (
updatedAt: update.updatedAt,
});
publishNoteUpdatesStream("updated", note);
publishToNoteUpdatesStream(note);
(async () => {
const noteActivity = await renderNote(note, false);

View file

@ -21,7 +21,7 @@ import type {
NoteStreamTypes,
UserListStreamTypes,
UserStreamTypes,
NoteUpdatesStreamTypes,
// NoteUpdatesStreamTypes,
} from "@/server/api/stream/types.js";
class Publisher {
@ -113,12 +113,13 @@ class Publisher {
});
};
public publishNoteUpdatesStream = <K extends keyof NoteUpdatesStreamTypes>(
type: K,
value: NoteUpdatesStreamTypes[K],
): void => {
this.publish("noteUpdatesStream", type, value);
};
/* ported to backend-rs */
// public publishNoteUpdatesStream = <K extends keyof NoteUpdatesStreamTypes>(
// type: K,
// value: NoteUpdatesStreamTypes[K],
// ): void => {
// this.publish("noteUpdatesStream", type, value);
// };
/* ported to backend-rs */
// public publishChannelStream = <K extends keyof ChannelStreamTypes>(
@ -232,7 +233,7 @@ export const publishMainStream = publisher.publishMainStream;
// export const publishDriveStream = publisher.publishDriveStream;
export const publishNoteStream = publisher.publishNoteStream;
// export const publishNotesStream = publisher.publishNotesStream;
export const publishNoteUpdatesStream = publisher.publishNoteUpdatesStream;
// export const publishNoteUpdatesStream = publisher.publishNoteUpdatesStream;
// export const publishChannelStream = publisher.publishChannelStream;
export const publishUserListStream = publisher.publishUserListStream;
// export const publishAntennaStream = publisher.publishAntennaStream;