eivid 1.1.1 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9246a571186c117fe8a8cedba5908a275eaa74b0bea191fd69f557431a18201a
4
- data.tar.gz: 860c7a305e0909d59b093cd33fb063542edf0a49632f7c1db83889681a6029a4
3
+ metadata.gz: 84e784e3dbec889dae0b8fd97deade4b7dfb158845015783c1f3bc4bf7ff1f5f
4
+ data.tar.gz: d804c9c9c80d164bcfcf07046d880f3359e7e1c6f030d038039c43e711689941
5
5
  SHA512:
6
- metadata.gz: ff72ebf02f8a5f89bb2ffa3ac1e92f7001900588fbbf54fe3764dd2a680003c06776a2100f68952ae4f2515b2213a5b8bbdc423dc01b2f28e9f241cca3bf839c
7
- data.tar.gz: a62b3655af2be692f16f71fb3bb029000cefff28575eb2f480f900037d11a41924a7dfab8d737a91714b1b345e5a29aa260c09a7a1aceabed1c9bcf6063493b3
6
+ metadata.gz: ade10d5df13c9d5bd79ce6c1c0e12a8ac470feca13d0cc7c0611a51d632dd01fb344afe54a4163a0a781238b8c9f63f3ceb6726a71aa17c93160eb4ef76bda75
7
+ data.tar.gz: e6df28555d25e1d259546285924e5fd237383bebfb9ce98b7856c3b2618428ca31245a07b67cc5f37396aa1aefb89cf6c863e232e820aba97bb3104774339586
@@ -14,27 +14,21 @@ module Eivid::Concerns::VideoValidations
14
14
 
15
15
  def validate_video_file_presence
16
16
  unless params["video_file"]
17
- raise Eivid::VideoFileNotPresentError.new(
18
- "you forgot to add a required 'video_file' to your request"
19
- )
17
+ raise_controller_error "you forgot to add a required 'video_file' to your request"
20
18
  end
21
19
  end
22
20
 
23
21
  def validate_video_file_format
24
22
  mime = params["video_file"]&.original_filename&.split('.')&.last&.downcase
25
23
  unless Eivid::VideoMimeDump::DATA.include?(mime)
26
- raise Eivid::IncorrectVideoMimeTypeError.new(
27
- "the 'video_file' you tried to upload, is of an invalid mime type"
28
- )
24
+ raise_controller_error "the 'video_file' you tried to upload, is of an invalid mime type"
29
25
  end
30
26
  end
31
27
 
32
28
  def validate_video_file_size
33
29
  megabytes = params["video_file"].tempfile.size / 1.0.megabyte
34
30
  unless MAX_MB_VIDEO >= megabytes
35
- raise VideoFileSizeTooBigError.new(
36
- "the 'video_file' size (#{megabytes.round(2)} mb) you tried to upload exceeds the maximum file size (#{MAX_MB_VIDEO} mb)"
37
- )
31
+ raise_controller_error "the 'video_file' size (#{megabytes.round(2)} mb) you tried to upload exceeds the maximum file size (#{MAX_MB_VIDEO} mb)"
38
32
  end
39
33
  end
40
34
 
@@ -3,7 +3,7 @@ module Eivid::Concerns::MainApp::Owner
3
3
  included do
4
4
 
5
5
  has_one :video_owner, class_name: 'Eivid::Owner', foreign_key: 'external_id'
6
- has_many :videos, class_name: 'Eivid::Video', source: :video_owner, foreign_key: 'owner_id'
6
+ has_many :videos, class_name: 'Eivid::Video', foreign_key: 'owner_id'
7
7
 
8
8
  include Eivid::Concerns::MainApp::VideoConcerns
9
9
 
@@ -2,19 +2,56 @@ module Eivid::Concerns::RequestService::UploadVideo
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  def upload_video(video_path:)
5
- @file = File.open(video_path)
6
- @request = HTTParty.post Eivid::RequestService::VIDEOS_URL, **upload_params
7
- @response = JSON.parse(@request).deep_symbolize_keys
8
- @upload_link = @response.dig(:upload, :upload_link)
9
-
5
+ @file = File.open(video_path)
6
+ retrieve_upload_link
10
7
  tus_upload_to_vimeo
11
8
  @response
12
9
  end
13
10
 
14
11
  private
15
12
 
13
+ def retrieve_upload_link
14
+ efforts = 0
15
+ max_efforts = 180
16
+ sleep_time = 1
17
+
18
+ while @upload_link.blank? && efforts < max_efforts do
19
+
20
+ puts "Trying to retrieve upload link from Vimeo... try #{efforts}/#{max_efforts} with #{sleep_time} seconds sleep in between..."
21
+
22
+ @request = HTTParty.post Eivid::RequestService::VIDEOS_URL, **upload_params
23
+ @response = JSON.parse(@request).deep_symbolize_keys
24
+ @upload_link = @response.dig(:upload, :upload_link)
25
+
26
+ if @upload_link.blank?
27
+ sleep sleep_time
28
+ efforts += 1
29
+
30
+ else
31
+ puts "successfully retrieved the Vimeo upload link!"
32
+ end
33
+ end
34
+ end
35
+
16
36
  def tus_upload_to_vimeo
17
- HTTParty.patch @upload_link, body: @file.read, headers: tus_headers
37
+ efforts = 0
38
+ max_efforts = 10
39
+ sleep_time = 30
40
+ successful = false
41
+
42
+ while !successful && efforts < max_efforts
43
+
44
+ puts "Trying to upload the video to Vimeo... try #{efforts}/#{max_efforts} with #{sleep_time} seconds sleep in between..."
45
+ response = HTTParty.patch @upload_link, body: @file.read, headers: tus_headers
46
+
47
+ if response.code >= 500
48
+ sleep sleep_time
49
+ efforts += 1
50
+ else
51
+ successful = true
52
+ puts "successfully uploaded the video to Vimeo!"
53
+ end
54
+ end
18
55
  end
19
56
 
20
57
  def upload_params
@@ -28,4 +65,4 @@ module Eivid::Concerns::RequestService::UploadVideo
28
65
  { body: body.to_json, headers: default_headers }
29
66
  end
30
67
 
31
- end
68
+ end
data/lib/eivid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eivid
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eivid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-25 00:00:00.000000000 Z
11
+ date: 2022-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.1.2
146
+ rubygems_version: 3.2.22
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Eivid because we can.