rozporek 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/config.ru +3 -0
- data/lib/rozporek.rb +15 -0
- data/lib/rozporek/extract.rb +25 -0
- data/lib/rozporek/rails.rb +4 -0
- data/lib/rozporek/version.rb +3 -0
- data/lib/rozporek/web.rb +44 -0
- data/public/.gitkeep +0 -0
- data/rozporek.gemspec +33 -0
- data/web/views/index.erb +32 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 687ca495d7d9b7d184f744de354a4b10a35ad914
|
4
|
+
data.tar.gz: 8c4168e06e7064d81b185ec0fc164df5a71fc48c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9dfaabc2c8c1c6991071a7afef0b7b93416af527793d6884b80b7598608b5946e38e8f0e0deecaeca24a962e09684cc324997a0399cdf973fda840fcfe6d775
|
7
|
+
data.tar.gz: 79fd25523b97efdc16a8cc9b2dd4810463133f593b5e0afa2b5e3d430b0ed6355c3892800d901fd23055376254915ec0260a1d40829016fdb5a086c5f5d72e9b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Adam Sokolnicki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Local
|
2
|
+
|
3
|
+
A Sinatra app for uploading and extracting the zip files
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rozporek', github: 'asok/local'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Rails application
|
20
|
+
|
21
|
+
#### Setup backend
|
22
|
+
|
23
|
+
#### Mount
|
24
|
+
|
25
|
+
Add this to the routes:
|
26
|
+
|
27
|
+
```rb
|
28
|
+
mount Local::Web => '/rozporek', :as => 'rozporek'
|
29
|
+
```
|
30
|
+
|
31
|
+
## Testing
|
32
|
+
|
33
|
+
`bundle exec rspec`
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/asok/local.
|
38
|
+
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
43
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/config.ru
ADDED
data/lib/rozporek.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rozporek/version"
|
2
|
+
require "rozporek/web"
|
3
|
+
require 'rozporek/rails'
|
4
|
+
|
5
|
+
module Rozporek
|
6
|
+
module Methods
|
7
|
+
def dirs
|
8
|
+
Dir.entries("#{Rozporek::Web.root}/public").delete_if do |file|
|
9
|
+
file == 'index.erb' || file == '.' || file == '..'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
extend Methods
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
module Rozporek
|
4
|
+
module Extract
|
5
|
+
def call(file_hash, dest, root)
|
6
|
+
Zip::File.open(file_hash[:tempfile].path) do |zip_file|
|
7
|
+
zip_file.each do |f|
|
8
|
+
f_path = File.join("#{root}/public/#{env_prefix}#{dest}", f.name)
|
9
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
10
|
+
zip_file.extract(f, f_path)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def env_prefix
|
16
|
+
if ENV['RACK_ENV'] == 'test'
|
17
|
+
'test'
|
18
|
+
else
|
19
|
+
''
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
extend self
|
24
|
+
end
|
25
|
+
end
|
data/lib/rozporek/web.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'rack-flash'
|
4
|
+
|
5
|
+
require_relative './extract'
|
6
|
+
|
7
|
+
module Rozporek
|
8
|
+
class Web < Sinatra::Base
|
9
|
+
enable :sessions
|
10
|
+
|
11
|
+
use Rack::Flash
|
12
|
+
|
13
|
+
set :root, File.expand_path(File.dirname(__FILE__) + "/../..")
|
14
|
+
set :views, "#{root}/web/views"
|
15
|
+
|
16
|
+
get('/') do
|
17
|
+
erb :index
|
18
|
+
end
|
19
|
+
|
20
|
+
post('/') do
|
21
|
+
if params[:file][:type] == 'application/zip'
|
22
|
+
Rozporek::Extract.call(params[:file], params[:dirname], self.class.root)
|
23
|
+
flash[:notice] = 'Success'
|
24
|
+
else
|
25
|
+
flash[:error] = 'It should be a zip file'
|
26
|
+
end
|
27
|
+
|
28
|
+
redirect '/'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if defined?(::ActionDispatch::Request::Session) &&
|
34
|
+
!::ActionDispatch::Request::Session.respond_to?(:each)
|
35
|
+
# mperham/sidekiq#2460
|
36
|
+
# Rack apps can't reuse the Rails session store without
|
37
|
+
# this monkeypatch
|
38
|
+
class ActionDispatch::Request::Session
|
39
|
+
def each(&block)
|
40
|
+
hash = self.to_hash
|
41
|
+
hash.each(&block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/public/.gitkeep
ADDED
File without changes
|
data/rozporek.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rozporek/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rozporek"
|
8
|
+
spec.version = Rozporek::VERSION
|
9
|
+
spec.authors = ["Adam Sokolnicki"]
|
10
|
+
spec.email = ["adam.sokolnicki@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A sinatra app for uploading zip files and storing them in the publick dir}
|
13
|
+
spec.description = %q{A sinatra app for uploading zip files and storing them in the publick dir}
|
14
|
+
spec.homepage = "https://github.com/asok/rozporek"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "byebug"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "capybara"
|
28
|
+
|
29
|
+
spec.add_dependency "sinatra"
|
30
|
+
spec.add_dependency "sinatra-contrib"
|
31
|
+
spec.add_dependency "rubyzip"
|
32
|
+
spec.add_dependency "rack-flash3"
|
33
|
+
end
|
data/web/views/index.erb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Rozporek</title>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
7
|
+
<meta name="google" content="notranslate" />
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<div>
|
11
|
+
<%= env['x-rack.flash'][:notice] %>
|
12
|
+
<%= env['x-rack.flash'][:error] %>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<div>
|
16
|
+
<form method="POST" action="<%= request.path %>" enctype="multipart/form-data">
|
17
|
+
<div>
|
18
|
+
<label for="dirname">
|
19
|
+
The name of the directory to extract to (leave empty to not extract to a top dir)
|
20
|
+
</label>
|
21
|
+
<input type="text" name="dirname">
|
22
|
+
</div>
|
23
|
+
|
24
|
+
|
25
|
+
<div>
|
26
|
+
<input type="file" name="file">
|
27
|
+
</div>
|
28
|
+
<button type="submit">Submit</button>
|
29
|
+
</form>
|
30
|
+
</div>
|
31
|
+
</body>
|
32
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rozporek
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Sokolnicki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: capybara
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sinatra
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sinatra-contrib
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubyzip
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rack-flash3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: A sinatra app for uploading zip files and storing them in the publick
|
154
|
+
dir
|
155
|
+
email:
|
156
|
+
- adam.sokolnicki@gmail.com
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- Gemfile
|
163
|
+
- LICENSE.txt
|
164
|
+
- README.md
|
165
|
+
- Rakefile
|
166
|
+
- bin/console
|
167
|
+
- config.ru
|
168
|
+
- lib/rozporek.rb
|
169
|
+
- lib/rozporek/extract.rb
|
170
|
+
- lib/rozporek/rails.rb
|
171
|
+
- lib/rozporek/version.rb
|
172
|
+
- lib/rozporek/web.rb
|
173
|
+
- public/.gitkeep
|
174
|
+
- rozporek.gemspec
|
175
|
+
- web/views/index.erb
|
176
|
+
homepage: https://github.com/asok/rozporek
|
177
|
+
licenses:
|
178
|
+
- MIT
|
179
|
+
metadata: {}
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubyforge_project:
|
196
|
+
rubygems_version: 2.4.5.1
|
197
|
+
signing_key:
|
198
|
+
specification_version: 4
|
199
|
+
summary: A sinatra app for uploading zip files and storing them in the publick dir
|
200
|
+
test_files: []
|
201
|
+
has_rdoc:
|