@@ -98,14 +98,26 @@ app.patch(
9898 "source[privacy]" : z . enum ( [ "public" , "unlisted" , "private" ] ) . optional ( ) ,
9999 "source[sensitive]" : z . enum ( [ "true" , "false" ] ) . optional ( ) ,
100100 "source[language]" : z . string ( ) . optional ( ) ,
101- "fields_attributes[0][name]" : z . string ( ) . optional ( ) ,
102- "fields_attributes[0][value]" : z . string ( ) . optional ( ) ,
103- "fields_attributes[1][name]" : z . string ( ) . optional ( ) ,
104- "fields_attributes[1][value]" : z . string ( ) . optional ( ) ,
105- "fields_attributes[2][name]" : z . string ( ) . optional ( ) ,
106- "fields_attributes[2][value]" : z . string ( ) . optional ( ) ,
107- "fields_attributes[3][name]" : z . string ( ) . optional ( ) ,
108- "fields_attributes[3][value]" : z . string ( ) . optional ( ) ,
101+ "fields_attributes[0][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
102+ "fields_attributes[0][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
103+ "fields_attributes[1][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
104+ "fields_attributes[1][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
105+ "fields_attributes[2][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
106+ "fields_attributes[2][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
107+ "fields_attributes[3][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
108+ "fields_attributes[3][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
109+ "fields_attributes[4][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
110+ "fields_attributes[4][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
111+ "fields_attributes[5][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
112+ "fields_attributes[5][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
113+ "fields_attributes[6][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
114+ "fields_attributes[6][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
115+ "fields_attributes[7][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
116+ "fields_attributes[7][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
117+ "fields_attributes[8][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
118+ "fields_attributes[8][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
119+ "fields_attributes[9][name]" : z . string ( ) . max ( 255 ) . optional ( ) ,
120+ "fields_attributes[9][value]" : z . string ( ) . max ( 255 ) . optional ( ) ,
109121 } ) ,
110122 ) ,
111123 async ( c ) => {
@@ -167,23 +179,42 @@ app.patch(
167179 username : account . handle ,
168180 } ) ,
169181 } ;
170- const fields = Object . entries ( owner . fields ) ;
171- const fieldHtmls : [ string , string ] [ ] = [ ] ;
172- for ( const i of [ 0 , 1 , 2 , 3 ] as const ) {
182+ const fields : ( [ string , string ] | undefined ) [ ] = Object . entries (
183+ owner . fields ,
184+ ) ;
185+ let anyFieldAttributeSubmitted = false ;
186+ for ( const i of [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] as const ) {
173187 const name = form [ `fields_attributes[${ i } ][name]` ] ;
174188 const value = form [ `fields_attributes[${ i } ][value]` ] ;
189+ if ( name == null && value == null ) {
190+ continue ;
191+ }
192+ anyFieldAttributeSubmitted = true ;
175193 if (
176194 name == null ||
177195 name . trim ( ) === "" ||
178196 value == null ||
179197 value . trim ( ) === ""
180198 ) {
199+ fields [ i ] = undefined ;
181200 continue ;
182201 }
183202 fields [ i ] = [ name , value ] ;
184- const contentHtml = ( await formatText ( db , fields [ i ] [ 1 ] , fmtOpts ) ) . html ;
185- fieldHtmls . push ( [ fields [ i ] [ 0 ] , contentHtml ] ) ;
186203 }
204+ const denseFields = fields . filter ( ( f ) : f is [ string , string ] => f != null ) ;
205+ const fieldHtmlsRecord : Record < string , string > = anyFieldAttributeSubmitted
206+ ? Object . fromEntries (
207+ await Promise . all (
208+ denseFields . map (
209+ async ( [ fieldName , fieldValue ] ) =>
210+ [
211+ fieldName ,
212+ ( await formatText ( db , fieldValue , fmtOpts ) ) . html ,
213+ ] as [ string , string ] ,
214+ ) ,
215+ ) ,
216+ )
217+ : account . fieldHtmls ;
187218 const bioResult =
188219 form . note == null ? null : await formatText ( db , form . note , fmtOpts ) ;
189220 const name = form . display_name ?? account . name ;
@@ -200,7 +231,7 @@ app.patch(
200231 bioHtml : bioResult == null ? account . bioHtml : bioResult . html ,
201232 avatarUrl,
202233 coverUrl,
203- fieldHtmls : Object . fromEntries ( fieldHtmls ) ,
234+ fieldHtmls : fieldHtmlsRecord ,
204235 protected :
205236 form . locked == null ? account . protected : form . locked === "true" ,
206237 sensitive :
@@ -220,7 +251,9 @@ app.patch(
220251 . update ( accountOwners )
221252 . set ( {
222253 bio : form . note ?? owner . bio ,
223- fields : Object . fromEntries ( fields ) ,
254+ fields : anyFieldAttributeSubmitted
255+ ? Object . fromEntries ( denseFields )
256+ : owner . fields ,
224257 visibility : form [ "source[privacy]" ] ?? owner . visibility ,
225258 language : form [ "source[language]" ] ?? owner . language ,
226259 } )
0 commit comments