1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
use Bytes;
use crateUploadResumeInfo;
use crate::;
use async_trait;
/// Context for upload prepare stage.
/// Context for upload chunk stage.
///
/// [`UploadChunkCtx::chunk`] is a [`bytes::Bytes`] handle. Cloning it is an
/// O(1) refcount bump, and passing it into [`reqwest::Body`] never copies the
/// underlying buffer. This lets protocol implementations send the same chunk
/// multiple times (for example during retries) without re-allocating.
/// Custom breakpoint upload protocol.
///
/// Implementors are responsible for request construction and response parsing.
/// The executor handles file I/O, chunking, retries, progress, and scheduling.
///
/// # Examples
///
/// ```no_run
/// use async_trait::async_trait;
/// use rusty_cat::api::{
/// BreakpointUpload, MeowError, UploadChunkCtx, UploadPrepareCtx, UploadResumeInfo,
/// };
///
/// struct MyUploadProtocol;
///
/// #[async_trait]
/// impl BreakpointUpload for MyUploadProtocol {
/// async fn prepare(&self, _ctx: UploadPrepareCtx<'_>) -> Result<UploadResumeInfo, MeowError> {
/// Ok(UploadResumeInfo::default())
/// }
///
/// async fn upload_chunk(&self, ctx: UploadChunkCtx<'_>) -> Result<UploadResumeInfo, MeowError> {
/// let _ = (ctx.task.file_name(), ctx.offset);
/// Ok(UploadResumeInfo {
/// completed_file_id: None,
/// next_byte: Some(ctx.offset + ctx.chunk.len() as u64),
/// })
/// }
/// }
/// ```
///
/// # Executor integration contract
///
/// - If [`UploadResumeInfo::completed_file_id`] is `Some`, the executor treats
/// the upload as fully completed and stops sending further chunks.
/// - [`UploadResumeInfo::next_byte`] is a server-suggested next offset; the
/// executor merges it with local offset before continuing.
/// - When computed next offset reaches `task.total_size()`, the executor calls
/// [`BreakpointUpload::complete_upload`] unless completion was already
/// indicated by `completed_file_id`.
/// - When user cancels an upload task, executor calls
/// [`BreakpointUpload::abort_upload`].