@@ -17,7 +17,7 @@ module PlaceOS::Api
1717 end
1818 end
1919
20- @[AC ::Route ::Filter (:before_action , only: [:get_link , :download_proxy_file_contents , :edit , :update , :finished , :destroy ])]
20+ @[AC ::Route ::Filter (:before_action , only: [:get_link , :download_proxy_file_contents , :download_simple_route , : edit , :update , :finished , :destroy ])]
2121 def get_upload (
2222 @[AC ::Param ::Info (description: " upload id of the upload" , example: " uploads-XXX" )]
2323 id : String ,
@@ -104,15 +104,15 @@ module PlaceOS::Api
104104
105105 # 4. Assemble full SQL (with CTE for total_count)
106106 sql = <<-SQL
107- WITH total AS (
108- SELECT COUNT (u.* ) AS total_count
109- FROM " #{ table_name} " u
110- # {where_clause}
111- )
112- SELECT u.* , t .total_count FROM " #{ table_name} " u
113- CROSS JOIN total t
114- # {where_clause}
115- LIMIT $#{ limit_idx } OFFSET $#{ offset_idx } ;
107+ WITH total AS (
108+ SELECT COUNT (u.* ) AS total_count
109+ FROM " #{ table_name} " u
110+ # {where_clause}
111+ )
112+ SELECT u.* , t .total_count FROM " #{ table_name} " u
113+ CROSS JOIN total t
114+ # {where_clause}
115+ LIMIT $#{ limit_idx } OFFSET $#{ offset_idx } ;
116116 SQL
117117
118118 # 5. Append limit and offset params
@@ -276,6 +276,21 @@ module PlaceOS::Api
276276 end
277277 end
278278
279+ # skip authentication for the lookup
280+ skip_action :authorize! , only: :download_simple_route
281+ skip_action :set_user_id , only: :download_simple_route
282+
283+ # a traditional looking route for downloading files
284+ @[AC ::Route ::GET (" /:id/download/:api_key/*:file_name" )]
285+ def download_simple_route (api_key : String , file_name : String )
286+ # check api key
287+ request.headers[" X-API-Key" ] = api_key
288+ authorize!
289+
290+ response.headers[" Content-Disposition" ] = %( attachment; filename="#{ file_name } ")
291+ download_proxy_file_contents
292+ end
293+
279294 # obtain a signed request for each chunk of the file being uploaded.
280295 #
281296 # once all parts are uploaded, you can obtain the final commit request by passing `?part=finish`
0 commit comments