pig-media-server 1500 → 2000

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc54f9184c672581fb17deec0595fbb9a51798dd
4
- data.tar.gz: 0445b45dd4e055005cbd1ba53b04942616be1ad0
3
+ metadata.gz: dab850bdae7c3e0de1ef2cd2b31a041892e008e7
4
+ data.tar.gz: 34defff9f55b15ade326f44c716f21d432f62631
5
5
  SHA512:
6
- metadata.gz: da2888ca26f7840489e54146513e5422c332f03a3087a15fed11c6fb22054db4960ec13180ea0d9d1d28b10347090f91cb28f367b24e65b9c4feba664f049cbb
7
- data.tar.gz: 61b9254791ae2f467b624b5adb68babf1ad3b4c2eeb30c87f96ba40fa21a576585d0b682eddd231a844edcfa1d109d5010cd623f3f41acda901afd95e98b5c52
6
+ metadata.gz: ada348c8e28316f833e98bbe86b374036465ae2403e4d6f70fbee0120e34576a5c62daaccd9791063c0eebeaea8443de66b6d0f1cf7660a53db2b26eb343c5ab
7
+ data.tar.gz: beb055da9f66b87cfcfea986589b1f936e1a76d692de985637651201a4154c1159ad9a000e83441f229eecbedc5da9e1d9faa9ebff1fdc5aaf81cda583764831
@@ -1,3 +1,3 @@
1
1
  module PigMediaServer
2
- VERSION = "1500"
2
+ VERSION = "2000"
3
3
  end
@@ -15,6 +15,8 @@ require 'redcarpet'
15
15
  require 'json'
16
16
  require 'twitter'
17
17
  require 'tempfile'
18
+ require 'tmpdir'
19
+
18
20
 
19
21
  module PigMediaServer
20
22
  CONFIG = Pit.get 'Pig Media Sever'
@@ -30,36 +32,39 @@ module PigMediaServer
30
32
 
31
33
  class Gyazo
32
34
  def self.tweet url, comment, key, secret, token, token_secret, c
33
- $config = $config ||Pit.get("Pig Media Server")
34
- name = $config['gyazo_path'] + "/#{rand(256**16).to_s(16)}.png"
35
- jpg = name.sub(/png$/, 'jpg')
36
- img = url.sub(/data:image\/png;base64,/, '').unpack('m').first
37
- open(name, 'w'){|f| f.puts img}
38
- system "gm", "convert", name, jpg
39
- client = Twitter::REST::Client.new do |config|
40
- config.consumer_key = key
41
- config.consumer_secret = secret
42
- config.access_token = token
43
- config.access_token_secret = token_secret
44
- end
45
- client.update_with_media(comment.to_s, open(jpg))# rescue nil
46
- FileUtils.rm name
47
- FileUtils.rm jpg
35
+ Dir.mktmpdir do |dir|
36
+ name = dir + "/#{rand(256**16).to_s(16)}.png"
37
+ jpg = name.sub(/png$/, 'jpg')
38
+ img = url.sub(/data:image\/png;base64,/, '').unpack('m').first
39
+ open(name, 'w'){|f| f.puts img}
40
+ system "gm", "convert", name, jpg
41
+ client = Twitter::REST::Client.new do |config|
42
+ config.consumer_key = key
43
+ config.consumer_secret = secret
44
+ config.access_token = token
45
+ config.access_token_secret = token_secret
46
+ end
47
+
48
+ client.update_with_media(comment.to_s, open(jpg))# rescue nil
49
+ FileUtils.rm name
50
+ FileUtils.rm jpg
51
+ end
48
52
  end
53
+
49
54
  def self.post url, point
50
55
  imagedata = url.sub(/data:image\/png;base64,/, '').unpack('m').first
51
56
  boundary = '----BOUNDARYBOUNDARY----'
52
- id = rand(256**16).to_s(16)
57
+ id = rand(256**16).to_s(16)
53
58
 
54
59
  data = <<EOF
55
60
  --#{boundary}\r
56
61
  content-disposition: form-data; name="id"\r
57
62
  \r
58
- #{id}\r
63
+ #{id}\r
59
64
  --#{boundary}\r
60
65
  content-disposition: form-data; name="imagedata"; filename="gyazo.com"\r
61
66
  \r
62
- #{imagedata}\r
67
+ #{imagedata}\r
63
68
  --#{boundary}--\r
64
69
  EOF
