ongaku_ryoho_server 0.3.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/README.md +6 -2
- data/Rakefile +7 -0
- data/history.txt +13 -0
- data/lib/ongaku_ryoho_server/application.rb +26 -8
- data/lib/ongaku_ryoho_server/list.rb +1 -2
- data/lib/ongaku_ryoho_server/process.rb +19 -11
- data/lib/ongaku_ryoho_server.rb +8 -0
- data/ongaku_ryoho_server.gemspec +17 -15
- data/spec/application_spec.rb +121 -0
- data/spec/data/a.mp3 +0 -0
- data/spec/data/b.mp3 +0 -0
- data/spec/data/c.mp3 +0 -0
- data/spec/spec_helper.rb +14 -0
- metadata +58 -34
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7de0168f5720bba9e90009b42988c9dbb9d1cc2a
|
4
|
+
data.tar.gz: 1985ef84ad0aa83a0d690961ec0cd41897397ff9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1dd31f2434a4d21c01b604bbf988a1f8885e25d515216d3df7426ec8a423c3c32592b2f9fe1cc13619029ababf8b1c12db63e27c3690672d24b447cda52c554b
|
7
|
+
data.tar.gz: a983c63d1281ea398f47cadc4be5f6283dd6e573514f4d0b35c49aa5198db8b0230ca5372d38f65db09b739803e07de2807a6380823b304ef1457fb1f60ea2cd
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p195
|
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# Ongaku Ryoho Server
|
2
2
|
|
3
|
-
A little
|
3
|
+
A little web server (with Puma) wrapped in a gem specifically for the Ongaku Ryoho client.
|
4
4
|
|
5
5
|
## How to use
|
6
6
|
|
7
7
|
### Requirements
|
8
8
|
|
9
|
-
|
9
|
+
- taglib
|
10
|
+
- ruby 1.8.7 (or higher)
|
10
11
|
|
11
12
|
### Installation
|
12
13
|
|
@@ -34,4 +35,7 @@ or create a [launch agent](https://gist.github.com/4106353) (tested on OSX Mount
|
|
34
35
|
--update update the cached collection
|
35
36
|
|
36
37
|
+ all the other puma cli options
|
38
|
+
-> https://github.com/puma/puma/blob/v2.0.1/lib/puma/cli.rb#L185
|
39
|
+
|
40
|
+
-d daemonize
|
37
41
|
```
|
data/Rakefile
CHANGED
data/history.txt
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "sinatra/base"
|
2
|
-
|
3
1
|
module OngakuRyohoServer
|
4
2
|
#
|
5
3
|
# { Application }
|
@@ -16,24 +14,44 @@ module OngakuRyohoServer
|
|
16
14
|
|
17
15
|
# root
|
18
16
|
get "/" do
|
19
|
-
|
17
|
+
callback = params[:callback]
|
18
|
+
json = OngakuRyohoServer::List.get
|
19
|
+
|
20
|
+
if callback and !callback.empty?
|
21
|
+
content_type :js
|
22
|
+
response = "#{callback}(#{json})"
|
23
|
+
else
|
24
|
+
content_type :json
|
25
|
+
response = json
|
26
|
+
end
|
20
27
|
|
21
|
-
|
28
|
+
response
|
22
29
|
end
|
23
30
|
|
24
31
|
|
25
32
|
# compare filelists
|
26
33
|
post "/check" do
|
27
|
-
|
34
|
+
callback = params[:callback]
|
35
|
+
file_list = params[:file_list]
|
36
|
+
other_file_list = params[:other_file_list]
|
37
|
+
|
38
|
+
missing_and_new = OngakuRyohoServer::Process.check_files(file_list, other_file_list)
|
39
|
+
json = Oj.dump(missing_and_new)
|
40
|
+
|
41
|
+
if callback and !callback.empty?
|
42
|
+
content_type :js
|
43
|
+
response = "#{callback}(#{json})"
|
44
|
+
else
|
45
|
+
content_type :json
|
46
|
+
response = json
|
47
|
+
end
|
28
48
|
|
29
|
-
|
30
|
-
OngakuRyohoServer::Process.check_files(collection).to_json
|
49
|
+
response
|
31
50
|
end
|
32
51
|
|
33
52
|
|
34
53
|
# music file
|
35
54
|
get %r{.(#{FILE_FORMATS.join("|")})$}i do
|
36
|
-
require "uri"
|
37
55
|
requested_item = URI.unescape(request.path_info[1..-1])
|
38
56
|
File.exists?(requested_item) ? send_file(requested_item) : 404
|
39
57
|
end
|
@@ -17,7 +17,6 @@ module OngakuRyohoServer
|
|
17
17
|
# => Creates a digest from the path of the current directory
|
18
18
|
#
|
19
19
|
def self.get_digest
|
20
|
-
require "digest/sha1"
|
21
20
|
digested_path = Digest::SHA1.hexdigest(Dir.pwd)
|
22
21
|
end
|
23
22
|
|
@@ -54,7 +53,7 @@ module OngakuRyohoServer
|
|
54
53
|
def self.save
|
55
54
|
path = self.config_file_path
|
56
55
|
file_list = OngakuRyohoServer::Process.directory
|
57
|
-
collection = OngakuRyohoServer::Process.files(file_list)
|
56
|
+
collection = Oj.dump(OngakuRyohoServer::Process.files(file_list))
|
58
57
|
|
59
58
|
# make path
|
60
59
|
FileUtils.mkpath(CONFIG_PATH)
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require "taglib"
|
2
|
-
require "json"
|
3
|
-
|
4
1
|
module OngakuRyohoServer
|
5
2
|
#
|
6
3
|
# { Process }
|
@@ -29,27 +26,38 @@ module OngakuRyohoServer
|
|
29
26
|
#
|
30
27
|
# Check files
|
31
28
|
#
|
32
|
-
# => compares a given file list to
|
29
|
+
# => compares a given file list to another file list.
|
30
|
+
# fallback is file list from the current directory.
|
33
31
|
# show which files are missing and scan the ones that are new
|
34
32
|
#
|
35
33
|
# [params]
|
36
|
-
# file_list
|
34
|
+
# file_list : array of hashes with a :location key
|
35
|
+
# other_file_list
|
37
36
|
#
|
38
37
|
# [output]
|
39
38
|
# object containing missing_files and new_tracks array
|
40
39
|
#
|
41
|
-
def self.check_files(file_list)
|
42
|
-
file_list =
|
43
|
-
|
44
|
-
|
40
|
+
def self.check_files(file_list, other_file_list=nil)
|
41
|
+
file_list = Oj.load(file_list || "[]")
|
42
|
+
|
43
|
+
# other file list
|
44
|
+
if other_file_list
|
45
|
+
other_file_list = Oj.load(other_file_list)
|
46
|
+
else
|
47
|
+
other_file_list = Oj.load(OngakuRyohoServer::List.get)
|
48
|
+
other_file_list.map! { |obj| obj[:location] }
|
49
|
+
end
|
45
50
|
|
46
|
-
|
47
|
-
|
51
|
+
# determine which files are missing and which are new
|
52
|
+
missing_files = file_list - other_file_list
|
53
|
+
new_files = other_file_list - file_list
|
48
54
|
|
55
|
+
# process new files
|
49
56
|
new_tracks = OngakuRyohoServer::Process.files(
|
50
57
|
new_files, { :last_modified => Time.now }
|
51
58
|
)
|
52
59
|
|
60
|
+
# return missing and new tracks
|
53
61
|
return {
|
54
62
|
:missing_files => missing_files,
|
55
63
|
:new_tracks => new_tracks
|
data/lib/ongaku_ryoho_server.rb
CHANGED
data/ongaku_ryoho_server.gemspec
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name
|
5
|
-
s.version
|
4
|
+
s.name = "ongaku_ryoho_server"
|
5
|
+
s.version = "0.5.0"
|
6
6
|
|
7
|
-
s.authors
|
8
|
-
s.email
|
9
|
-
s.description
|
10
|
-
s.summary
|
11
|
-
s.homepage
|
7
|
+
s.authors = ["Steven Vandevelde"]
|
8
|
+
s.email = ["icid.asset@gmail.com"]
|
9
|
+
s.description = "Serves music to Ongaku Ryoho clients"
|
10
|
+
s.summary = "Serves music to Ongaku Ryoho clients"
|
11
|
+
s.homepage = "https://github.com/icidasset/ongaku_ryoho_server"
|
12
12
|
|
13
|
-
s.files
|
14
|
-
s.
|
15
|
-
s.
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
s.test_files = s.files.grep(%r{^spec/})
|
15
|
+
s.executables = ["ongaku_ryoho_server"]
|
16
16
|
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
|
19
19
|
|
20
|
-
s.
|
21
|
-
s.
|
22
|
-
s.
|
23
|
-
s.
|
20
|
+
s.add_runtime_dependency "oj", "~> 2.0.14"
|
21
|
+
s.add_runtime_dependency "taglib-ruby", "~> 0.6.0"
|
22
|
+
s.add_runtime_dependency "sinatra", "~> 1.4.2"
|
23
|
+
s.add_runtime_dependency "puma", "~> 2.0.1"
|
24
24
|
|
25
|
-
s.add_development_dependency "rake"
|
25
|
+
s.add_development_dependency "rake", "~> 10.0.4"
|
26
|
+
s.add_development_dependency "rack-test", "~> 0.6.2"
|
27
|
+
s.add_development_dependency "minitest", "~> 5.0.3"
|
26
28
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require File.expand_path("../spec_helper.rb", __FILE__)
|
2
|
+
|
3
|
+
describe "Application" do
|
4
|
+
|
5
|
+
#
|
6
|
+
# Index (GET)
|
7
|
+
#
|
8
|
+
describe "GET /" do
|
9
|
+
before do
|
10
|
+
OngakuRyohoServer::List.save
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return json" do
|
14
|
+
get "/"
|
15
|
+
last_response.must_be :ok?
|
16
|
+
last_response.content_type.must_equal "application/json;charset=utf-8"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return jsonp" do
|
20
|
+
get "/", :callback => "test"
|
21
|
+
last_response.must_be :ok?
|
22
|
+
last_response.content_type.must_equal "application/javascript;charset=utf-8"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have 3 items" do
|
26
|
+
get "/"
|
27
|
+
json = Oj.load(last_response.body)
|
28
|
+
json.length.must_equal 3
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have an item with the necessary keys" do
|
32
|
+
get "/"
|
33
|
+
|
34
|
+
json = Oj.load(last_response.body)
|
35
|
+
first_item = json.first
|
36
|
+
|
37
|
+
first_item.has_key?(:title).must_equal true
|
38
|
+
first_item.has_key?(:artist).must_equal true
|
39
|
+
first_item.has_key?(:album).must_equal true
|
40
|
+
first_item.has_key?(:year).must_equal true
|
41
|
+
first_item.has_key?(:track).must_equal true
|
42
|
+
first_item.has_key?(:genre).must_equal true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
#
|
48
|
+
# Check (POST)
|
49
|
+
#
|
50
|
+
describe "POST /check" do
|
51
|
+
before do
|
52
|
+
OngakuRyohoServer::List.save
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have 2 parent keys" do
|
56
|
+
post "/check"
|
57
|
+
json = Oj.load(last_response.body)
|
58
|
+
json[:missing_files].must_be_kind_of Array
|
59
|
+
json[:new_tracks].must_be_kind_of Array
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should have 3 new tracks when given empty file list" do
|
63
|
+
post "/check", :file_list => Oj.dump([])
|
64
|
+
json = Oj.load(last_response.body)
|
65
|
+
json[:new_tracks].length.must_equal 3
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have 0 new tracks when given same file list" do
|
69
|
+
file_list = [
|
70
|
+
{ :location => "spec/data/a.mp3" },
|
71
|
+
{ :location => "spec/data/b.mp3" },
|
72
|
+
{ :location => "spec/data/c.mp3" }
|
73
|
+
]
|
74
|
+
|
75
|
+
post "/check", :file_list => Oj.dump(file_list)
|
76
|
+
json = Oj.load(last_response.body)
|
77
|
+
json[:new_tracks].length.must_equal 3
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should have 3 missing files" do
|
81
|
+
file_list = [
|
82
|
+
{ :location => "spec/data/a.mp3" },
|
83
|
+
{ :location => "spec/data/b.mp3" },
|
84
|
+
{ :location => "spec/data/c.mp3" }
|
85
|
+
]
|
86
|
+
|
87
|
+
post "/check",
|
88
|
+
:file_list => Oj.dump(file_list),
|
89
|
+
:other_file_list => Oj.dump([])
|
90
|
+
|
91
|
+
json = Oj.load(last_response.body)
|
92
|
+
json[:missing_files].length.must_equal 3
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
#
|
98
|
+
# Files (GET)
|
99
|
+
#
|
100
|
+
describe "GET /*.ALLOWED_FILE_FORMAT" do
|
101
|
+
it "should be able to load a.mp3" do
|
102
|
+
get "/spec/data/a.mp3"
|
103
|
+
last_response.status.must_equal 200
|
104
|
+
last_response.content_type.must_equal "audio/mpeg"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return a 404 if the file doesn't exist" do
|
108
|
+
get "/spec/data/does_not_exist.mp3"
|
109
|
+
last_response.status.must_equal 404
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
describe "GET /*.DISALLOWED_FILE_FORMAT" do
|
115
|
+
it "should return a 403" do
|
116
|
+
get "/forbidden.tar.gz"
|
117
|
+
last_response.status.must_equal 403
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
data/spec/data/a.mp3
ADDED
Binary file
|
data/spec/data/b.mp3
ADDED
Binary file
|
data/spec/data/c.mp3
ADDED
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
ENV["RACK_ENV"] = "test"
|
2
|
+
|
3
|
+
require File.expand_path("../../lib/ongaku_ryoho_server", __FILE__)
|
4
|
+
require "minitest/autorun"
|
5
|
+
require "rack/test"
|
6
|
+
|
7
|
+
|
8
|
+
class MiniTest::Spec
|
9
|
+
include Rack::Test::Methods
|
10
|
+
|
11
|
+
def app
|
12
|
+
OngakuRyohoServer::Application
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,52 +1,46 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ongaku_ryoho_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Steven Vandevelde
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-06-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: oj
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 2.0.14
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 2.0.14
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: taglib-ruby
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
33
|
+
version: 0.6.0
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
40
|
+
version: 0.6.0
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: sinatra
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,35 +55,59 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: puma
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ~>
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
61
|
+
version: 2.0.1
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ~>
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
68
|
+
version: 2.0.1
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rake
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 10.0.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 10.0.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack-test
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
84
88
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
89
|
+
version: 0.6.2
|
86
90
|
type: :development
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
93
|
requirements:
|
91
|
-
- -
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.6.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 5.0.3
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
92
109
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
110
|
+
version: 5.0.3
|
94
111
|
description: Serves music to Ongaku Ryoho clients
|
95
112
|
email:
|
96
113
|
- icid.asset@gmail.com
|
@@ -100,6 +117,7 @@ extensions: []
|
|
100
117
|
extra_rdoc_files: []
|
101
118
|
files:
|
102
119
|
- .gitignore
|
120
|
+
- .ruby-version
|
103
121
|
- Gemfile
|
104
122
|
- LICENSE
|
105
123
|
- README.md
|
@@ -112,31 +130,37 @@ files:
|
|
112
130
|
- lib/ongaku_ryoho_server/list.rb
|
113
131
|
- lib/ongaku_ryoho_server/process.rb
|
114
132
|
- ongaku_ryoho_server.gemspec
|
133
|
+
- spec/application_spec.rb
|
134
|
+
- spec/data/a.mp3
|
135
|
+
- spec/data/b.mp3
|
136
|
+
- spec/data/c.mp3
|
137
|
+
- spec/spec_helper.rb
|
115
138
|
homepage: https://github.com/icidasset/ongaku_ryoho_server
|
116
139
|
licenses: []
|
140
|
+
metadata: {}
|
117
141
|
post_install_message:
|
118
142
|
rdoc_options: []
|
119
143
|
require_paths:
|
120
144
|
- lib
|
121
145
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
146
|
requirements:
|
124
|
-
- -
|
147
|
+
- - '>='
|
125
148
|
- !ruby/object:Gem::Version
|
126
149
|
version: 1.8.7
|
127
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
-
none: false
|
129
151
|
requirements:
|
130
|
-
- -
|
152
|
+
- - '>='
|
131
153
|
- !ruby/object:Gem::Version
|
132
154
|
version: '0'
|
133
|
-
segments:
|
134
|
-
- 0
|
135
|
-
hash: 1922673208521641221
|
136
155
|
requirements: []
|
137
156
|
rubyforge_project:
|
138
|
-
rubygems_version:
|
157
|
+
rubygems_version: 2.0.2
|
139
158
|
signing_key:
|
140
|
-
specification_version:
|
159
|
+
specification_version: 4
|
141
160
|
summary: Serves music to Ongaku Ryoho clients
|
142
|
-
test_files:
|
161
|
+
test_files:
|
162
|
+
- spec/application_spec.rb
|
163
|
+
- spec/data/a.mp3
|
164
|
+
- spec/data/b.mp3
|
165
|
+
- spec/data/c.mp3
|
166
|
+
- spec/spec_helper.rb
|