File tree 3 files changed +37
-5
lines changed
3 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,14 @@ defmodule Kaffy.ResourceForm do
152
152
:decimal ->
153
153
text_input ( form , field , opts )
154
154
155
+ :binary ->
156
+ value =
157
+ data
158
+ |> Map . get ( field , "" )
159
+ |> Base . encode64 ( )
160
+
161
+ text_input ( form , field , [ value: value ] ++ opts )
162
+
155
163
t when t in [ :boolean , :boolean_checkbox ] ->
156
164
checkbox_opts = add_class ( opts , "custom-control-input" )
157
165
label_opts = add_class ( opts , "custom-control-label" )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ defmodule Kaffy.ResourceParams do
3
3
4
4
def decode_map_fields ( resource , schema , params ) do
5
5
map_fields = ResourceSchema . get_map_fields ( schema ) |> Enum . map ( fn { f , _ } -> to_string ( f ) end )
6
+ binary_fields = ResourceSchema . get_binary_fields ( schema ) |> Enum . map ( fn { f , _ } -> to_string ( f ) end )
6
7
7
8
attrs =
8
9
Map . get ( params , resource , % { } )
@@ -12,9 +13,13 @@ defmodule Kaffy.ResourceParams do
12
13
{ k , v }
13
14
14
15
false ->
15
- case k in map_fields && String . length ( v ) > 0 do
16
- true -> { k , Kaffy.Utils . json ( ) . decode! ( v ) }
17
- false -> { k , v }
16
+ if k in binary_fields && String . length ( v ) > 0 do
17
+ { k , Base . decode64! ( v ) }
18
+ else
19
+ case k in map_fields && String . length ( v ) > 0 do
20
+ true -> { k , Kaffy.Utils . json ( ) . decode! ( v ) }
21
+ false -> { k , v }
22
+ end
18
23
end
19
24
end
20
25
end )
Original file line number Diff line number Diff line change @@ -194,7 +194,11 @@ defmodule Kaffy.ResourceSchema do
194
194
Kaffy.Utils . json ( ) . encode! ( value , escape: :html_safe , pretty: true )
195
195
196
196
is_binary ( value ) ->
197
- value
197
+ if String . valid? ( value ) do
198
+ value
199
+ else
200
+ Base . encode64 ( value )
201
+ end
198
202
199
203
true ->
200
204
kaffy_field_value ( schema , field )
@@ -224,7 +228,11 @@ defmodule Kaffy.ResourceSchema do
224
228
Kaffy.Utils . json ( ) . encode! ( value , escape: :html_safe , pretty: true )
225
229
226
230
is_binary ( value ) ->
227
- String . slice ( value , 0 , 140 )
231
+ if String . valid? ( value ) do
232
+ String . slice ( value , 0 , 140 )
233
+ else
234
+ Base . encode64 ( String . slice ( value , 0 , 140 ) )
235
+ end
228
236
229
237
is_list ( value ) ->
230
238
pretty_list ( value )
@@ -337,6 +345,17 @@ defmodule Kaffy.ResourceSchema do
337
345
end )
338
346
end
339
347
348
+ def get_binary_fields ( schema ) do
349
+ get_all_fields ( schema )
350
+ |> Enum . filter ( fn
351
+ { _f , % { type: :binary } } ->
352
+ true
353
+
354
+ _ ->
355
+ false
356
+ end )
357
+ end
358
+
340
359
def widgets ( _resource ) do
341
360
[ ]
342
361
end
You can’t perform that action at this time.
0 commit comments