cessna 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,23 +37,32 @@ module Cessna
37
37
  end
38
38
 
39
39
  get '/browse' do
40
- items = fetch_items('/')
41
- @folders = collect_folders(items)
42
- @videos = collect_videos(items)
40
+ begin
41
+ items = fetch_items('/')
42
+ @folders = collect_folders(items)
43
+ @videos = collect_videos(items)
43
44
 
44
- haml :browse
45
+ haml :browse
46
+ rescue RuntimeError
47
+ show_error('It was not possible to access the shared folders. Perhaps the content is protected?')
48
+ end
45
49
  end
46
50
 
47
51
  get '/browse/:folder_location' do
48
52
  location = Base64.decode64(params[:folder_location])
49
- @parent_location = parent_location(location)
50
- @current_folder = item_name(location)
51
53
 
52
- items = fetch_items(location)
53
- @folders = collect_folders(items)
54
- @videos = collect_videos(items)
54
+ begin
55
+ @parent_location = parent_location(location)
56
+ @current_folder = item_name(location)
57
+
58
+ items = fetch_items(location)
59
+ @folders = collect_folders(items)
60
+ @videos = collect_videos(items)
55
61
 
56
- haml :browse
62
+ haml :browse
63
+ rescue RuntimeError => e
64
+ show_runtime_error(e)
65
+ end
57
66
  end
58
67
 
59
68
  post '/session' do
@@ -66,15 +75,20 @@ module Cessna
66
75
 
67
76
  get '/play/:video_location' do
68
77
  location = Base64.decode64(params[:video_location])
69
- client = airvideo_client
70
- @parent_location = parent_location(location)
71
- @video_name = item_name(location)
72
78
 
73
- client.cd(@parent_location)
74
- video = client.ls.select{|item| item.name == @video_name}.first
75
- @video_stream_url = video.url
79
+ begin
80
+ client = airvideo_client
81
+ @parent_location = parent_location(location)
82
+ @video_name = item_name(location)
83
+
84
+ client.cd(@parent_location)
85
+ video = client.ls.select{|item| item.name == @video_name}.first
86
+ @video_stream_url = video.url
76
87
 
77
- haml :play
88
+ haml :play
89
+ rescue RuntimeError => e
90
+ show_runtime_error(e)
91
+ end
78
92
  end
79
93
 
80
94
  private
@@ -119,5 +133,21 @@ module Cessna
119
133
  location.split('/').last
120
134
  end
121
135
  end
136
+
137
+ def show_runtime_error(exception)
138
+ show_error("AirVideo Runtime Error: #{exception}")
139
+ end
140
+
141
+ def show_error(error_message)
142
+ clear_session
143
+ @error_message = error_message
144
+ haml :error
145
+ end
146
+
147
+ def clear_session
148
+ session['hostname'] = nil
149
+ session['port'] = nil
150
+ session['password'] = nil
151
+ end
122
152
  end
123
153
  end
@@ -1,3 +1,3 @@
1
1
  module Cessna
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -21,4 +21,4 @@
21
21
  ="#{video.name}"
22
22
  - else
23
23
  %div{class: 'alert alert-info'}
24
- ="No folders or supported video formats were found in this folder..."
24
+ ="There are no folders or supported video formats in this folder..."
@@ -0,0 +1,7 @@
1
+ %div{class: 'alert alert-error'}
2
+ %p
3
+ %strong
4
+ ="Something went wrong!"
5
+ =@error_message
6
+
7
+ %a{href: '/', class: 'btn'}="back"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cessna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -82,6 +82,7 @@ files:
82
82
  - public/assets/img/glyphicons-halflings-white.png
83
83
  - public/assets/img/glyphicons-halflings.png
84
84
  - views/browse.haml
85
+ - views/error.haml
85
86
  - views/index.haml
86
87
  - views/layout.haml
87
88
  - views/play.haml