geoblacklight 0.9.0 → 0.9.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a389fc333cbe630a7ac3660914238f022e23bff8
|
4
|
+
data.tar.gz: 2bce6269f6d334bc6b9dc26a67adc45fc4da5404
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0dcb5fab1faeec1b5717df0e1fe30ee6b72895b360e02ffc76bac454b08106565620b60e2d1d2de14b69500f04c876726e2da7672ff9d2053d6ed2751aee62c
|
7
|
+
data.tar.gz: bb025868024d82323684086345dcb387382e3bf6485d7f0f4dbaa1070e96a827c42a8b7c58f4cad06af868bda63f54a89049d386a9ec63d934bb61d7c44a2dea
|
@@ -32,7 +32,7 @@ class DownloadController < ApplicationController
|
|
32
32
|
# Grab the solr document to check if it should be public or not
|
33
33
|
@response, @document = fetch(file_name_to_id(params[:id]))
|
34
34
|
restricted_should_authenticate
|
35
|
-
send_file
|
35
|
+
send_file download_file_path_and_name, type: 'application/zip', x_sendfile: true
|
36
36
|
end
|
37
37
|
|
38
38
|
def hgl
|
@@ -75,6 +75,10 @@ class DownloadController < ApplicationController
|
|
75
75
|
|
76
76
|
private
|
77
77
|
|
78
|
+
def download_file_path_and_name
|
79
|
+
"#{Geoblacklight::Download.file_path}/#{params[:id]}.#{params[:format]}"
|
80
|
+
end
|
81
|
+
|
78
82
|
def check_type
|
79
83
|
response = case params[:type]
|
80
84
|
when 'shapefile'
|
@@ -13,12 +13,16 @@ module Geoblacklight
|
|
13
13
|
"#{@document[:layer_slug_s]}-#{@options[:type]}.#{@options[:extension]}"
|
14
14
|
end
|
15
15
|
|
16
|
-
def file_path
|
16
|
+
def self.file_path
|
17
17
|
Settings.DOWNLOAD_PATH || "#{Rails.root}/tmp/cache/downloads"
|
18
18
|
end
|
19
19
|
|
20
|
+
def file_path_and_name
|
21
|
+
"#{self.class.file_path}/#{file_name}"
|
22
|
+
end
|
23
|
+
|
20
24
|
def download_exists?
|
21
|
-
File.file?(
|
25
|
+
File.file?(file_path_and_name)
|
22
26
|
end
|
23
27
|
|
24
28
|
def get
|
@@ -35,18 +39,18 @@ module Geoblacklight
|
|
35
39
|
# @return [String] filename of the completed download
|
36
40
|
def create_download_file
|
37
41
|
download = initiate_download
|
38
|
-
File.open("#{
|
42
|
+
File.open("#{file_path_and_name}.tmp", 'wb') do |file|
|
39
43
|
if download.headers['content-type'] == @options[:content_type]
|
40
44
|
file.write download.body
|
41
45
|
else
|
42
46
|
fail Geoblacklight::Exceptions::WrongDownloadFormat
|
43
47
|
end
|
44
48
|
end
|
45
|
-
File.rename("#{
|
49
|
+
File.rename("#{file_path_and_name}.tmp", "#{file_path_and_name}")
|
46
50
|
file_name
|
47
51
|
rescue Geoblacklight::Exceptions::WrongDownloadFormat => error
|
48
52
|
Geoblacklight.logger.error "#{error} expected #{@options[:content_type]} received #{download.headers['content-type']}"
|
49
|
-
File.delete("#{
|
53
|
+
File.delete("#{file_path_and_name}.tmp")
|
50
54
|
raise Geoblacklight::Exceptions::ExternalDownloadFailed, message: 'Wrong download type'
|
51
55
|
end
|
52
56
|
|
@@ -20,11 +20,11 @@ describe Geoblacklight::Download do
|
|
20
20
|
end
|
21
21
|
describe '#file_path' do
|
22
22
|
it 'should return the path with name and extension' do
|
23
|
-
expect(download.file_path).to eq "#{Rails.root}/tmp/cache/downloads"
|
23
|
+
expect(download.class.file_path).to eq "#{Rails.root}/tmp/cache/downloads"
|
24
24
|
end
|
25
25
|
it 'should be configurable' do
|
26
26
|
expect(Settings).to receive(:DOWNLOAD_PATH).and_return('configured/path')
|
27
|
-
expect(download.file_path).to eq 'configured/path'
|
27
|
+
expect(download.class.file_path).to eq 'configured/path'
|
28
28
|
end
|
29
29
|
end
|
30
30
|
describe '#download_exists?' do
|
@@ -45,7 +45,7 @@ describe Geoblacklight::Download do
|
|
45
45
|
it 'should call create_download_file if it does not exist' do
|
46
46
|
expect(download).to receive(:download_exists?).and_return(false)
|
47
47
|
expect(download).to receive(:initiate_download).and_return(object: 'file')
|
48
|
-
expect(File).to receive(:open).with("#{download.
|
48
|
+
expect(File).to receive(:open).with("#{download.file_path_and_name}.tmp", 'wb').and_return('')
|
49
49
|
expect(File).to receive(:rename)
|
50
50
|
expect(download.get).to eq 'test-shapefile.zip'
|
51
51
|
end
|
@@ -54,13 +54,13 @@ describe Geoblacklight::Download do
|
|
54
54
|
it 'should create the file in fs and delete it if the content headers are not correct' do
|
55
55
|
bad_file = OpenStruct.new(headers: { 'content-type' => 'bad/file' })
|
56
56
|
expect(download).to receive(:initiate_download).and_return(bad_file)
|
57
|
-
expect(File).to receive(:delete).with("#{download.
|
57
|
+
expect(File).to receive(:delete).with("#{download.file_path_and_name}.tmp").and_return(nil)
|
58
58
|
expect { download.create_download_file }.to raise_error(Geoblacklight::Exceptions::ExternalDownloadFailed, 'Wrong download type')
|
59
59
|
end
|
60
60
|
it 'should create the file, write it, and then rename from tmp if everything is ok' do
|
61
61
|
shapefile = OpenStruct.new(headers: {'content-type' => 'application/zip'})
|
62
62
|
expect(download).to receive(:initiate_download).and_return(shapefile)
|
63
|
-
expect(File).to receive(:open).with("#{download.
|
63
|
+
expect(File).to receive(:open).with("#{download.file_path_and_name}.tmp", 'wb').and_return('')
|
64
64
|
expect(File).to receive(:rename)
|
65
65
|
expect(download.create_download_file).to eq download.file_name
|
66
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoblacklight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Graves
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-04-
|
14
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: blacklight
|