@@ -171,6 +171,8 @@ pub enum TagKind {
171
171
Title ,
172
172
/// Image (NIP23)
173
173
Image ,
174
+ /// Thumbnail
175
+ Thumb ,
174
176
/// Summary (NIP23)
175
177
Summary ,
176
178
/// PublishedAt (NIP23)
@@ -212,6 +214,7 @@ impl fmt::Display for TagKind {
212
214
Self :: Challenge => write ! ( f, "challenge" ) ,
213
215
Self :: Title => write ! ( f, "title" ) ,
214
216
Self :: Image => write ! ( f, "image" ) ,
217
+ Self :: Thumb => write ! ( f, "thumb" ) ,
215
218
Self :: Summary => write ! ( f, "summary" ) ,
216
219
Self :: PublishedAt => write ! ( f, "published_at" ) ,
217
220
Self :: Description => write ! ( f, "description" ) ,
@@ -249,6 +252,7 @@ where
249
252
"challenge" => Self :: Challenge ,
250
253
"title" => Self :: Title ,
251
254
"image" => Self :: Image ,
255
+ "thumb" => Self :: Thumb ,
252
256
"summary" => Self :: Summary ,
253
257
"published_at" => Self :: PublishedAt ,
254
258
"description" => Self :: Description ,
@@ -305,6 +309,7 @@ pub enum Tag {
305
309
Challenge ( String ) ,
306
310
Title ( String ) ,
307
311
Image ( String , Option < ( u64 , u64 ) > ) ,
312
+ Thumb ( String , Option < ( u64 , u64 ) > ) ,
308
313
Summary ( String ) ,
309
314
Description ( String ) ,
310
315
Bolt11 ( String ) ,
@@ -354,6 +359,7 @@ impl Tag {
354
359
Tag :: Challenge ( ..) => TagKind :: Challenge ,
355
360
Tag :: Title ( ..) => TagKind :: Title ,
356
361
Tag :: Image ( ..) => TagKind :: Image ,
362
+ Tag :: Thumb ( ..) => TagKind :: Thumb ,
357
363
Tag :: Summary ( ..) => TagKind :: Summary ,
358
364
Tag :: PublishedAt ( ..) => TagKind :: PublishedAt ,
359
365
Tag :: Description ( ..) => TagKind :: Description ,
@@ -411,7 +417,8 @@ where
411
417
TagKind :: Subject => Ok ( Self :: Subject ( content. to_string ( ) ) ) ,
412
418
TagKind :: Challenge => Ok ( Self :: Challenge ( content. to_string ( ) ) ) ,
413
419
TagKind :: Title => Ok ( Self :: Title ( content. to_string ( ) ) ) ,
414
- TagKind :: Image => Ok ( Self :: Image ( content. to_string ( ) ) ) ,
420
+ TagKind :: Image => Ok ( Self :: Image ( content. to_string ( ) , None ) ) ,
421
+ TagKind :: Thumb => Ok ( Self :: Thumb ( content. to_string ( ) , None ) ) ,
415
422
TagKind :: Summary => Ok ( Self :: Summary ( content. to_string ( ) ) ) ,
416
423
TagKind :: PublishedAt => Ok ( Self :: PublishedAt ( Timestamp :: from_str ( content) ?) ) ,
417
424
TagKind :: Description => Ok ( Self :: Description ( content. to_string ( ) ) ) ,
@@ -470,6 +477,26 @@ where
470
477
Err ( Error :: InvalidLength )
471
478
}
472
479
}
480
+ TagKind :: Image => {
481
+ let image = tag[ 1 ] . clone ( ) ;
482
+ let dimensions: Vec < & str > = tag[ 2 ] . split ( 'x' ) . collect ( ) ;
483
+ if dimensions. len ( ) == 2 {
484
+ let ( width, height) = ( dimensions[ 0 ] , dimensions[ 1 ] ) ;
485
+ Ok ( Self :: Image ( image, Some ( ( width. parse ( ) ?, height. parse ( ) ?) ) ) )
486
+ } else {
487
+ Err ( Error :: InvalidLength )
488
+ }
489
+ }
490
+ TagKind :: Thumb => {
491
+ let thumb = tag[ 1 ] . clone ( ) ;
492
+ let dimensions: Vec < & str > = tag[ 2 ] . split ( 'x' ) . collect ( ) ;
493
+ if dimensions. len ( ) == 2 {
494
+ let ( width, height) = ( dimensions[ 0 ] , dimensions[ 1 ] ) ;
495
+ Ok ( Self :: Thumb ( thumb, Some ( ( width. parse ( ) ?, height. parse ( ) ?) ) ) )
496
+ } else {
497
+ Err ( Error :: InvalidLength )
498
+ }
499
+ }
473
500
_ => Ok ( Self :: Generic ( tag_kind, tag[ 1 ..] . to_vec ( ) ) ) ,
474
501
}
475
502
} else if tag_len == 4 {
@@ -587,7 +614,22 @@ impl From<Tag> for Vec<String> {
587
614
Tag :: Subject ( sub) => vec ! [ TagKind :: Subject . to_string( ) , sub] ,
588
615
Tag :: Challenge ( challenge) => vec ! [ TagKind :: Challenge . to_string( ) , challenge] ,
589
616
Tag :: Title ( title) => vec ! [ TagKind :: Title . to_string( ) , title] ,
590
- Tag :: Image ( image) => vec ! [ TagKind :: Image . to_string( ) , image] ,
617
+ Tag :: Image ( image, dimensions) => match dimensions {
618
+ None => vec ! [ TagKind :: Image . to_string( ) , image] ,
619
+ Some ( ( width, height) ) => vec ! [
620
+ TagKind :: Image . to_string( ) ,
621
+ image,
622
+ format!( "{}x{}" , height, width) ,
623
+ ] ,
624
+ } ,
625
+ Tag :: Thumb ( thumb, dimensions) => match dimensions {
626
+ None => vec ! [ TagKind :: Thumb . to_string( ) , thumb] ,
627
+ Some ( ( width, height) ) => vec ! [
628
+ TagKind :: Thumb . to_string( ) ,
629
+ thumb,
630
+ format!( "{}x{}" , height, width) ,
631
+ ] ,
632
+ } ,
591
633
Tag :: Summary ( summary) => vec ! [ TagKind :: Summary . to_string( ) , summary] ,
592
634
Tag :: PublishedAt ( timestamp) => {
593
635
vec ! [ TagKind :: PublishedAt . to_string( ) , timestamp. to_string( ) ]
0 commit comments