privchat_protocol/rpc/file/upload.rs
1// Copyright 2025 Shanghai Boyu Information Technology Co., Ltd.
2// https://privchat.dev
3//
4// Author: zoujiaqing <zoujiaqing@gmail.com>
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18/// 文件上传相关 RPC
19use serde::{Deserialize, Serialize};
20
21/// 请求上传令牌请求
22///
23/// RPC路由: `file/request_upload_token`
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct FileRequestUploadTokenRequest {
26 /// 用户ID
27 pub user_id: u64,
28 /// 文件名
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub filename: Option<String>,
31 /// 文件大小(字节)
32 pub file_size: i64,
33 /// 文件MIME类型
34 pub mime_type: String,
35 /// 文件类型 (image/video/audio/file/other)
36 pub file_type: String,
37 /// 业务类型 (message/avatar/group_avatar等)
38 pub business_type: String,
39}
40
41/// 上传回调请求
42///
43/// RPC路由: `file/upload_callback`
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct FileUploadCallbackRequest {
46 /// 文件ID
47 pub file_id: String,
48 /// 用户ID
49 pub user_id: u64,
50 /// 上传状态
51 pub status: String,
52}
53
54/// 请求上传令牌响应
55///
56/// RPC路由: `file/request_upload_token`
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct FileRequestUploadTokenResponse {
59 pub token: String,
60 pub upload_url: String,
61 pub file_id: String,
62}
63
64/// 上传回调响应
65///
66/// RPC路由: `file/upload_callback`
67/// 简单操作,返回 true(成功/失败由协议层 code 处理)
68pub type FileUploadCallbackResponse = bool;