refactor (backend): port publishNoteUpdatesStream to backend-rs
This commit is contained in:
parent
3f1cf90ff3
commit
7d2e98963d
9 changed files with 38 additions and 25 deletions
2
packages/backend-rs/index.d.ts
vendored
2
packages/backend-rs/index.d.ts
vendored
|
@ -1117,6 +1117,8 @@ export declare function publishToModerationStream(moderatorId: string, report: A
|
||||||
|
|
||||||
export declare function publishToNotesStream(note: Note): Promise<void>
|
export declare function publishToNotesStream(note: Note): Promise<void>
|
||||||
|
|
||||||
|
export declare function publishToNoteUpdatesStream(note: Note): Promise<void>
|
||||||
|
|
||||||
export interface PugArgs {
|
export interface PugArgs {
|
||||||
img: string | null
|
img: string | null
|
||||||
title: string
|
title: string
|
||||||
|
|
|
@ -424,6 +424,7 @@ module.exports.publishToDriveFolderStream = nativeBinding.publishToDriveFolderSt
|
||||||
module.exports.publishToGroupChatStream = nativeBinding.publishToGroupChatStream
|
module.exports.publishToGroupChatStream = nativeBinding.publishToGroupChatStream
|
||||||
module.exports.publishToModerationStream = nativeBinding.publishToModerationStream
|
module.exports.publishToModerationStream = nativeBinding.publishToModerationStream
|
||||||
module.exports.publishToNotesStream = nativeBinding.publishToNotesStream
|
module.exports.publishToNotesStream = nativeBinding.publishToNotesStream
|
||||||
|
module.exports.publishToNoteUpdatesStream = nativeBinding.publishToNoteUpdatesStream
|
||||||
module.exports.PushNotificationKind = nativeBinding.PushNotificationKind
|
module.exports.PushNotificationKind = nativeBinding.PushNotificationKind
|
||||||
module.exports.PushSubscriptionType = nativeBinding.PushSubscriptionType
|
module.exports.PushSubscriptionType = nativeBinding.PushSubscriptionType
|
||||||
module.exports.RelayStatus = nativeBinding.RelayStatus
|
module.exports.RelayStatus = nativeBinding.RelayStatus
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub mod custom_emoji;
|
||||||
pub mod drive;
|
pub mod drive;
|
||||||
pub mod group_chat;
|
pub mod group_chat;
|
||||||
pub mod moderation;
|
pub mod moderation;
|
||||||
|
pub mod note_edit;
|
||||||
pub mod notes;
|
pub mod notes;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -30,6 +31,7 @@ pub enum Stream {
|
||||||
note_id: String,
|
note_id: String,
|
||||||
},
|
},
|
||||||
Notes,
|
Notes,
|
||||||
|
NoteEdit,
|
||||||
UserList {
|
UserList {
|
||||||
list_id: String,
|
list_id: String,
|
||||||
},
|
},
|
||||||
|
@ -86,6 +88,7 @@ pub async fn publish_to_stream(
|
||||||
Stream::User { user_id } => format!("user:{user_id}"),
|
Stream::User { user_id } => format!("user:{user_id}"),
|
||||||
Stream::Channel { channel_id } => format!("channelStream:{channel_id}"),
|
Stream::Channel { channel_id } => format!("channelStream:{channel_id}"),
|
||||||
Stream::Note { note_id } => format!("noteStream:{note_id}"),
|
Stream::Note { note_id } => format!("noteStream:{note_id}"),
|
||||||
|
Stream::NoteEdit => format!("noteUpdatesStream"),
|
||||||
Stream::Notes => "notesStream".to_owned(),
|
Stream::Notes => "notesStream".to_owned(),
|
||||||
Stream::UserList { list_id } => format!("userListStream:{list_id}"),
|
Stream::UserList { list_id } => format!("userListStream:{list_id}"),
|
||||||
Stream::Main { user_id } => format!("mainStream:{user_id}"),
|
Stream::Main { user_id } => format!("mainStream:{user_id}"),
|
||||||
|
|
18
packages/backend-rs/src/service/stream/note_edit.rs
Normal file
18
packages/backend-rs/src/service/stream/note_edit.rs
Normal 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
|
||||||
|
}
|
|
@ -18,7 +18,6 @@ export const DB_MAX_NOTE_TEXT_LENGTH = 100000;
|
||||||
*/
|
*/
|
||||||
export const DB_MAX_IMAGE_COMMENT_LENGTH = 8192;
|
export const DB_MAX_IMAGE_COMMENT_LENGTH = 8192;
|
||||||
|
|
||||||
|
|
||||||
export const MAX_NOTE_TEXT_LENGTH = Math.min(
|
export const MAX_NOTE_TEXT_LENGTH = Math.min(
|
||||||
config.maxNoteLength ?? 3000,
|
config.maxNoteLength ?? 3000,
|
||||||
DB_MAX_NOTE_TEXT_LENGTH,
|
DB_MAX_NOTE_TEXT_LENGTH,
|
||||||
|
|
|
@ -44,9 +44,5 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
return 204;
|
return 204;
|
||||||
}
|
}
|
||||||
|
|
||||||
return translate(
|
return translate(note.text, note.lang as string | null, ps.targetLang);
|
||||||
note.text,
|
|
||||||
note.lang as string | null,
|
|
||||||
ps.targetLang,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,11 +6,7 @@ import type S3 from "aws-sdk/clients/s3.js"; // TODO: migrate to SDK v3
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import { publishMainStream } from "@/services/stream.js";
|
import { publishMainStream } from "@/services/stream.js";
|
||||||
import {
|
import { fetchMeta, genId, publishToDriveFileStream } from "backend-rs";
|
||||||
fetchMeta,
|
|
||||||
genId,
|
|
||||||
publishToDriveFileStream,
|
|
||||||
} from "backend-rs";
|
|
||||||
import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
|
import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
|
||||||
import { contentDisposition } from "@/misc/content-disposition.js";
|
import { contentDisposition } from "@/misc/content-disposition.js";
|
||||||
import { getFileInfo } from "@/misc/get-file-info.js";
|
import { getFileInfo } from "@/misc/get-file-info.js";
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
import * as mfm from "mfm-js";
|
import * as mfm from "mfm-js";
|
||||||
import {
|
import { publishNoteStream } from "@/services/stream.js";
|
||||||
publishNoteStream,
|
|
||||||
publishNoteUpdatesStream,
|
|
||||||
} from "@/services/stream.js";
|
|
||||||
import DeliverManager from "@/remote/activitypub/deliver-manager.js";
|
import DeliverManager from "@/remote/activitypub/deliver-manager.js";
|
||||||
import renderNote from "@/remote/activitypub/renderer/note.js";
|
import renderNote from "@/remote/activitypub/renderer/note.js";
|
||||||
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||||
|
@ -21,7 +18,7 @@ import {
|
||||||
import type { DriveFile } from "@/models/entities/drive-file.js";
|
import type { DriveFile } from "@/models/entities/drive-file.js";
|
||||||
import { In } from "typeorm";
|
import { In } from "typeorm";
|
||||||
import type { ILocalUser, IRemoteUser } from "@/models/entities/user.js";
|
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 type { IPoll } from "@/models/entities/poll.js";
|
||||||
import { deliverToRelays } from "../relay.js";
|
import { deliverToRelays } from "../relay.js";
|
||||||
import renderUpdate from "@/remote/activitypub/renderer/update.js";
|
import renderUpdate from "@/remote/activitypub/renderer/update.js";
|
||||||
|
@ -194,7 +191,7 @@ export default async function (
|
||||||
updatedAt: update.updatedAt,
|
updatedAt: update.updatedAt,
|
||||||
});
|
});
|
||||||
|
|
||||||
publishNoteUpdatesStream("updated", note);
|
publishToNoteUpdatesStream(note);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const noteActivity = await renderNote(note, false);
|
const noteActivity = await renderNote(note, false);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import type {
|
||||||
NoteStreamTypes,
|
NoteStreamTypes,
|
||||||
UserListStreamTypes,
|
UserListStreamTypes,
|
||||||
UserStreamTypes,
|
UserStreamTypes,
|
||||||
NoteUpdatesStreamTypes,
|
// NoteUpdatesStreamTypes,
|
||||||
} from "@/server/api/stream/types.js";
|
} from "@/server/api/stream/types.js";
|
||||||
|
|
||||||
class Publisher {
|
class Publisher {
|
||||||
|
@ -113,12 +113,13 @@ class Publisher {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
public publishNoteUpdatesStream = <K extends keyof NoteUpdatesStreamTypes>(
|
/* ported to backend-rs */
|
||||||
type: K,
|
// public publishNoteUpdatesStream = <K extends keyof NoteUpdatesStreamTypes>(
|
||||||
value: NoteUpdatesStreamTypes[K],
|
// type: K,
|
||||||
): void => {
|
// value: NoteUpdatesStreamTypes[K],
|
||||||
this.publish("noteUpdatesStream", type, value);
|
// ): void => {
|
||||||
};
|
// this.publish("noteUpdatesStream", type, value);
|
||||||
|
// };
|
||||||
|
|
||||||
/* ported to backend-rs */
|
/* ported to backend-rs */
|
||||||
// public publishChannelStream = <K extends keyof ChannelStreamTypes>(
|
// public publishChannelStream = <K extends keyof ChannelStreamTypes>(
|
||||||
|
@ -232,7 +233,7 @@ export const publishMainStream = publisher.publishMainStream;
|
||||||
// export const publishDriveStream = publisher.publishDriveStream;
|
// export const publishDriveStream = publisher.publishDriveStream;
|
||||||
export const publishNoteStream = publisher.publishNoteStream;
|
export const publishNoteStream = publisher.publishNoteStream;
|
||||||
// export const publishNotesStream = publisher.publishNotesStream;
|
// export const publishNotesStream = publisher.publishNotesStream;
|
||||||
export const publishNoteUpdatesStream = publisher.publishNoteUpdatesStream;
|
// export const publishNoteUpdatesStream = publisher.publishNoteUpdatesStream;
|
||||||
// export const publishChannelStream = publisher.publishChannelStream;
|
// export const publishChannelStream = publisher.publishChannelStream;
|
||||||
export const publishUserListStream = publisher.publishUserListStream;
|
export const publishUserListStream = publisher.publishUserListStream;
|
||||||
// export const publishAntennaStream = publisher.publishAntennaStream;
|
// export const publishAntennaStream = publisher.publishAntennaStream;
|
||||||
|
|
Loading…
Reference in a new issue