Aggiunge modulo Replay, Garage dev e YouTube a livello società.
Pipeline registrazione/upload con storage S3, archivio web e app, proxy replay per il browser, OAuth YouTube sulla pagina club (Premium Full) e footer legale. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
105
backend/app/controllers/api/v1/recordings_controller.rb
Normal file
105
backend/app/controllers/api/v1/recordings_controller.rb
Normal file
@@ -0,0 +1,105 @@
|
||||
module Api
|
||||
module V1
|
||||
class RecordingsController < BaseController
|
||||
before_action :set_recording
|
||||
|
||||
def update
|
||||
authorize_manage!
|
||||
@recording.update!(recording_update_attrs)
|
||||
render json: recording_json(@recording)
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize_manage!
|
||||
Recordings::Delete.new(@recording).call
|
||||
head :no_content
|
||||
end
|
||||
|
||||
def download
|
||||
url = Recordings::DownloadUrl.new(@recording, viewer: current_user).call
|
||||
render json: { download_url: url, expires_in_seconds: MatchLiveTv.replay_download_url_ttl_seconds }
|
||||
rescue Recordings::DownloadUrl::NotAllowed
|
||||
render json: { error: "Download non disponibile per il tuo piano", error_code: "download_not_allowed" },
|
||||
status: :forbidden
|
||||
rescue ArgumentError => e
|
||||
render json: { error: e.message }, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
def publish_youtube
|
||||
authorize_manage!
|
||||
ent = @recording.team.entitlements
|
||||
unless ent.premium_full? && ent.youtube_enabled?
|
||||
return render json: { error: "Republicazione YouTube con Premium Full" }, status: :forbidden
|
||||
end
|
||||
|
||||
Recordings::PublishToYoutubeJob.perform_async(@recording.id)
|
||||
render json: { queued: true, message: "Pubblicazione su YouTube in corso" }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_recording
|
||||
team_ids = current_user.manageable_teams.map(&:id)
|
||||
@recording = Recording.not_deleted
|
||||
.includes(stream_session: :match)
|
||||
.where(team_id: team_ids)
|
||||
.find(params[:id])
|
||||
end
|
||||
|
||||
def authorize_manage!
|
||||
team = @recording.team
|
||||
return if team.club.owned_by?(current_user)
|
||||
return if current_user.manageable_teams.exists?(id: team.id)
|
||||
|
||||
render json: { error: "Non autorizzato" }, status: :forbidden
|
||||
end
|
||||
|
||||
def recording_update_attrs
|
||||
p = params.require(:recording).permit(:privacy_status, :title)
|
||||
p = p.to_h
|
||||
p[:privacy_status] = "unlisted" if p[:privacy_status] == "private"
|
||||
if params.dig(:recording, :metadata).present?
|
||||
p[:metadata] = @recording.metadata.merge(
|
||||
params[:recording][:metadata].to_unsafe_h.stringify_keys
|
||||
)
|
||||
end
|
||||
p
|
||||
end
|
||||
|
||||
def recording_json(recording)
|
||||
session = recording.stream_session
|
||||
match = session.match
|
||||
ent = recording.team.entitlements
|
||||
{
|
||||
id: recording.id,
|
||||
session_id: session.id,
|
||||
match_id: match.id,
|
||||
title: recording.title_or_default,
|
||||
opponent_name: match.opponent_name,
|
||||
team_name: match.team.name,
|
||||
team_id: recording.team_id,
|
||||
status: recording.status,
|
||||
status_label: recording.status_label,
|
||||
privacy_status: recording.privacy_status,
|
||||
ended_at: session.ended_at,
|
||||
recorded_at: recording.recorded_at_or_fallback,
|
||||
duration_secs: recording.duration_secs,
|
||||
duration_label: recording.duration_label,
|
||||
byte_size: recording.byte_size,
|
||||
byte_size_label: recording.byte_size_label,
|
||||
view_count: recording.view_count,
|
||||
views_label: recording.views_label,
|
||||
replay_url: recording.replay_url,
|
||||
playback_url: recording.playback_stream_url,
|
||||
thumbnail_url: recording.thumbnail_url,
|
||||
download_enabled: ent.phone_download_enabled?,
|
||||
youtube_video_id: recording.youtube_video_id,
|
||||
youtube_watch_url: recording.youtube_watch_url,
|
||||
youtube_publish_enabled: ent.premium_full? && ent.youtube_enabled?,
|
||||
expires_at: recording.expires_at,
|
||||
metadata: recording.metadata
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -37,7 +37,11 @@ module Api
|
||||
}, status: :forbidden
|
||||
end
|
||||
|
||||
recs = team.recordings.ready.includes(stream_session: :match).order(created_at: :desc).limit(50)
|
||||
recs = team.recordings.not_deleted
|
||||
.where(status: %w[ready processing])
|
||||
.includes(stream_session: :match)
|
||||
.order(recorded_at: :desc, created_at: :desc)
|
||||
.limit(50)
|
||||
render json: recs.map { |r| recording_json(r) }
|
||||
end
|
||||
|
||||
@@ -87,7 +91,7 @@ module Api
|
||||
youtube_uses_platform_channel: yt.uses_platform_channel?,
|
||||
youtube_platform_available: resolver.platform_available?,
|
||||
youtube_team_channel_available: resolver.team_channel_available?,
|
||||
youtube_team_channel_title: team.youtube_credential&.channel_title,
|
||||
youtube_team_channel_title: team.club.youtube_credential&.channel_title,
|
||||
plan_slug: ent.plan.slug,
|
||||
plan_name: ent.plan.name,
|
||||
premium_active: ent.premium_active?,
|
||||
@@ -108,7 +112,7 @@ module Api
|
||||
youtube_mode: ent.plan.youtube_mode,
|
||||
staff_role: current_user.staff_role_for(team),
|
||||
can_stream: current_user.can_stream_for?(team),
|
||||
can_connect_youtube: current_user.can_stream_for?(team) && ent.premium_full? && ent.youtube_enabled?
|
||||
can_connect_youtube: team.club.owned_by?(current_user) && ent.premium_full? && ent.youtube_enabled?
|
||||
}
|
||||
if detail
|
||||
data[:members] = team.user_teams.includes(:user).where.not(role: "owner").map do |ut|
|
||||
@@ -121,16 +125,34 @@ module Api
|
||||
def recording_json(recording)
|
||||
session = recording.stream_session
|
||||
match = session.match
|
||||
ent = recording.team.entitlements
|
||||
{
|
||||
id: recording.id,
|
||||
session_id: session.id,
|
||||
match_id: match.id,
|
||||
title: recording.title_or_default,
|
||||
opponent_name: match.opponent_name,
|
||||
team_name: match.team.name,
|
||||
status: recording.status,
|
||||
status_label: recording.status_label,
|
||||
privacy_status: recording.privacy_status,
|
||||
ended_at: session.ended_at,
|
||||
recorded_at: recording.recorded_at_or_fallback,
|
||||
duration_secs: recording.duration_secs,
|
||||
duration_label: recording.duration_label,
|
||||
byte_size: recording.byte_size,
|
||||
byte_size_label: recording.byte_size_label,
|
||||
replay_url: recording.replay_url,
|
||||
download_url: recording.replay_url,
|
||||
expires_at: recording.expires_at
|
||||
playback_url: recording.playback_stream_url,
|
||||
thumbnail_url: recording.thumbnail_url,
|
||||
download_enabled: ent.phone_download_enabled?,
|
||||
view_count: recording.view_count,
|
||||
views_label: recording.views_label,
|
||||
youtube_video_id: recording.youtube_video_id,
|
||||
youtube_watch_url: recording.youtube_watch_url,
|
||||
youtube_publish_enabled: ent.premium_full? && ent.youtube_enabled?,
|
||||
expires_at: recording.expires_at,
|
||||
metadata: recording.metadata
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,9 @@ module Api
|
||||
def authorize
|
||||
team = current_user.streamable_teams.find { |t| t.id.to_s == params[:team_id].to_s }
|
||||
raise ActiveRecord::RecordNotFound unless team
|
||||
unless team.club.owned_by?(current_user)
|
||||
return render json: { error: "Solo il titolare della società può collegare YouTube" }, status: :forbidden
|
||||
end
|
||||
|
||||
team.entitlements.assert_can_connect_youtube!
|
||||
return_app = ActiveModel::Type::Boolean.new.cast(params[:return_app])
|
||||
|
||||
Reference in New Issue
Block a user