Class: ActiveAgent::Dashboard::RecordingSnapshot

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
lib/active_agent/dashboard/app/models/active_agent/dashboard/recording_snapshot.rb

Overview

Stores screenshots and DOM snapshots from session recordings.

Supports Active Storage for file attachment and provides signed URLs for secure access.

Constant Summary collapse

SNAPSHOT_TYPES =
%w[screenshot dom full_page].freeze

Instance Method Summary collapse

Methods inherited from ApplicationRecord

for_owner, owner_association, table_name

Instance Method Details

#as_json_for_apiObject

For API response



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/recording_snapshot.rb', line 51

def as_json_for_api
  {
    id: id,
    storage_key: storage_key,
    snapshot_type: snapshot_type,
    width: width,
    height: height,
    file_size_bytes: file_size_bytes,
    url: signed_url,
    created_at: created_at.iso8601
  }
end

#signed_url(expires_in: 15.minutes) ⇒ Object

Get a signed URL for the file



26
27
28
29
30
31
32
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/recording_snapshot.rb', line 26

def signed_url(expires_in: 15.minutes)
  return nil unless respond_to?(:file) && file.attached?

  file.url(expires_in: expires_in)
rescue StandardError
  nil
end

#store!(data, filename: nil, content_type: nil) ⇒ Object

Store file data



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/recording_snapshot.rb', line 35

def store!(data, filename: nil, content_type: nil)
  return unless respond_to?(:file)

  content_type ||= infer_content_type
  filename ||= generate_filename

  file.attach(
    io: StringIO.new(data),
    filename: filename,
    content_type: content_type
  )

  update!(file_size_bytes: data.bytesize)
end