Skip to content

Commit

Permalink
properly match new recordings
Browse files Browse the repository at this point in the history
  • Loading branch information
branch14 committed Apr 10, 2017
1 parent 4526194 commit 39c6b45
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,33 @@ def propagate_changes
Faye.publish_to '/admin/devices', attributes
end

def recordings(period=14.days)
files.map do |file|
def old_recordings
files.select { |f| f.key.match(/recording_\d+_\d+\.ogg$/) }.map do |file|
{
name: file.key.sub(prefix, ''),
date: Time.at(file.key.match(/_(\d+)(_\d+)?\.ogg$/)[1].to_i),
duration: hms(estimate_duration(file.content_length)),
size: file.content_length,
link: "/backup/#{file.key}"
}
end.reject do |rec|
end
end

def new_recordings
files.select { |f| f.key.match(/rec_\d+_\d+\.ogg$/) }.map do |file|
key = file.key.sub(prefix, '')
{
name: key,
date: DateTime.strptime(key, 'rec_%Y%m%d_%H%M%S.ogg').to_time,
duration: hms(estimate_duration(file.content_length)),
size: file.content_length,
link: "/backup/#{file.key}"
}
end
end

def recordings(period=14.days)
(new_recordings + old_recordings).reject do |rec|
rec[:date] < period.ago
end
end
Expand Down

0 comments on commit 39c6b45

Please sign in to comment.