docbrown/app/controllers/api/v0/videos_controller.rb
rhymes a56eb8fab0
Enable CORS on public API endpoints (#6116) [deploy]
* Enable CORS for public API

* Add specs for Articles API

* Mention CORS in the API docs
2020-02-18 10:47:07 -05:00

21 lines
637 B
Ruby

module Api
module V0
class VideosController < ApiController
before_action :set_cache_control_headers, only: %i[index]
def index
page = params[:page]
per_page = (params[:per_page] || 24).to_i
num = [per_page, 1000].min
@video_articles = Article.with_video.
includes([:user]).
select(:id, :video, :path, :title, :video_thumbnail_url, :user_id, :video_duration_in_seconds).
order("hotness_score DESC").
page(page).per(num)
set_surrogate_key_header "videos", Article.table_key, @video_articles.map(&:record_key)
end
end
end
end