browse-everything 0.16.1 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +3 -0
  3. data/CODE_OF_CONDUCT.md +36 -0
  4. data/CONTRIBUTING.md +21 -19
  5. data/Gemfile +1 -0
  6. data/README.md +29 -9
  7. data/SUPPORT.md +5 -0
  8. data/app/controllers/browse_everything_controller.rb +7 -3
  9. data/app/views/browse_everything/_files.html.erb +14 -6
  10. data/app/views/browse_everything/index.html.erb +7 -1
  11. data/browse-everything.gemspec +5 -5
  12. data/lib/browse_everything/driver/base.rb +1 -1
  13. data/lib/browse_everything/driver/box.rb +4 -14
  14. data/lib/browse_everything/driver/dropbox.rb +34 -11
  15. data/lib/browse_everything/driver/google_drive.rb +2 -2
  16. data/lib/browse_everything/driver/s3.rb +8 -14
  17. data/lib/browse_everything/retriever.rb +4 -5
  18. data/lib/browse_everything/version.rb +1 -1
  19. data/lib/generators/browse_everything/templates/browse_everything_providers.yml.example +2 -2
  20. data/spec/controllers/browse_everything_controller_spec.rb +8 -1
  21. data/spec/lib/browse_everything/driver/box_spec.rb +114 -34
  22. data/spec/lib/browse_everything/driver/dropbox_spec.rb +53 -5
  23. data/spec/lib/browse_everything/driver/google_drive_spec.rb +41 -4
  24. data/spec/lib/browse_everything/driver/s3_spec.rb +27 -18
  25. data/spec/lib/browse_everything/retriever_spec.rb +65 -2
  26. data/spec/spec_helper.rb +4 -9
  27. data/spec/support/capybara.rb +14 -10
  28. metadata +31 -37
  29. data/spec/fixtures/vcr_cassettes/box.yml +0 -498
  30. data/spec/fixtures/vcr_cassettes/dropbox.yml +0 -282
  31. data/spec/fixtures/vcr_cassettes/google_drive.yml +0 -331
  32. data/spec/fixtures/vcr_cassettes/retriever.yml +0 -170
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 36223786bc3a801a4cde821810d4e8976f0a1034fcc228acaea6a7eba411770e
4
- data.tar.gz: 1611bfb8566183526c1489bb3de4dd8beac2147c7cf0b637d18a445267984daf
2
+ SHA1:
3
+ metadata.gz: 46cd3b246ede692cfea34a3251136fe8eb5e64a1
4
+ data.tar.gz: b0bc78f050b3c55dae7b3dab2962c606ecc9cf8c
5
5
  SHA512:
6
- metadata.gz: 47f835658832bc8837d99c18f4e3dae6a5e8d1edebb183950022a3d44c9b309e04437853d727449b1c0705eaf959fa43ab62c7b5c50ccc78298d6b3d6d2d0e0c
7
- data.tar.gz: a725066448c474d91fd38590dbc470ce5bdcf5cf7e60df0721a7ddfbc122fd004a23c99688565ca368610da3adf77f8b95d0bd383f940cf0285d4c189638756e
6
+ metadata.gz: a5e82c374b814abca77205c8d79705eb901952a5cb589559d66c7b6619a2673c8f5978f425f17f7639d9862b5dfb7155d28b1ac15a84ddcfc03246ad394b8b2c
7
+ data.tar.gz: 0a9935875a2ed98761c866e297a7114fa6352da032548f7c4fe9ca164ebd00101ff7404822f56529eb4c38199bb1a54438d55390b8e9317e6550f88b97a0ba07
data/.rubocop.yml CHANGED
@@ -20,6 +20,9 @@ Metrics/ClassLength:
20
20
  - 'lib/browse_everything/driver/google_drive.rb'
21
21
  Metrics/LineLength:
22
22
  Max: 400
