File tree Expand file tree Collapse file tree 3 files changed +37
-5
lines changed Expand file tree Collapse file tree 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 @@ -191,7 +191,11 @@ defmodule Kaffy.ResourceSchema do
191
191
Kaffy.Utils . json ( ) . encode! ( value , escape: :html_safe , pretty: true )
192
192
193
193
is_binary ( value ) ->
194
- value
194
+ if String . valid? ( value ) do
195
+ value
196
+ else
197
+ Base . encode64 ( value )
198
+ end
195
199
196
200
true ->
197
201
kaffy_field_value ( schema , field )
@@ -218,7 +222,11 @@ defmodule Kaffy.ResourceSchema do
218
222
Kaffy.Utils . json ( ) . encode! ( value , escape: :html_safe , pretty: true )
219
223
220
224
is_binary ( value ) ->
221
- String . slice ( value , 0 , 140 )
225
+ if String . valid? ( value ) do
226
+ String . slice ( value , 0 , 140 )
227
+ else
228
+ Base . encode64 ( String . slice ( value , 0 , 140 ) )
229
+ end
222
230
223
231
is_list ( value ) ->
224
232
pretty_list ( value )
@@ -328,6 +336,17 @@ defmodule Kaffy.ResourceSchema do
328
336
end )
329
337
end
330
338
339
+ def get_binary_fields ( schema ) do
340
+ get_all_fields ( schema )
341
+ |> Enum . filter ( fn
342
+ { _f , % { type: :binary } } ->
343
+ true
344
+
345
+ _ ->
346
+ false
347
+ end )
348
+ end
349
+
331
350
def widgets ( _resource ) do
332
351
[ ]
333
352
end
You can’t perform that action at this time.
0 commit comments