@@ -10,6 +10,19 @@ const makebuffer = (raw) => {
10
10
realLength -- ;
11
11
return b . subarray ( 0 , realLength ) ;
12
12
} ;
13
+
14
+ function formatBytes ( bytes , decimals = 2 ) {
15
+ if ( bytes === 0 ) return '0 Bytes' ;
16
+
17
+ const k = 1024 ;
18
+ const dm = decimals < 0 ? 0 : decimals ;
19
+ const sizes = [ 'Bytes' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] ;
20
+
21
+ const i = Math . floor ( Math . log ( bytes ) / Math . log ( k ) ) ;
22
+
23
+ return parseFloat ( ( bytes / Math . pow ( k , i ) ) . toFixed ( dm ) ) + ' ' + sizes [ i ] ;
24
+ }
25
+
13
26
const setup = async ( ) => {
14
27
const elem = document . getElementById ( "messages" ) ;
15
28
if ( elem )
@@ -53,14 +66,15 @@ const setup = async () => {
53
66
}
54
67
55
68
const plain = Message . decode ( data ) . dataMessage ;
56
- console . log ( "VERIFY:" )
57
- console . log ( data )
58
- console . log ( Message . decode ( data ) )
59
- console . log ( Message . decode ( data ) . dataMessage )
60
- console . log ( Message )
61
- console . log ( Message . verify )
62
- console . log ( Message . verify ( data ) )
63
- // if msg is a reply
69
+ // console.log("VERIFY:")
70
+ // console.log(data)
71
+ // console.log(Message.decode(data))
72
+ // console.log(Message.decode(data).dataMessage)
73
+ // console.log(Message)
74
+ // console.log(Message.verify)
75
+ // console.log(Message.verify(data))
76
+
77
+ // reply
64
78
if ( plain . quote ) {
65
79
originalMsg = document . createElement ( 'p' ) ;
66
80
originalMsg . classList . add ( 'text-sm' , 'italic' , 'border-l-2' , 'border-sessionGreen' , 'pl-2' ) ;
@@ -72,9 +86,29 @@ const setup = async () => {
72
86
originalMsg . appendChild ( document . createTextNode ( "..." + authorId + ": " + plain . quote . text ) ) ;
73
87
e . appendChild ( originalMsg ) ;
74
88
}
89
+
90
+ // message body
75
91
e . appendChild ( document . createTextNode ( plain . profile . displayName + ": " + plain . body ) ) ;
76
92
e . classList . add ( 'bg-gray-300' , 'dark:bg-lightGray' , 'w-fit' , 'rounded-lg' , 'p-2' , 'my-2' )
77
93
elem . appendChild ( e ) ;
94
+
95
+ // attachments
96
+ if ( plain . attachments . length > 0 ) {
97
+ plain . attachments . forEach ( attachment => {
98
+ console . log ( attachment ) ;
99
+ attachmentElement = document . createElement ( 'p' ) ;
100
+ attachmentElement . appendChild ( document . createTextNode ( "📎\xa0\xa0\xa0" ) ) ;
101
+
102
+ attachmentLink = document . createElement ( 'a' ) ;
103
+ attachmentLink . appendChild ( document . createTextNode ( ( attachment . fileName || attachment . contentType ) + ` (${ formatBytes ( attachment . size ) } )` ) ) ;
104
+ attachmentLink . href = attachment . url ;
105
+ attachmentLink . download = ( attachment . fileName || "" ) ;
106
+
107
+ attachmentElement . appendChild ( attachmentLink ) ;
108
+ attachmentElement . classList . add ( 'text-sm' , 'italic' , 'pl-1' ) ;
109
+ e . appendChild ( attachmentElement ) ;
110
+ } ) ;
111
+ }
78
112
79
113
}
80
114
catch ( ex )
0 commit comments