class V1::LearningObjects::ChunksController < ApplicationController before_action :authorize! before_action :chunk_service # GET /learning_objects/:learning_object_id/chunk def show if @chunk.exist? post_file render status: :ok else render status: :not_found # chunk doesnt exists and needs to be uploaded end end # POST /learning_objects/:learning_object_id/chunk def create @chunk.save post_file render status: :ok end private def chunk_service @chunk = ChunksService.new(chunks_params) return render status: :unsupported_media_type if @chunk.nil? end def post_file return false unless @chunk.concatenated publisher = LearningObjectPublisher.new(DspaceService.create_client) publisher.upload @chunk.learning_object, @chunk.resumable_filename end def authorize! learning_object = LearningObject.find chunks_params[:id] authorize(learning_object || LearningObject.new, :update?) end # Never trust parameters from the scary internet, only allow the white list through. def chunks_params params.permit(:id, :file, :resumableIdentifier, :resumableFilename, :resumableChunkNumber, :resumableTotalChunks, :resumableChunkSize, :resumableCurrentChunkSize, :resumableTotalSize, :resumableType, :resumableRelativePath) end end