Skip to main content

swarmhive_api_types/
upload.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4use utoipa::ToSchema;
5use uuid::Uuid;
6
7use crate::platform::Platform;
8use crate::release::ReleaseStatus;
9
10/// 客户端打算上传的一个文件,带预先算好的 sha256 + md5 和平台分类
11/// (用于推导对象键 + artifact 行)。
12#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
13pub struct PresignFile {
14    pub relative_path: String,
15    pub size: i64,
16    pub expected_sha256: String,
17    /// 文件的 hex MD5。会绑成预签名 PUT 的 `Content-MD5` 头,让所有 S3 兼容后端
18    /// ——包括不支持 AWS additional checksum(`x-amz-checksum-sha256`)的阿里云
19    /// OSS——在写入时强制校验传输完整性。
20    pub expected_md5: String,
21    pub platform: Platform,
22    #[serde(default)]
23    pub target: Option<String>,
24    #[serde(default)]
25    pub arch: Option<String>,
26    #[serde(default)]
27    pub abi: Option<String>,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
31pub struct PresignRequest {
32    pub files: Vec<PresignFile>,
33}
34
35/// 单个文件的预签名 PUT。`headers` 必须原样发到 PUT 上——它们携带 `Content-MD5`
36/// (以及后端支持时的 `x-amz-checksum-sha256`),让对象存储强制校验、拒绝损坏的 body。
37#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
38pub struct PresignPart {
39    pub object_key: String,
40    pub presigned_url: String,
41    pub headers: BTreeMap<String, String>,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
45pub struct PresignResponse {
46    pub upload_id: Uuid,
47    pub parts: Vec<PresignPart>,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
51pub struct CompletePart {
52    pub object_key: String,
53    pub sha256: String,
54    #[serde(default)]
55    pub etag: Option<String>,
56    /// 该产物的签名文本(Tauri `.sig` 内容)。非空时 server 写入 artifact 的
57    /// `signature_metadata`。CLI 不发该字段,故 `#[serde(default)]` 向后兼容。
58    #[serde(default)]
59    pub signature: Option<String>,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
63pub struct CompleteRequest {
64    pub parts: Vec<CompletePart>,
65    /// 为 true 时发布该 release(需 `release:publish`)。
66    #[serde(default)]
67    pub publish: bool,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
71pub struct CompleteResponse {
72    pub release_id: Uuid,
73    pub status: ReleaseStatus,
74    /// 各平台的更新检查 / 下载入口 URL,以平台为 key。
75    pub endpoints: BTreeMap<String, String>,
76}