@@ -23,21 +23,54 @@ def validate_params(response, _params, user_id, original_project, remix_origin)
2323 end
2424
2525 def remix_project ( response , params , user_id , original_project , remix_origin )
26- response [ :project ] = create_remix ( original_project , params , user_id , remix_origin )
26+ response [ :project ] = if scratch_project? ( original_project )
27+ create_scratch_remix ( original_project , params , user_id , remix_origin )
28+ else
29+ create_remix ( original_project , params , user_id , remix_origin )
30+ end
2731 response [ :project ] . save!
2832 response
2933 end
3034
3135 def create_remix ( original_project , params , user_id , remix_origin )
3236 remix = format_project ( original_project , params , user_id , remix_origin )
33- copy_media_attachments ( original_project , remix )
3437
35- ( params [ :components ] . presence || original_project . components ) . each do |component |
36- remix . components . build ( record_attributes ( component ) . slice ( :name , :extension , :content ) )
38+ original_project . images . each do |image |
39+ remix . images . attach ( image . blob )
3740 end
3841
39- scratch_component = params [ :scratch_component ] || original_project . scratch_component
40- remix . build_scratch_component ( content : record_attributes ( scratch_component ) [ :content ] ) if scratch_component . present?
42+ original_project . videos . each do |video |
43+ remix . videos . attach ( video . blob )
44+ end
45+
46+ original_project . audio . each do |audio_file |
47+ remix . audio . attach ( audio_file . blob )
48+ end
49+
50+ params [ :components ] . each do |component |
51+ remix . components . build ( component . slice ( :name , :extension , :content ) )
52+ end
53+
54+ remix
55+ end
56+
57+ def create_scratch_remix ( original_project , params , user_id , remix_origin )
58+ remix = format_project ( original_project , params , user_id , remix_origin )
59+
60+ original_project . images . each do |image |
61+ remix . images . attach ( image . blob )
62+ end
63+
64+ original_project . videos . each do |video |
65+ remix . videos . attach ( video . blob )
66+ end
67+
68+ original_project . audio . each do |audio_file |
69+ remix . audio . attach ( audio_file . blob )
70+ end
71+
72+ scratch_component = params . fetch ( :scratch_component )
73+ remix . build_scratch_component ( content : scratch_component [ :content ] || scratch_component [ 'content' ] )
4174
4275 remix
4376 end
@@ -54,14 +87,8 @@ def format_project(original_project, params, user_id, remix_origin)
5487 end
5588 end
5689
57- def record_attributes ( record )
58- ( record . respond_to? ( :attributes ) ? record . attributes : record . to_h ) . symbolize_keys
59- end
60-
61- def copy_media_attachments ( original_project , remix )
62- original_project . images . each { |image | remix . images . attach ( image . blob ) }
63- original_project . videos . each { |video | remix . videos . attach ( video . blob ) }
64- original_project . audio . each { |audio_file | remix . audio . attach ( audio_file . blob ) }
90+ def scratch_project? ( project )
91+ project . project_type == Project ::Types ::CODE_EDITOR_SCRATCH
6592 end
6693 end
6794 end
0 commit comments