ferver 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +87 -0
- data/README.md +1 -1
- data/ferver.gemspec +1 -0
- data/lib/ferver.rb +1 -2
- data/lib/ferver/app.rb +5 -57
- data/lib/ferver/controller.rb +65 -0
- data/lib/ferver/file_list.rb +3 -2
- data/lib/ferver/version.rb +1 -1
- data/spec/ferver_spec.rb +1 -1
- data/spec/file_list_spec.rb +5 -5
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e42a62e59a7371617918ea1c1a52702b6765ade1
|
4
|
+
data.tar.gz: 7144fe5b0a7167319a4f1837980f55796fabb554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d3ee2dfde1b61732967fc3cd2011702dec256256ae73dd3110c956588fdbb39f954b44c3dc0f5798c04597309d8f306d3f72caa8fabc49a731ba864ab17cc04
|
7
|
+
data.tar.gz: 7c658dfd826f29d134eb31fe0eb56a3973e5860c72446826cf3a7674e91063681a518a5adc1db1fb44b9940c19d27984773f5fd5258706cff0083118faecca79
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
## 1.2.1 - 2014-11-14 - XX
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
- State minimum Ruby version
|
9
|
+
|
10
|
+
### Deprecated
|
11
|
+
- Nothing.
|
12
|
+
|
13
|
+
### Removed
|
14
|
+
- Nothing.
|
15
|
+
|
16
|
+
|
17
|
+
## 1.2.0 - 2014-06-15 - 72dc58b
|
18
|
+
|
19
|
+
### Added
|
20
|
+
- Use named command line arguments.
|
21
|
+
- `Rake s` alias of `Rake server`.
|
22
|
+
- Testing on `Ruby 2.1.1`.
|
23
|
+
|
24
|
+
### Deprecated
|
25
|
+
- Nothing.
|
26
|
+
|
27
|
+
### Removed
|
28
|
+
- Nothing.
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
- Code refactoring.
|
32
|
+
|
33
|
+
## 1.1.0 - 2014-03-18 - 59d6ddf
|
34
|
+
|
35
|
+
### Added
|
36
|
+
- Run **Sinatra** in production mode when started from `bin/`.
|
37
|
+
|
38
|
+
### Deprecated
|
39
|
+
- Nothing.
|
40
|
+
|
41
|
+
### Removed
|
42
|
+
- Nothing.
|
43
|
+
|
44
|
+
### Fixed
|
45
|
+
- #7 : Crash when directory does not exist.
|
46
|
+
|
47
|
+
## 1.0.0 - 2014-03-08 - 0522648
|
48
|
+
|
49
|
+
### Added
|
50
|
+
- Redesign `Ferver` into a **Rubygem**.
|
51
|
+
|
52
|
+
### Deprecated
|
53
|
+
- Nothing.
|
54
|
+
|
55
|
+
### Removed
|
56
|
+
- Nothing.
|
57
|
+
|
58
|
+
### Fixed
|
59
|
+
- Nothing.
|
60
|
+
|
61
|
+
## 1.0.0-beta - 2014-01-31 - 8f27a55
|
62
|
+
|
63
|
+
### Added
|
64
|
+
- Nothing.
|
65
|
+
|
66
|
+
### Deprecated
|
67
|
+
- Nothing.
|
68
|
+
|
69
|
+
### Removed
|
70
|
+
- Nothing.
|
71
|
+
|
72
|
+
### Fixed
|
73
|
+
- Negotiate `content-type` vai HTTP Accept request header.
|
74
|
+
|
75
|
+
## 0.9.0-beta - 2014-01-28 - 09a7504
|
76
|
+
|
77
|
+
### Added
|
78
|
+
- Initial release.
|
79
|
+
|
80
|
+
### Deprecated
|
81
|
+
- Nothing.
|
82
|
+
|
83
|
+
### Removed
|
84
|
+
- Nothing.
|
85
|
+
|
86
|
+
### Fixed
|
87
|
+
- Nothing.
|
data/README.md
CHANGED
@@ -75,7 +75,7 @@ curl -i -H "Accept: application/json" http://localhost:4567/files
|
|
75
75
|
|
76
76
|
#### Download a file
|
77
77
|
|
78
|
-
Files are available via their index in the list, e.g. `http://localhost:4567/files/:id`
|
78
|
+
Files are available via their zero based index in the list, e.g. `http://localhost:4567/files/:id`
|
79
79
|
|
80
80
|
For example to download file appearing third in the list displayed earlier, request `http://localhost:4567/files/2`
|
81
81
|
|
data/ferver.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = %q(Ferver is a super, simple ruby gem to serve files over http; useful as a basic file server to quickly share files on your local network.)
|
13
13
|
spec.homepage = 'https://github.com/rob-murray/ferver'
|
14
14
|
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = '>= 1.9.3'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0")
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
data/lib/ferver.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'ferver/app'
|
2
|
+
require_relative 'ferver/controller'
|
2
3
|
require_relative 'ferver/configuration'
|
3
4
|
require_relative 'ferver/directory_not_found_error'
|
4
5
|
require_relative 'ferver/file_id_request'
|
@@ -6,8 +7,6 @@ require_relative 'ferver/file_list'
|
|
6
7
|
require_relative 'ferver/version'
|
7
8
|
|
8
9
|
module Ferver
|
9
|
-
autoload :App, 'ferver/app'
|
10
|
-
|
11
10
|
# By default, serve files from current location when the gem is called.
|
12
11
|
DEFAULT_FILE_SERVER_DIR_PATH = './'
|
13
12
|
|
data/lib/ferver/app.rb
CHANGED
@@ -1,67 +1,15 @@
|
|
1
1
|
require 'sinatra'
|
2
2
|
require 'sinatra/base'
|
3
|
-
|
4
|
-
require_relative './directory_not_found_error'
|
5
|
-
require_relative './configuration'
|
3
|
+
require_relative './controller'
|
6
4
|
|
7
5
|
module Ferver
|
8
|
-
class App < Sinatra::
|
6
|
+
class App < Sinatra::Application
|
9
7
|
set :app_file, __FILE__
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
configure do
|
10
|
+
set :views, './views'
|
13
11
|
end
|
14
12
|
|
15
|
-
|
16
|
-
halt 500, "Ferver: Directory '#{current_ferver_path}' not found."
|
17
|
-
end
|
18
|
-
|
19
|
-
# redirect to file list
|
20
|
-
get '/' do
|
21
|
-
redirect to('/files')
|
22
|
-
end
|
23
|
-
|
24
|
-
# list files
|
25
|
-
get '/files' do
|
26
|
-
if request.preferred_type.to_s == 'application/json'
|
27
|
-
content_type :json
|
28
|
-
|
29
|
-
ferver_list.all.to_json
|
30
|
-
else
|
31
|
-
erb :index, locals: { file_list: ferver_list.all,
|
32
|
-
ferver_path: File.expand_path(current_ferver_path),
|
33
|
-
file_count: ferver_list.size }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# download file
|
38
|
-
get '/files/:id' do
|
39
|
-
halt(400, 'Bad request') unless valid_file_request?
|
40
|
-
|
41
|
-
if ferver_list.file_id_is_valid?(file_id_request.value)
|
42
|
-
file_name = ferver_list.file_by_id(file_id_request.value)
|
43
|
-
file = FileList.path_for_file(current_ferver_path, file_name)
|
44
|
-
|
45
|
-
send_file(file, disposition: 'attachment', filename: File.basename(file))
|
46
|
-
else
|
47
|
-
status 404
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
attr_reader :ferver_list
|
54
|
-
|
55
|
-
def file_id_request
|
56
|
-
@file_id_request ||= FileIdRequest.new(params[:id])
|
57
|
-
end
|
58
|
-
|
59
|
-
def valid_file_request?
|
60
|
-
file_id_request.valid?
|
61
|
-
end
|
62
|
-
|
63
|
-
def current_ferver_path
|
64
|
-
Ferver.configuration.directory_path
|
65
|
-
end
|
13
|
+
use Controller
|
66
14
|
end
|
67
15
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'json'
|
4
|
+
require_relative './directory_not_found_error'
|
5
|
+
require_relative './configuration'
|
6
|
+
|
7
|
+
module Ferver
|
8
|
+
class Controller < Sinatra::Base
|
9
|
+
before do
|
10
|
+
@ferver_list = FileList.new(current_ferver_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
error Ferver::DirectoryNotFoundError do
|
14
|
+
halt 500, "Ferver: Directory '#{current_ferver_path}' not found."
|
15
|
+
end
|
16
|
+
|
17
|
+
# redirect to file list
|
18
|
+
get '/' do
|
19
|
+
redirect to('/files')
|
20
|
+
end
|
21
|
+
|
22
|
+
# list files
|
23
|
+
get '/files' do
|
24
|
+
if request.preferred_type.to_s == 'application/json'
|
25
|
+
content_type :json
|
26
|
+
|
27
|
+
ferver_list.all.to_json
|
28
|
+
else
|
29
|
+
erb :index, locals: { file_list: ferver_list.all,
|
30
|
+
ferver_path: File.expand_path(current_ferver_path),
|
31
|
+
file_count: ferver_list.size }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# download file
|
36
|
+
get '/files/:id' do
|
37
|
+
halt(400, 'Bad request') unless valid_file_request?
|
38
|
+
|
39
|
+
if ferver_list.file_id_valid?(file_id_request.value)
|
40
|
+
file_name = ferver_list.file_by_id(file_id_request.value)
|
41
|
+
file = FileList.path_for_file(current_ferver_path, file_name)
|
42
|
+
|
43
|
+
send_file(file, disposition: 'attachment', filename: File.basename(file))
|
44
|
+
else
|
45
|
+
status 404
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
attr_reader :ferver_list
|
52
|
+
|
53
|
+
def file_id_request
|
54
|
+
@file_id_request ||= FileIdRequest.new(params[:id])
|
55
|
+
end
|
56
|
+
|
57
|
+
def valid_file_request?
|
58
|
+
file_id_request.valid?
|
59
|
+
end
|
60
|
+
|
61
|
+
def current_ferver_path
|
62
|
+
Ferver.configuration.directory_path
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/ferver/file_list.rb
CHANGED
@@ -5,9 +5,10 @@ require 'forwardable'
|
|
5
5
|
module Ferver
|
6
6
|
class FileList
|
7
7
|
extend Forwardable
|
8
|
-
def_delegators :@files, :size, :each
|
9
8
|
include Enumerable
|
10
9
|
|
10
|
+
def_delegators :@files, :size, :each
|
11
|
+
|
11
12
|
# Create a new instance with a path
|
12
13
|
#
|
13
14
|
def initialize(path)
|
@@ -27,7 +28,7 @@ module Ferver
|
|
27
28
|
|
28
29
|
# Is the file id a valid id for Ferver to serve
|
29
30
|
#
|
30
|
-
def
|
31
|
+
def file_id_valid?(file_id)
|
31
32
|
file_id < files.size
|
32
33
|
end
|
33
34
|
|
data/lib/ferver/version.rb
CHANGED
data/spec/ferver_spec.rb
CHANGED
@@ -149,7 +149,7 @@ describe 'ferver' do
|
|
149
149
|
|
150
150
|
context 'when requesting a file out of range' do
|
151
151
|
before do
|
152
|
-
allow(file_list).to receive(:
|
152
|
+
allow(file_list).to receive(:file_id_valid?).with(3).and_return(false)
|
153
153
|
get '/files/3'
|
154
154
|
end
|
155
155
|
|
data/spec/file_list_spec.rb
CHANGED
@@ -116,12 +116,12 @@ describe Ferver::FileList do
|
|
116
116
|
context 'when requesting valid file_id' do
|
117
117
|
# TODO: possible to redesign this
|
118
118
|
|
119
|
-
it '#
|
120
|
-
expect(subject.
|
119
|
+
it '#file_id_valid? should return true for first file' do
|
120
|
+
expect(subject.file_id_valid?(0)).to be_truthy
|
121
121
|
end
|
122
122
|
|
123
|
-
it '#
|
124
|
-
expect(subject.
|
123
|
+
it '#file_id_valid? should return true for second file' do
|
124
|
+
expect(subject.file_id_valid?(1)).to be_truthy
|
125
125
|
end
|
126
126
|
|
127
127
|
it '#file_by_id should return the correct file for the first file' do
|
@@ -135,7 +135,7 @@ describe Ferver::FileList do
|
|
135
135
|
|
136
136
|
context 'when requesting invalid file_id' do
|
137
137
|
it 'should return false for invalid file_id' do
|
138
|
-
expect(subject.
|
138
|
+
expect(subject.file_id_valid?(2)).to be_falsey
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'should raise_error if file_by_id is called' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ferver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Murray
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- ".rspec"
|
150
150
|
- ".ruby-version"
|
151
151
|
- ".travis.yml"
|
152
|
+
- CHANGELOG.md
|
152
153
|
- Gemfile
|
153
154
|
- LICENSE
|
154
155
|
- README.md
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- lib/ferver.rb
|
159
160
|
- lib/ferver/app.rb
|
160
161
|
- lib/ferver/configuration.rb
|
162
|
+
- lib/ferver/controller.rb
|
161
163
|
- lib/ferver/directory_not_found_error.rb
|
162
164
|
- lib/ferver/file_id_request.rb
|
163
165
|
- lib/ferver/file_list.rb
|
@@ -180,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
180
182
|
requirements:
|
181
183
|
- - ">="
|
182
184
|
- !ruby/object:Gem::Version
|
183
|
-
version:
|
185
|
+
version: 1.9.3
|
184
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
187
|
requirements:
|
186
188
|
- - ">="
|
@@ -188,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
190
|
version: '0'
|
189
191
|
requirements: []
|
190
192
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.
|
193
|
+
rubygems_version: 2.4.4
|
192
194
|
signing_key:
|
193
195
|
specification_version: 4
|
194
196
|
summary: A simple web app to serve files over HTTP.
|