pig-media-server 2 → 100
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.babelrc +3 -0
- data/Gemfile +1 -0
- data/front/application.js +71 -0
- data/front/components/custom.js +35 -0
- data/front/components/head.js +38 -0
- data/front/components/index.js +23 -0
- data/front/components/item.js +63 -0
- data/front/components/latest.js +32 -0
- data/front/components/new_flag.js +29 -0
- data/front/components/no_match.js +10 -0
- data/front/components/pager.js +38 -0
- data/{javascripts → front}/components/player.js +7 -11
- data/{javascripts → front}/components/query_list.js +6 -23
- data/front/components/recommend.js +41 -0
- data/front/components/search.js +87 -0
- data/front/components/search_box.js +56 -0
- data/{javascripts → front}/components/watch.js +8 -5
- data/front/controller.js +22 -0
- data/{javascripts/event_dispatcher.js → front/models/base.js} +1 -5
- data/front/models/config.js +12 -0
- data/front/models/custom.js +41 -0
- data/front/models/custom_list.js +12 -0
- data/front/models/latest.js +60 -0
- data/front/models/list.js +76 -0
- data/front/models/playing.js +11 -0
- data/front/models/recent.js +34 -0
- data/front/models/recommend.js +13 -0
- data/front/models/session.js +16 -0
- data/lib/pig-media-server/api.rb +35 -3
- data/lib/pig-media-server/backup.rb +3 -7
- data/lib/pig-media-server/model/comic.rb +1 -1
- data/lib/pig-media-server/model/data.rb +85 -81
- data/lib/pig-media-server/model/data_use_rdb.rb +124 -0
- data/lib/pig-media-server/version.rb +1 -1
- data/lib/pig-media-server/views/bundle.js +48 -13
- data/package.json +13 -18
- data/webpack.build.js +25 -0
- data/webpack.config.js +30 -0
- metadata +34 -19
- data/gulpfile.js +0 -33
- data/javascripts/application.js +0 -117
- data/javascripts/components/head.js +0 -106
- data/javascripts/components/list.js +0 -104
- data/javascripts/components/new_flag.js +0 -23
- data/javascripts/components/sort.js +0 -64
- data/javascripts/controller.js +0 -62
- data/javascripts/custom_list.js +0 -14
- data/javascripts/recent.js +0 -34
- data/javascripts/utils.js +0 -22
- data/javascripts/video.js +0 -10
- /data/{javascripts → front}/chromecast.js +0 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
#coding:utf-8
|
2
|
+
require 'fileutils'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'pig-media-server/model/migrate'
|
5
|
+
|
6
|
+
require 'active_record'
|
7
|
+
|
8
|
+
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
|
9
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
10
|
+
|
11
|
+
tables = ActiveRecord::Base.connection.tables
|
12
|
+
|
13
|
+
unless tables.index('app_datas')
|
14
|
+
ActiveRecord::Migration.create_table :app_datas do |t|
|
15
|
+
t.string :key
|
16
|
+
t.string :original_key
|
17
|
+
t.text :value
|
18
|
+
t.timestamps null: false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
unless tables.index('stars')
|
23
|
+
ActiveRecord::Migration.create_table :stars do |t|
|
24
|
+
t.string :user_id
|
25
|
+
t.string :key
|
26
|
+
t.timestamps null: false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
unless tables.index('recents')
|
31
|
+
ActiveRecord::Migration.create_table :recents do |t|
|
32
|
+
t.string :user_id
|
33
|
+
t.string :key
|
34
|
+
t.timestamps null: false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class AppData < ActiveRecord::Base
|
39
|
+
def self.find key
|
40
|
+
key = Digest::MD5.hexdigest(key)
|
41
|
+
a = self.where(key: key).first
|
42
|
+
if a
|
43
|
+
a.parse
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.set key, value
|
50
|
+
a_key = Digest::MD5.hexdigest(key)
|
51
|
+
a = self.find_or_create_by(key: a_key)
|
52
|
+
a.value = value.to_json
|
53
|
+
a.original_key = key
|
54
|
+
a.save!
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.all
|
58
|
+
super.map{|x| {key: x.original_key, value: x.parse}}
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse
|
62
|
+
val = self.value
|
63
|
+
case val
|
64
|
+
when 'true'
|
65
|
+
true
|
66
|
+
when 'false'
|
67
|
+
false
|
68
|
+
else
|
69
|
+
JSON.parse val
|
70
|
+
end
|
71
|
+
|
72
|
+
rescue
|
73
|
+
if val.class == String
|
74
|
+
val.gsub(/^"|"$/, '')
|
75
|
+
else
|
76
|
+
val
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class Star < ActiveRecord::Base
|
82
|
+
end
|
83
|
+
|
84
|
+
class Stars
|
85
|
+
def self.list user
|
86
|
+
Pig.find Star.where(user_id: user).map{|x| x.key}
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.star? user, key
|
90
|
+
!!Star.where(user_id: user, key: key).first
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.star user, key
|
94
|
+
Star.find_or_create_by(user_id: user, key: key)
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.unstar user, key
|
98
|
+
s = Star.where(user_id: user, key: key).first
|
99
|
+
s.destroy if s
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Recent < ActiveRecord::Base
|
104
|
+
end
|
105
|
+
|
106
|
+
class Recents
|
107
|
+
def self.list user
|
108
|
+
hash = {}
|
109
|
+
Recent.where(user_id: user).each{|r|
|
110
|
+
hash[r.key] = {}
|
111
|
+
}
|
112
|
+
hash
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.recent? user, key
|
116
|
+
!!Recent.where(user_id: user, key: key).first
|
117
|
+
rescue
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.recent user, key
|
122
|
+
Recent.find_or_create_by(user_id: user, key: key)
|
123
|
+
end
|
124
|
+
end
|