gitpic 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/gitpic/uploader.rb +32 -9
  2. data/lib/gitpic.rb +1 -1
  3. metadata +7 -7
@@ -18,7 +18,8 @@ class Gitpic::Uploader
18
18
  if File.directory?(path)
19
19
  upload!(path)
20
20
  else
21
- checksum = Digest::MD5.file(path).hexdigest
21
+ next unless photo_extension? file_name
22
+ checksum = Digest::SHA1.file(path).hexdigest
22
23
  if check_file(checksum)
23
24
  puts "Uploading #{path}"
24
25
  post_file(path)
@@ -35,17 +36,39 @@ class Gitpic::Uploader
35
36
  end
36
37
 
37
38
  def post_file(path)
38
- file = File.new(path, 'rb')
39
- RestClient.post( "#{Gitpic::HOST}/api/file_blobs?auth_token=#{token}", :file_blob => {
40
- :data => file,
41
- :path => path,
42
- :filesystem_created_at => file.ctime,
43
- :filesystem_modified_at => file.mtime
44
- })
39
+ tries = 0
40
+ begin
41
+ file = File.new(path, 'rb')
42
+ RestClient.post( "#{Gitpic::HOST}/api/file_blobs?auth_token=#{token}", :file_blob => {
43
+ :data => file,
44
+ :path => path,
45
+ :filesystem_created_at => file.ctime,
46
+ :filesystem_modified_at => file.mtime
47
+ })
48
+ rescue RestClient::PreconditionFailed => e
49
+ puts "Failed to upload #{path}; #{e.response}"
50
+ rescue RestClient::RequestTimeout, RestClient::ServiceUnavailable => e
51
+ if tries < 10
52
+ tries += 1
53
+ puts "Server temporarily unavailable, trying again (#{tries} time)"
54
+ sleep 30
55
+ retry
56
+ else
57
+ puts "Server is fully non-responsive, try re-running the uploader later"
58
+ raise "Stop flogging the server, it's already dead!!!"
59
+ end
60
+ rescue Errno::EPIPE
61
+ puts "Failed to upload #{path}; [\"File is too large\"]"
62
+ end
63
+ end
64
+
65
+ def photo_extension?(file_name)
66
+ photo_extensions = %w(jpg jpeg png gif)
67
+ photo_extensions.include? file_name.split('.').last
45
68
  end
46
69
 
47
70
  def black_list
48
- [".", "..", ".DS_Store"]
71
+ [".", "..", ".DS_Store", "Thumbs.db"]
49
72
  end
50
73
 
51
74
  end
data/lib/gitpic.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Gitpic
2
- HOST = "http://gitpic.com"
2
+ HOST = ENV['GITPIC_HOST'] || "http://gitpic.com"
3
3
  end
4
4
 
5
5
  require 'gitpic/uploader'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitpic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: term-ansicolor
16
- requirement: &2156246360 !ruby/object:Gem::Requirement
16
+ requirement: &2164703760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156246360
24
+ version_requirements: *2164703760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &2156245820 !ruby/object:Gem::Requirement
27
+ requirement: &2164703200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.6.7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156245820
35
+ version_requirements: *2164703200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thor
38
- requirement: &2156245320 !ruby/object:Gem::Requirement
38
+ requirement: &2164702740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 0.14.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2156245320
46
+ version_requirements: *2164702740
47
47
  description: A ruby command line interface for uploading to GitPic
48
48
  email: rosshale@gmail.com
49
49
  executables: