@@ -139,15 +139,19 @@ impl Timeline {
139
139
}
140
140
141
141
fn build_thumbnail_info (
142
- thumbnail_path : Option < String > ,
142
+ thumbnail_source : Option < UploadSource > ,
143
143
thumbnail_info : Option < ThumbnailInfo > ,
144
144
) -> Result < Option < Thumbnail > , RoomError > {
145
- match ( thumbnail_path , thumbnail_info) {
145
+ match ( thumbnail_source , thumbnail_info) {
146
146
( None , None ) => Ok ( None ) ,
147
147
148
- ( Some ( thumbnail_path) , Some ( thumbnail_info) ) => {
149
- let thumbnail_data =
150
- fs:: read ( thumbnail_path) . map_err ( |_| RoomError :: InvalidThumbnailData ) ?;
148
+ ( Some ( thumbnail_source) , Some ( thumbnail_info) ) => {
149
+ let thumbnail_data = match thumbnail_source {
150
+ UploadSource :: File { filename } => {
151
+ fs:: read ( filename) . map_err ( |_| RoomError :: InvalidThumbnailData ) ?
152
+ }
153
+ UploadSource :: Data { bytes, .. } => bytes,
154
+ } ;
151
155
152
156
let height = thumbnail_info
153
157
. height
@@ -177,7 +181,7 @@ fn build_thumbnail_info(
177
181
}
178
182
179
183
_ => {
180
- warn ! ( "Ignoring thumbnail because either the thumbnail path or info isn't defined" ) ;
184
+ warn ! ( "Ignoring thumbnail because either the thumbnail source or info isn't defined" ) ;
181
185
Ok ( None )
182
186
}
183
187
}
@@ -380,26 +384,26 @@ impl Timeline {
380
384
pub fn send_image (
381
385
self : Arc < Self > ,
382
386
params : UploadParameters ,
383
- thumbnail_path : Option < String > ,
387
+ thumbnail_source : Option < UploadSource > ,
384
388
image_info : ImageInfo ,
385
389
) -> Result < Arc < SendAttachmentJoinHandle > , RoomError > {
386
390
let attachment_info = AttachmentInfo :: Image (
387
391
BaseImageInfo :: try_from ( & image_info) . map_err ( |_| RoomError :: InvalidAttachmentData ) ?,
388
392
) ;
389
- let thumbnail = build_thumbnail_info ( thumbnail_path , image_info. thumbnail_info ) ?;
393
+ let thumbnail = build_thumbnail_info ( thumbnail_source , image_info. thumbnail_info ) ?;
390
394
self . send_attachment ( params, attachment_info, image_info. mimetype , thumbnail)
391
395
}
392
396
393
397
pub fn send_video (
394
398
self : Arc < Self > ,
395
399
params : UploadParameters ,
396
- thumbnail_path : Option < String > ,
400
+ thumbnail_source : Option < UploadSource > ,
397
401
video_info : VideoInfo ,
398
402
) -> Result < Arc < SendAttachmentJoinHandle > , RoomError > {
399
403
let attachment_info = AttachmentInfo :: Video (
400
404
BaseVideoInfo :: try_from ( & video_info) . map_err ( |_| RoomError :: InvalidAttachmentData ) ?,
401
405
) ;
402
- let thumbnail = build_thumbnail_info ( thumbnail_path , video_info. thumbnail_info ) ?;
406
+ let thumbnail = build_thumbnail_info ( thumbnail_source , video_info. thumbnail_info ) ?;
403
407
self . send_attachment ( params, attachment_info, video_info. mimetype , thumbnail)
404
408
}
405
409
@@ -1336,14 +1340,14 @@ mod galleries {
1336
1340
source : UploadSource ,
1337
1341
caption : Option < String > ,
1338
1342
formatted_caption : Option < FormattedBody > ,
1339
- thumbnail_path : Option < String > ,
1343
+ thumbnail_source : Option < UploadSource > ,
1340
1344
} ,
1341
1345
Video {
1342
1346
video_info : VideoInfo ,
1343
1347
source : UploadSource ,
1344
1348
caption : Option < String > ,
1345
1349
formatted_caption : Option < FormattedBody > ,
1346
- thumbnail_path : Option < String > ,
1350
+ thumbnail_source : Option < UploadSource > ,
1347
1351
} ,
1348
1352
}
1349
1353
@@ -1408,11 +1412,17 @@ mod galleries {
1408
1412
fn thumbnail ( & self ) -> Result < Option < Thumbnail > , RoomError > {
1409
1413
match self {
1410
1414
GalleryItemInfo :: Audio { .. } | GalleryItemInfo :: File { .. } => Ok ( None ) ,
1411
- GalleryItemInfo :: Image { image_info, thumbnail_path, .. } => {
1412
- build_thumbnail_info ( thumbnail_path. clone ( ) , image_info. thumbnail_info . clone ( ) )
1415
+ GalleryItemInfo :: Image { image_info, thumbnail_source, .. } => {
1416
+ build_thumbnail_info (
1417
+ thumbnail_source. as_ref ( ) . cloned ( ) ,
1418
+ image_info. thumbnail_info . clone ( ) ,
1419
+ )
1413
1420
}
1414
- GalleryItemInfo :: Video { video_info, thumbnail_path, .. } => {
1415
- build_thumbnail_info ( thumbnail_path. clone ( ) , video_info. thumbnail_info . clone ( ) )
1421
+ GalleryItemInfo :: Video { video_info, thumbnail_source, .. } => {
1422
+ build_thumbnail_info (
1423
+ thumbnail_source. as_ref ( ) . cloned ( ) ,
1424
+ video_info. thumbnail_info . clone ( ) ,
1425
+ )
1416
1426
}
1417
1427
}
1418
1428
}
0 commit comments