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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76f49bc8d1e6eacb6e18e20cbcc1f6c51517a68dce9da8c04452ef24e9dbf234
|
|
4
|
+
data.tar.gz: 4c28ee5e130bb987b96d9875aaf0c311f57ac8183f9192fae0f3004e17130769
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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(
|
|
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
|
-
|
|
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
|
|
31
|
-
|
|
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}
|
|
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
|
-
|
|
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")
|