helios-videos 0.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e3128ca8453dd9d7bb22e3cc19315474a4dd398d3ba228a212ed54e9c8e2818
4
- data.tar.gz: f7ad28e93d4fb7eaebd2965cdee27d26e5f01d0a48aadf0821234a770f1380bc
3
+ metadata.gz: 76f49bc8d1e6eacb6e18e20cbcc1f6c51517a68dce9da8c04452ef24e9dbf234
4
+ data.tar.gz: 4c28ee5e130bb987b96d9875aaf0c311f57ac8183f9192fae0f3004e17130769
5
5
  SHA512:
6
- metadata.gz: 7960c948c478d4fcc24dff6ab49254628727836ba32f7c0d2a5b1a897da932d0f8b143d651466df0c53ce51e32cb16cf439ae248296ae9859d5f8691da3b9c03
7
- data.tar.gz: 19238d28e62666f25a1165fe1272d3922ed479b5203a9d52dcac93cdccbee604b33b78fc151a7f572b26728ba5533ba4b4abbc0ff2cc523ac0cce4133f0c24e9
6
+ metadata.gz: 299c28c8d5c04276658b6ee9fb90490d22e614e8fb4326ad4feb1789d365cc7282231062d50e5108b0843cb74b51a588dc3409bf2d57edcbc0f1a2f9adc2ecf1
7
+ data.tar.gz: 667d4b2cce0d79fb170b0c0696a3261a42d8bc9115440bdf9230df8abb62d5a1318ed9d2caeb6d5aafaa1681860182bcd64bec79d361adbe1eb2932af9c7fe68
@@ -1,9 +1,59 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
2
 
3
- // Manages inline name editing for video blocks
3
+ // Manages inline name editing and auto-polling for video blocks
4
4
  export default class extends Controller {
5
5
  static values = {
6
- videoId: Number
6
+ videoId: Number,
7
+ ready: Boolean,
8
+ statusUrl: String
9
+ }
10
+
11
+ static targets = ["player"]
12
+
13
+ connect() {
14
+ if (!this.readyValue && this.statusUrlValue) {
15
+ this.startPolling()
16
+ }
17
+ }
18
+
19
+ disconnect() {
20
+ this.stopPolling()
21
+ }
22
+
23
+ startPolling() {
24
+ this.pollTimer = setInterval(() => this.checkStatus(), 5000)
25
+ }
26
+
27
+ stopPolling() {
28
+ if (this.pollTimer) {
29
+ clearInterval(this.pollTimer)
30
+ this.pollTimer = null
31
+ }
32
+ }
33
+
34
+ async checkStatus() {
35
+ try {
36
+ const response = await fetch(this.statusUrlValue, {
37
+ headers: {
38
+ 'Accept': 'application/json',
39
+ 'X-CSRF-Token': document.querySelector('[name="csrf-token"]').content
40
+ }
41
+ })
42
+
43
+ if (!response.ok) return
44
+
45
+ const data = await response.json()
46
+
47
+ if (data.ready && data.player_html) {
48
+ this.stopPolling()
49
+ this.readyValue = true
50
+ if (this.hasPlayerTarget) {
51
+ this.playerTarget.innerHTML = data.player_html
52
+ }
53
+ }
54
+ } catch (e) {
55
+ // Silently retry on next interval
56
+ }
7
57
  }
8
58
 
9
59
  editName(event) {
@@ -19,7 +69,7 @@ export default class extends Controller {
19
69
  const input = event.currentTarget
20
70
  const name = input.value
21
71
 
22
- fetch(`/helios_videos/admin/videos/${this.videoIdValue}`, {
72
+ fetch(this.statusUrlValue, {
23
73
  method: 'PATCH',
24
74
  headers: {
25
75
  'Content-Type': 'application/json',
@@ -16,7 +16,9 @@ module Helios
16
16
  # @param video_id [Integer]
17
17
  # @param from [String] source provider
18
18
  # @param to [String] destination provider
19
- def perform(video_id:, from:, to:)
19
+ # @param use_original [Boolean] if true, use the original S3 file instead
20
+ # of downloading from the source provider
21
+ def perform(video_id:, from:, to:, use_original: false)
20
22
  video = Helios::Videos.video_class.find(video_id)
21
23
 
22
24
  unless video.provider == from
@@ -27,10 +29,21 @@ module Helios
27
29
  source_processor = Helios::Videos.processor_for(from.to_sym)
28
30
  dest_processor = Helios::Videos.processor_for(to.to_sym)
29
31
 
30
- # Get download URL from source
31
- source_url = source_processor.download_url(video, expiration: 12.hours)
32
+ # Get source URL — either from the original S3 upload or from the current provider
33
+ if use_original
34
+ unless video.video_file.attached?
35
+ Rails.logger.error("[helios-videos] Migration: video #{video_id} has no original file attached, falling back to provider download")
36
+ source_url = source_processor.download_url(video, expiration: 12.hours)
37
+ else
38
+ source_url = video.video_file.url
39
+ Rails.logger.info("[helios-videos] Migration: using original S3 file for video #{video_id}")
40
+ end
41
+ else
42
+ source_url = source_processor.download_url(video, expiration: 12.hours)
43
+ end
44
+
32
45
  unless source_url.present?
33
- Rails.logger.error("[helios-videos] Migration: could not get download URL for video #{video_id} from #{from}")
46
+ Rails.logger.error("[helios-videos] Migration: could not get download URL for video #{video_id}")
34
47
  return
35
48
  end
36
49
 
@@ -10,17 +10,21 @@ module Helios
10
10
  # @param from [String] source provider ("cloudflare" or "mux")
11
11
  # @param to [String] destination provider ("cloudflare" or "mux")
12
12
  # @param batch_size [Integer] how many to enqueue per run (default: all)
13
- def perform(from:, to:, batch_size: nil)
13
+ # @param use_original [Boolean] if true, ingest from the original S3 file
14
+ # (via ActiveStorage) instead of downloading from the source provider.
15
+ # Useful if you want higher quality unprocessed source files. Requires
16
+ # that the original uploads still exist in your storage bucket.
17
+ def perform(from:, to:, batch_size: nil, use_original: false)
14
18
  video_class = Helios::Videos.video_class
15
19
 
16
20
  videos = video_class.where(provider: from).where.not(key: [nil, ""])
17
21
  videos = videos.limit(batch_size) if batch_size.present?
18
22
 
19
23
  total = videos.count
20
- Rails.logger.info("[helios-videos] Migration: enqueuing #{total} videos from #{from} -> #{to}")
24
+ Rails.logger.info("[helios-videos] Migration: enqueuing #{total} videos from #{from} -> #{to} (use_original: #{use_original})")
21
25
 
22
26
  videos.find_each do |video|
23
- ConvertVideoJob.perform_later(video_id: video.id, from: from, to: to)
27
+ ConvertVideoJob.perform_later(video_id: video.id, from: from, to: to, use_original: use_original)
24
28
  end
25
29
 
26
30
  Rails.logger.info("[helios-videos] Migration: all #{total} conversion jobs enqueued")
@@ -1,5 +1,5 @@
1
1
  module Helios
2
2
  module Videos
3
- VERSION = "0.2"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helios-videos
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt