Skip to content

Commit

Permalink
Add endpoint for solution image generator (#5747)
Browse files Browse the repository at this point in the history
* Add endpoint for solution image generator

* Allow access from docker

---------

Co-authored-by: Erik Schierboom <[email protected]>
  • Loading branch information
iHiD and ErikSchierboom authored Aug 1, 2023
1 parent 176fe73 commit db86b3c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/controllers/spi/solution_image_data_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module SPI
class SolutionImageDataController < BaseController
def show
solution = Solution.for!(
params[:user_handle],
params[:track_slug],
params[:exercise_slug]
)

exercise = solution.exercise
track = exercise.track
file = solution.latest_published_iteration_submission.files.first
snippet = solution.snippet.presence || file.content[0, 10]
render json: {
solution: {
snippet:,
extension: File.extname(file.filename),
language: track.highlightjs_language,
track_icon_url: track.icon_url,
exercise_icon_url: exercise.icon_url,
user_avatar_url: solution.user.avatar_url
}
}
end
end
end
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
config.hosts << "website" if ENV['EXERCISM_DOCKER']
config.hosts << /.*.ngrok.io/
config.hosts << /.*.ngrok-free.app/
config.hosts << "host.docker.internal"
end

Rails.application.routes.default_url_options = {
Expand Down
1 change: 1 addition & 0 deletions config/routes/spi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
namespace :spi do
resources :tooling_jobs, only: :update
resources :chatgpt_responses, only: :create
get "solution_image_data/:track_slug/:exercise_slug/:user_handle" => "solution_image_data#show"
end

0 comments on commit db86b3c

Please sign in to comment.