23
+ Exclude:
24
+ - 'spec/lib/browse_everything/driver/box_spec.rb'
25
+ - 'spec/lib/browse_everything/driver/dropbox_spec.rb'
23
26
  Metrics/BlockLength:
24
27
  Exclude:
25
28
  - '*.gemspec'
@@ -0,0 +1,36 @@
1
+ The Samvera community is dedicated to providing a welcoming and
2
+ positive experience for all its members, whether they are at a formal
3
+ gathering, in a social setting, or taking part in activities online.
4
+ The Samvera community welcomes participation from people all over the
5
+ world and these members bring with them a wide variety of
6
+ professional, personal and social backgrounds; whatever these may be,
7
+ we treat colleagues with dignity and respect.
8
+
9
+ Community members communicate primarily in English, though for many of
10
+ them this is not their native language. We therefore strive to express
11
+ ourselves simply and clearly remembering that unnecessary use of
12
+ jargon and slang will be a barrier to understanding for many of our
13
+ colleagues. We are sensitive to the fact that the international
14
+ nature of the community means that we span many different social norms
15
+ around language and behaviour and we strive to conduct ourselves,
16
+ online and in person, in ways that are unlikely to cause offence.
17
+
18
+ Samvera conversations are often information-rich and intended to
19
+ generate discussion and debate. We discuss ideas from a standpoint of
20
+ mutual respect and reasoned argument.
21
+
22
+ Community members work together to promote a respectful and safe
23
+ community. In the event that someone’s conduct is causing offence or
24
+ distress, Samvera has a detailed
25
+ [Anti-Harassment Policy and Protocol](https://wiki.duraspace.org/display/samvera/Anti-Harassment+Policy)
26
+ which can be applied to address the problem. The first step in dealing
27
+ with any serious misconduct is to contact a local meeting organizer,
28
+ the
29
+ [Samvera community helpers](https://wiki.duraspace.org/display/samvera/Samvera+Community+Helpers)
30
+ ([email](mailto:helpers@samvera.org)), a community member you
31
+ trust, or the
32
+ [Samvera Steering Group](https://wiki.duraspace.org/display/samvera/Samvera+Steering+Group+membership)
33
+ immediately; at Samvera events, these people can be identified by
34
+ distinctive name badges. The
35
+ [Policy and Protocol](https://wiki.duraspace.org/display/samvera/Anti-Harassment+Policy)
36
+ should be consulted for fuller details.
data/CONTRIBUTING.md CHANGED
@@ -1,19 +1,22 @@
1
1
  # How to Contribute
2
2
 
3
- We want your help to make Samvera Community great.
4
- There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
3
+ We want your help to make the Samvera community great. There are a few guidelines
4
+ that we need contributors to follow so that we can have a chance of
5
+ keeping on top of things.
5
6
 
6
7
  ## Code of Conduct
7
8
 
8
- The Samvera Community is dedicated to providing a welcoming and positive experience for all its
9
- members, whether they are at a formal gathering, in a social setting, or taking part in activities
10
- online. Please see our [Code of Conduct](https://wiki.duraspace.org/display/samvera/Code+of+Conduct)
11
- for more information.
9
+ The Samvera Community is dedicated to providing a welcoming and positive
10
+ experience for all its members, whether they are at a formal gathering, in
11
+ a social setting, or taking part in activities online. Please see our
12
+ [Code of Conduct](CODE_OF_CONDUCT.md) for more information.
12
13
 
13
14
  ## Samvera Community Intellectual Property Licensing and Ownership
14
15
 
15
- All code contributors must have an Individual Contributor License Agreement (iCLA) on file with the Hydra Project Steering Group.
16
- If the contributor works for an institution, the institution must have a Corporate Contributor License Agreement (cCLA) on file.
16
+ All code contributors must have an Individual Contributor License Agreement
17
+ (iCLA) on file with the Samvera Steering Group. If the contributor works for
18
+ an institution, the institution must have a Corporate Contributor License
19
+ Agreement (cCLA) on file.
17
20
 
18
21
  https://wiki.duraspace.org/display/samvera/Samvera+Community+Intellectual+Property+Licensing+and+Ownership
19
22
 
@@ -31,7 +34,7 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
31
34
  ### Reporting Issues
32
35
 
33
36
  * Make sure you have a [GitHub account](https://github.com/signup/free)
34
- * Submit a [Github issue](./issues) by:
37
+ * Submit a [Github issue](https://github.com/samvera/browse-everything/issues) by:
35
38
  * Clearly describing the issue
36
39
  * Provide a descriptive summary
37
40
  * Explain the expected behavior
@@ -48,7 +51,7 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
48
51
  * Please avoid working directly on the `master` branch.
49
52
  * You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
50
53
  * Make sure you have added sufficient tests and documentation for your changes.
51
- * Test functionality with RSpec; est features / UI with Capybara.
54
+ * Test functionality with RSpec; Test features / UI with Capybara.
52
55
  * Run _all_ the tests to assure nothing else was accidentally broken.
53
56
 
54
57
  ### Documenting Code
@@ -60,15 +63,11 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
60
63
  * If you don't know exactly what a bit of code does, it is extra likely that it needs to be documented. Take a stab at it and ask for feedback in your pull request. You can use the 'blame' button on GitHub to identify the original developer of the code and @mention them in your comment.
61
64
  * This work greatly increases the usability of the code base and supports the on-ramping of new committers.
62
65
  * We will all be understanding of one another's time constraints in this area.
63
- * YARD examples:
64
- * [Hyrax::AdminSet](https://github.com/samvera/hyrax/blob/master/app/models/admin_set.rb)
65
- * [ActiveTriples::LocalName::Minter](https://github.com/ActiveTriples/active_triples-local_name/blob/master/lib/active_triples/local_name/minter.rb)
66
66
  * [Getting started with YARD](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
67
67
 
68
68
  ### Committing changes
69
69
 
70
70
  * Make commits of logical units.
71
- * Your commit should include a high level description of your work in HISTORY.textile
72
71
  * Check for unnecessary whitespace with `git diff --check` before committing.
73
72
  * Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
74
73
  * If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
@@ -103,6 +102,10 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
103
102
  long to fit in 72 characters
104
103
  ```
105
104
 
105
+ * Make sure you have added the necessary tests for your changes.
106
+ * Run _all_ the tests to assure nothing else was accidentally broken.
107
+ * When you are ready to submit a pull request
108
+
106
109
  ### Submitting Changes
107
110
 
108
111
  * Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
@@ -125,9 +128,7 @@ We adopted [Github's Pull Request Review](https://help.github.com/articles/about
125
128
  Common checks that may occur in our repositories:
126
129
 
127
130
  1. Travis CI - where our automated tests are running
128
- 2. Hound CI - where we check for style violations
129
- 3. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
130
- 4. CodeClimate - is our code remaining healthy (at least according to static code analysis)
131
+ 2. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
131
132
 
132
133
  If one or more of the required checks failed (or are incomplete), the code should not be merged (and the UI will not allow it). If all of the checks have passed, then anyone on the project (including the pull request submitter) may merge the code.
133
134
 
@@ -144,16 +145,17 @@ First, the person contributing the code is putting themselves out there. Be mind
144
145
  This is your chance for a mentoring moment of another developer. Take time to give an honest and thorough review of what has changed. Things to consider:
145
146
 
146
147
  * Does the commit message explain what is going on?
147
- * Does the code changes have tests? _Not all changes need new tests, some changes are refactors_
148
+ * Does the code changes have tests? _Not all changes need new tests, some changes are refactorings_
148
149
  * Do new or changed methods, modules, and classes have documentation?
149
150
  * Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
150
151
  * Does the description of the new/changed specs match your understanding of what the spec is doing?
152
+ * Did the Travis tests complete successfully?
151
153
 
152
154
  If you are uncertain, bring other contributors into the conversation by assigning them as a reviewer.
153
155
 
154
156
  # Additional Resources
155
157
 
156
158
  * [General GitHub documentation](http://help.github.com/)
157
- * [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
159
+ * [GitHub pull request documentation](https://help.github.com/articles/about-pull-requests/)
158
160
  * [Pro Git](http://git-scm.com/book) is both a free and excellent book about Git.
159
161
  * [A Git Config for Contributing](http://ndlib.github.io/practices/my-typical-per-project-git-config/)
data/Gemfile CHANGED
@@ -39,6 +39,7 @@ else
39
39
  when /^4\.2/
40
40
  gem 'coffee-rails', '~> 4.1.0'
41
41
  gem 'json', '~> 1.8'
42
+ gem 'railties', '~> 4.2'
42
43
  gem 'responders', '~> 2.0'
43
44
  gem 'sass-rails', '>= 5.0'
44
45
  end
data/README.md CHANGED
@@ -1,8 +1,17 @@
1
+ # BrowseEverything
2
+
3
+ Code:
1
4
  [![Gem Version](https://badge.fury.io/rb/browse-everything.png)](http://badge.fury.io/rb/browse-everything)
2
5
  [![Build Status](https://travis-ci.org/samvera/browse-everything.svg?branch=master)](https://travis-ci.org/samvera/browse-everything)
3
6
  [![Coverage Status](https://coveralls.io/repos/samvera/browse-everything/badge.svg?branch=master&service=github)](https://coveralls.io/github/samvera/browse-everything?branch=master)
4
7
 
5
- # BrowseEverything
8
+ Docs:
9
+ [![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md)
10
+ [![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE.txt)
11
+
12
+ Jump in: [![Slack Status](http://slack.samvera.org/badge.svg)](http://slack.samvera.org/)
13
+
14
+ # What is BrowseEverything?
6
15
 
7
16
  This Gem allows your rails application to access user files from cloud storage.
8
17
  Currently there are drivers implemented for [Dropbox](http://www.dropbox.com),
@@ -16,6 +25,18 @@ download the files.
16
25
 
17
26
  **This gem does not depend on hydra-head**
18
27
 
28
+ ## Product Owner & Maintenance
29
+
30
+ BrowseEverything is a Core Component of the Samvera community. The documentation for
31
+ what this means can be found
32
+ [here](http://samvera.github.io/core_components.html#requirements-for-a-core-component).
33
+
34
+ ### Product Owner
35
+
36
+ [mbklein](https://github.com/mbklein)
37
+
38
+ # Getting Started
39
+
19
40
  ## Supported Ruby Releases
20
41
  Currently, the following releases of Ruby are supported:
21
42
  - 2.5.1
@@ -213,14 +234,13 @@ See `spec/support/app/views/file_handler/index.html` for an example use case. Yo
213
234
  create a fully-functioning demo app in `spec/internal` (though you will have to create
214
235
  `spec/internal/config/browse_everything.providers.yml` file with your own configuration info.)
215
236
 
216
- ## Contributing
237
+ # Help
238
+
239
+ The Samvera community is here to help. Please see our [support guide](./SUPPORT.md).
217
240
 
218
- 1. Fork it
219
- 2. Create your feature branch (`git checkout -b my-new-feature`)
220
- 3. Commit your changes (`git commit -am 'Add some feature'`)
221
- 4. Push to the branch (`git push origin my-new-feature`)
222
- 5. Create new Pull Request
241
+ # Acknowledgments
223
242
 
224
- ## Help
243
+ This software has been developed by and is brought to you by the Samvera community. Learn more at the
244
+ [Samvera website](http://samvera.org/).
225
245
 
226
- For help with Browse Everything, contact <samvera-tech@googlegroups.com>.
246
+ ![Samvera Logo](https://wiki.duraspace.org/download/thumbnails/87459292/samvera-fall-font2-200w.png?version=1&modificationDate=1498550535816&api=v2)
data/SUPPORT.md ADDED
@@ -0,0 +1,5 @@
1
+ If you would like to report an issue, first search [the list of issues](https://github.com/samvera/browse-everything/issues/) to see if someone else has already reported it, and then feel free to [create a new issue](https://github.com/samvera/browse-everything/issues/new).
2
+
3
+ If you have questions or need help, please email [the Samvera community tech list](https://groups.google.com/forum/#!forum/samvera-tech) or stop by the #dev channel in [the Samvera community Slack team](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391#Getintouch!-Slack).
4
+
5
+ You can learn more about the various Samvera communication channels on the [Get in touch!](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391) wiki page.
@@ -36,10 +36,10 @@ class BrowseEverythingController < ActionController::Base
36
36
  end
37
37
 
38
38
  # Action for the OAuth2 callback
39
- # Authenticate against the Google API and store the token in the session
39
+ # Authenticate against the API and store the token in the session
40
40
  def auth
41
41
  # params contains the access code with with the key :code
42
- provider_session.token = provider.connect(params, provider_session.data)
42
+ provider_session.token = provider.connect(params, provider_session.data, connector_response_url_options)
43
43
  end
44
44
 
45
45
  def resolve
@@ -76,11 +76,15 @@ class BrowseEverythingController < ActionController::Base
76
76
  @provider_session = nil
77
77
  end
78
78
 
79
+ def connector_response_url_options
80
+ { protocol: request.protocol, host: request.host, port: request.port }
81
+ end
82
+
79
83
  # Generates the authentication link for a given provider service
80
84
  # @return [String] the authentication link
81
85
  def auth_link
82
86
  @auth_link ||= if provider.present?
83
- link, data = provider.auth_link
87
+ link, data = provider.auth_link(connector_response_url_options)
84
88
  provider_session.data = data
85
89
  link = "#{link}&state=#{provider.key}" unless link.to_s.include?('state')
86
90
  link
@@ -50,17 +50,25 @@
50
50
  </td>
51
51
  <% end %>
52
52
 
53
- <td role="gridcell" class="ev-file-size">
54
- <%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %>
55
- </td>
53
+ <% if file.size %>
54
+ <td role="gridcell" class="ev-file-size">
55
+ <%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %>
56
+ </td>
57
+ <% else %>
58
+ <td role="gridcell" class="ev-file-size">Unknown</td>
59
+ <% end %>
56
60
 
57
61
  <td role="gridcell" class="ev-file-kind">
58
62
  <%= file.type %>
59
63
  </td>
60
64
 
61
- <td role="gridcell" class="ev-file-date">
62
- <%= file.mtime.strftime('%F %R') %>
63
- </td>
65
+ <% if file.mtime %>
66
+ <td role="gridcell" class="ev-file-date">
67
+ <%= file.mtime.strftime('%F %R') %>
68
+ </td>
69
+ <% else %>
70
+ <td role="gridcell" class="ev-file-date">Unknown</td>
71
+ <% end %>
64
72
  </tr>
65
73
  <% end %>
66
74
  </table>
@@ -12,7 +12,13 @@
12
12
  </div>
13
13
  <div class="ev-browser row" aria-live="polite">
14
14
  <div class="<%=fa3or4('fa3','fa4')%> col-xs-12 ev-files list">
15
- <%= render :partial => 'files' if provider.present? %>
15
+ <% if provider.present? %>
16
+ <% if provider.authorized? %>
17
+ <%= render :partial => 'files' %>
18
+ <% else %>
19
+ <%= render :partial => 'auth' %>
20
+ <% end %>
21
+ <% end %>
16
22
  </div>
17
23
  </div>
18
24
  </div>
@@ -24,24 +24,25 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'bootstrap-sass', '~> 3.2'
25
25
  spec.add_dependency 'dropbox_api', '>= 0.1.10'
26
26
  spec.add_dependency 'font-awesome-rails'
27
- spec.add_dependency 'google-api-client', '~> 0.21'
27
+ spec.add_dependency 'google-api-client', '~> 0.23'
28
28
  spec.add_dependency 'google_drive', '~> 2.1'
29
- spec.add_dependency 'googleauth', '0.6.2'
29
+ spec.add_dependency 'googleauth', '0.6.6'
30
30
  spec.add_dependency 'rails', '>= 4.2'
31
31
  spec.add_dependency 'ruby-box'
32
32
  spec.add_dependency 'sass-rails'
33
33
  spec.add_dependency 'signet', '~> 0.8'
34
- spec.add_dependency 'thor', '~> 0.20'
34
+ spec.add_dependency 'thor', '~> 0.19'
35
35
  spec.add_dependency 'typhoeus'
36
36
 
37
37
  spec.add_development_dependency 'bixby', '>= 1.0'
38
38
  spec.add_development_dependency 'bundler', '~> 1.3'
39
39
  spec.add_development_dependency 'capybara'
40
- spec.add_development_dependency 'chromedriver-helper'
40
+ spec.add_development_dependency 'chromedriver-helper', '1.2.0'
41
41
  spec.add_development_dependency 'coveralls'
42
42
  spec.add_development_dependency 'engine_cart', '~> 2.0'
43
43
  spec.add_development_dependency 'factory_bot_rails'
44
44
  spec.add_development_dependency 'jasmine', '~> 2.3'
45
+ spec.add_development_dependency 'pry-byebug'
45
46
  spec.add_development_dependency 'rails-controller-testing'
46
47
  spec.add_development_dependency 'rake'
47
48
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -51,6 +52,5 @@ Gem::Specification.new do |spec|
51
52
  spec.add_development_dependency 'selenium-webdriver'
52
53
  spec.add_development_dependency 'simplecov'
53
54
  spec.add_development_dependency 'sqlite3'
54
- spec.add_development_dependency 'vcr'
55
55
  spec.add_development_dependency 'webmock'
56
56
  end
@@ -89,7 +89,7 @@ module BrowseEverything
89
89
  end
90
90
 
91
91
  # Abstract method
92
- def auth_link
92
+ def auth_link(*_args)
93
93
  []
94
94
  end
95
95
 
@@ -36,13 +36,8 @@ module BrowseEverything
36
36
  # @param [String] id of the file or folder in Box
37
37
  # @return [Array<RubyBox::File>]
38
38
  def contents(id = '')
39
- if id.empty?
40
- folder = box_client.root_folder
41
- @entries = []
42
- else
43
- folder = box_client.folder_by_id(id)
44
- @entries = [parent_directory(folder)]
45
- end
39
+ folder = id.empty? ? box_client.root_folder : box_client.folder_by_id(id)
40
+ @entries = []
46
41
 
47
42
  folder.items(ITEM_LIMIT, 0, %w[name size created_at]).collect do |f|
48
43
  @entries << directory_entry(f)
@@ -62,7 +57,7 @@ module BrowseEverything
62
57
 
63
58
  # @return [String]
64
59
  # Authorization url that is used to request the initial access code from Box
65
- def auth_link
60
+ def auth_link(*_args)
66
61
  box_session.authorize_url(callback.to_s)
67
62
  end
68
63
 
@@ -73,7 +68,7 @@ module BrowseEverything
73
68
 
74
69
  # @return [Hash]
75
70
  # Gets the appropriate tokens from Box using the access code returned from :auth_link:
76
- def connect(params, _data)
71
+ def connect(params, _data, _url_options)
77
72
  register_access_token(box_session.get_access_token(params[:code]))
78
73
  end
79
74
 
@@ -138,11 +133,6 @@ module BrowseEverything
138
133
  @token.fetch('expires_at', nil).to_i
139
134
  end
140
135
 
141
- # Used to represent the ".." parent directory of the folder
142
- def parent_directory(folder)
143
- BrowseEverything::FileEntry.new(Pathname(folder.name).join('..'), '', '..', 0, Time.current, true)
144
- end
145
-
146
136
  def directory_entry(file)
147
137
  BrowseEverything::FileEntry.new(file.id, "#{key}:#{file.id}", file.name, file.size, file.created_at, file.type == 'folder')
148
138
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tmpdir'
3
4
  require 'dropbox_api'
4
5
  require_relative 'authentication_factory'
5
6
 
@@ -66,6 +67,7 @@ module BrowseEverything
66
67
  # @param config_values [Hash] configuration for the driver
67
68
  def initialize(config_values)
68
69
  self.class.authentication_klass ||= self.class.default_authentication_klass
70
+ @downloaded_files = {}
69
71
  super(config_values)
70
72
  end
71
73
 
@@ -79,36 +81,53 @@ module BrowseEverything
79
81
  end
80
82
 
81
83
  def contents(path = '')
84
+ path = '/' + path unless path == ''
82
85
  response = client.list_folder(path)
83
86
  @entries = response.entries.map { |entry| FileEntryFactory.build(metadata: entry, key: key) }
84
87
  @sorter.call(@entries)
85
88
  end
86
89
 
87
- def download(path)
88
- temp_file = Tempfile.open(File.basename(path), encoding: 'ascii-8bit')
90
+ def downloaded_file_for(path)
91
+ return @downloaded_files[path] if @downloaded_files.key?(path)
92
+
93
+ # This ensures that the name of the file its extension are preserved for user downloads
94
+ temp_file_path = File.join(Dir.mktmpdir, File.basename(path))
95
+ temp_file = File.open(temp_file_path, mode: 'w+', encoding: 'ascii-8bit')
89
96
  client.download(path) do |chunk|
90
97
  temp_file.write chunk
91
98
  end
92
99
  temp_file.close
93
- temp_file
100
+ @downloaded_files[path] = temp_file
94
101
  end
95
102
 
96
103
  def uri_for(path)
97
- temp_file = download(path)
98
- uri = ::Addressable::URI.new(scheme: 'file', path: temp_file.path)
99
- uri.to_s
104
+ temp_file = downloaded_file_for(path)
105
+ "file://#{temp_file.path}"
106
+ end
107
+
108
+ def file_size_for(path)
109
+ downloaded_file = downloaded_file_for(path)
110
+ size = File.size(downloaded_file.path)
111
+ size.to_i
112
+ rescue StandardError => error
113
+ Rails.logger.error "Failed to find the file size for #{path}: #{error}"
114
+ 0
100
115
  end
101
116
 
102
117
  def link_for(path)
103
- [uri_for(path), {}]
118
+ uri = uri_for(path)
119
+ file_name = File.basename(path)
120
+ file_size = file_size_for(path)
121
+
122
+ [uri, { file_name: file_name, file_size: file_size }]
104
123
  end
105
124
 
106
- def auth_link
107
- authenticator.authorize_url
125
+ def auth_link(url_options)
126
+ authenticator.authorize_url redirect_uri: redirect_uri(url_options)
108
127
  end
109
128
 
110
- def connect(params, _data)
111
- auth_bearer = authenticator.get_token(params[:code])
129
+ def connect(params, _data, url_options)
130
+ auth_bearer = authenticator.get_token params[:code], redirect_uri: redirect_uri(url_options)
112
131
  self.token = auth_bearer.token
113
132
  end
114
133
 
@@ -137,6 +156,10 @@ module BrowseEverything
137
156
  def client
138
157
  DropboxApi::Client.new(token)
139
158
  end
159
+
160
+ def redirect_uri(url_options)
161
+ connector_response_url(**url_options)
162
+ end
140
163
  end
141
164
  end
142
165
  end