65
70
  header ={
@@ -80,14 +85,14 @@ EOF
80
85
  class Web < Sinatra::Base
81
86
  register Sinatra::Flash
82
87
  include PigMediaServer::API
83
-
88
+
84
89
  configure do
85
90
  set :haml, escape_html: true
86
91
  set :haml, attr_wrapper: '"'
87
92
  set :logging, true
88
93
  use Rack::Session::Cookie, key: 'pigmeidaserver', secret: $session_secret || rand(256**16).to_s(16)
89
94
  end
90
-
95
+
91
96
  get '/' do
92
97
  haml :react
93
98
  end
@@ -114,6 +119,7 @@ EOF
114
119
  get('/meta/:key') do
115
120
  haml :react
116
121
  end
122
+
117
123
  get('/sub/:key'){@p = Pig.find(params[:key]);haml :sub}
118
124
  get('/webvtt/:key'){@p = Pig.find(params[:key]); content_type :text; @p.webvtt}
119
125
  get '/delete/:key' do
@@ -125,7 +131,6 @@ EOF
125
131
  redirect params[:href]
126
132
  end
127
133
 
128
-
129
134
  get '/read/:key' do
130
135
  if request.xhr?
131
136
  @record = Pig.find params[:key] rescue nil
@@ -135,6 +140,7 @@ EOF
135
140
  raise
136
141
  end
137
142
  end
143
+
138
144
  get('/book/info/:key'){ content_type :json; Pig.find(params[:key]).comic.info(params[:page]).to_json}
139
145
  get '/book/image' do
140
146
  image, type = Pig.find(params[:id]).comic.page(params[:page])
@@ -152,6 +158,7 @@ EOF
152
158
  content_type :json
153
159
  {url: url}.to_json
154
160
  end
161
+
155
162
  post '/gyazo/tweet' do
156
163
  consumer_key = UserData.load session[:user_id], 'consumer_key'
157
164
  consumer_secret = UserData.load session[:user_id], 'consumer_secret'
@@ -161,15 +168,14 @@ EOF
161
168
  true
162
169
  end
163
170
 
164
-
165
171
  get '/remote' do
166
172
  if request.xhr? and params[:key]
167
173
  return partial :_link, locals: {l: Pig.find(params[:key])}
168
174
  end
175
+
169
176
  return haml :remote
170
177
  end
171
178
 
172
-
173
179
  get '/sessions' do
174
180
  if session[:user_id]
175
181
  session[:user_id] = nil
@@ -189,7 +195,6 @@ EOF
189
195
  end
190
196
  end
191
197
 
192
-
193
198
  post '/sessions' do
194
199
  session[:user_id] = params[:user_id]
195
200
  p session
@@ -226,13 +231,14 @@ EOF
226
231
  get('/*.css'){scss params[:splat].first.to_sym}
227
232
  get('/bundle.js'){content_type :js; open(File::dirname(__FILE__)+"/views/bundle.js").read}
228
233
  get('/*.js'){coffee params[:splat].first.to_sym}
229
-
234
+
230
235
  post '/api/save' do
231
236
  key = Digest::MD5.hexdigest(params[:name]).to_s
232
237
  FileUtils.mkdir_p "#{config['user_data_path']}/api_data"
233
238
  open("#{config['user_data_path']}/api_data/#{key}", 'w'){|x| x.puts params[:body]}
234
239
  true
235
240
  end
241
+
236
242
  get '/api/get' do
237
243
  key = Digest::MD5.hexdigest(params[:name]).to_s
238
244
  FileUtils.mkdir_p "#{config['user_data_path']}/api_data"
@@ -242,6 +248,7 @@ EOF
242
248
  nil
243
249
  end
244
250
  end
251
+
245
252
  post '/api/capapi' do
246
253
  record = Groonga['Files'][params[:key]]
247
254
  name = "#{rand(256**16).to_s(16)}.jpg"
@@ -262,17 +269,19 @@ EOF
262
269
  haml :index
263
270
  end
264
271
 
265
-
266
272
  helpers do
267
273
  def config
268
274
  $config = Pit.get("Pig Media Server") unless $config
269
275
  $config['page_title'] = 'Pig Media Server' unless $config['page_title']
270
276
  $config
271
277
  end
278
+
272
279
  def h str; CGI.escapeHTML str.to_s; end
280
+
273
281
  def remote?
274
282
  UserData.load(session[:user_id], 'remote')
275
283
  end
284
+
276
285
  def partial(template, *args)
277
286
  options = args.last.is_a?(Hash) ? args.pop : {}
278
287
  options.merge!(:layout => false)
@@ -283,40 +292,41 @@ EOF
283
292
  else
284
293
  haml(template, options)
285
294
  end
286
- end
295
+ end
287
296
 
288
297
  def star? key
289
298
  Stars.star?(session[:user_id], key)
290
299
  end
291
-
300
+
292
301
  def markdown str
293
- str = str.to_s
294
- Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(hard_wrap: true), autolink: true, fenced_code_blocks: true).render(str)
302
+ str = str.to_s
303
+ Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(hard_wrap: true), autolink: true, fenced_code_blocks: true).render(str)
295
304
  end
296
-
305
+
297
306
  def number_to_human_size(number, precision = 1)
298
307
  number = begin
299
- Float(number)
300
- rescue ArgumentError, TypeError
301
- return number
302
- end
308
+ Float(number)
309
+ rescue ArgumentError, TypeError
310
+ return number
311
+ end
312
+
303
313
  case
304
- when number.to_i == 1 then
305
- "1 Byte"
306
- when number < 1024 then
307
- "%d Bytes" % number
308
- when number < 1048576 then
309
- "%.#{precision}f KB" % (number / 1024)
310
- when number < 1073741824 then
311
- "%.#{precision}f MB" % (number / 1048576)
312
- when number < 1099511627776 then
313
- "%.#{precision}f GB" % (number / 1073741824)
314
- else
315
- "%.#{precision}f TB" % (number / 1099511627776)
314
+ when number.to_i == 1 then
315
+ "1 Byte"
316
+ when number < 1024 then
317
+ "%d Bytes" % number
318
+ when number < 1048576 then
319
+ "%.#{precision}f KB" % (number / 1024)
320
+ when number < 1073741824 then
321
+ "%.#{precision}f MB" % (number / 1048576)
322
+ when number < 1099511627776 then
323
+ "%.#{precision}f GB" % (number / 1073741824)
324
+ else
325
+ "%.#{precision}f TB" % (number / 1099511627776)
316
326
  end.sub(/([0-9]\.\d*?)0+ /, '\1 ' ).sub(/\. /,' ').encode('UTF-8')
317
327
  rescue
318
328
  ""
319
- end
329
+ end
320
330
 
321
331
  def title
322
332
  base = $config['page_title']
@@ -326,5 +336,4 @@ EOF
326
336
  end
327
337
  end
328
338
  end
329
-
330
339
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pig-media-server
3
3
  version: !ruby/object:Gem::Version
4
- version: '1500'
4
+ version: '2000'
5
5
  platform: ruby
6
6
  authors:
7
7
  - ssig33