Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kernel API for publish binary message broadcast #13681

Merged
merged 2 commits into from
Dec 31, 2024

Conversation

Zuoqiu-Yingyi
Copy link
Contributor

REL: #9031

当前广播消息推送 API /api/broadcast/postMessage 不支持广播二进制消息,且每次仅能向一个信道广播一条消息,不能完全满足社区开发需求
Currently, the broadcast message push API /api/broadcast/postMessage does not support broadcasting binary messages, and can only broadcast one message at a time, which cannot fully meet the needs

新增内核 API /api/broadcast/publish,用户可以使用 FormData 在一次请求中向多个不同的信道广播多个字符串&二进制消息
The new kernel API /api/broadcast/publish allows users to broadcast multiple string & binary messages to multiple different channels in a single request using the FormData

使用示例 | Examples:

const formData = new FormData();
formData.append("channel-1", "string-message-1-1");
formData.append("channel-1", "string-message-1-2");

formData.append("channel-1", new Blob(["binary-message-1-1"]));
formData.append("channel-1", new Blob(["binary-message-1-2"]), "specified-filename-1-2");

formData.append("channel-2", "string-message-2-1");
formData.append("channel-2", "string-message-2-2");

formData.append("channel-2", new File(["binary-message-2-2"], "filename-2-1"));
formData.append("channel-2", new File(["binary-message-2-2"], "filename-2-2"), "specified-filename-2-2");

fetch("/api/broadcast/publish", {
    method: "POST",
    body: formData,
}).then(async response => {
    console.log(await response.json());
});

示例运行结果 | Example results:

{
    "code": 0,
    "msg": "",
    "data": {
        "results": [
            {
                "code": 0,
                "msg": "",
                "channel": {
                    "name": "channel-1",
                    "count": 0
                },
                "message": {
                    "type": "string",
                    "size": 18,
                    "filename": ""
                }
            },
            {
                "code": 0,
                "msg": "",
                "channel": {
                    "name": "channel-1",
                    "count": 0
                },
                "message": {
                    "type": "string",
                    "size": 18,
                    "filename": ""
                }
            },
            {
                "code": 0,
                "msg": "",
                "channel": {
                    "name": "channel-2",
                    "count": 0
                },
                "message": {
                    "type": "string",
                    "size": 18,
                    "filename": ""
                }
            },
            {
                "code": 0,
                "msg": "",
                "channel": {
                    "name": "channel-2",
                    "count": 0
                },
                "message": {
                    "type": "string",
                    "size": 18,
                    "filename": ""
                }
            },
            {
                "code": 0,
                "msg": "",
                "channel": {
                    "name": "channel-1",
                    "count": 0
                },
                "message": {
                    "type": "binary",
                    "size": 18,
                    "filename": "blob"
                }
            },
            {
                "code": 0,
                "msg": "",
                "channel": {
                    "name": "channel-1",
                    "count": 0
                },
                "message": {
                    "type": "binary",
                    "size": 18,
                    "filename": "specified-filename-1-2"
                }
            },
            {
                "code": 0,
                "msg": "",
                "channel": {
                    "name": "channel-2",
                    "count": 0
                },
                "message": {
                    "type": "binary",
                    "size": 18,
                    "filename": "filename-2-1"
                }
            },
            {
                "code": 0,
                "msg": "",
                "channel": {
                    "name": "channel-2",
                    "count": 0
                },
                "message": {
                    "type": "binary",
                    "size": 18,
                    "filename": "specified-filename-2-2"
                }
            }
        ]
    }
}

已测试 | Tested

@Zuoqiu-Yingyi Zuoqiu-Yingyi marked this pull request as ready for review December 31, 2024 09:19
@88250 88250 added this to the 3.1.19 milestone Dec 31, 2024
@88250 88250 merged commit 3807f83 into siyuan-note:dev Dec 31, 2024
1 check passed
@88250
Copy link
Member

88250 commented Dec 31, 2024

感谢你的贡献,思源有你更精彩!
Thank you for your contribution. SiYuan will be more wonderful with you!

@Zuoqiu-Yingyi Zuoqiu-Yingyi deleted the feat/broadcast-publish branch December 31, 2024 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants