sf-gdrive 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/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +37 -0
- data/app/assets/config/gdrive_manifest.js +2 -0
- data/app/assets/javascripts/gdrive/application.js +13 -0
- data/app/assets/javascripts/gdrive/drive.js +2 -0
- data/app/assets/stylesheets/gdrive/application.css +34 -0
- data/app/assets/stylesheets/gdrive/drive.css +4 -0
- data/app/controllers/gdrive/application_controller.rb +5 -0
- data/app/controllers/gdrive/drive_controller.rb +71 -0
- data/app/helpers/gdrive/application_helper.rb +4 -0
- data/app/helpers/gdrive/drive_helper.rb +4 -0
- data/app/jobs/gdrive/application_job.rb +4 -0
- data/app/mailers/gdrive/application_mailer.rb +6 -0
- data/app/models/gdrive/application_record.rb +5 -0
- data/app/views/gdrive/drive/index.html.erb +23 -0
- data/app/views/layouts/gdrive/application.html.erb +14 -0
- data/config/routes.rb +6 -0
- data/lib/gdrive/engine.rb +5 -0
- data/lib/gdrive/version.rb +3 -0
- data/lib/gdrive.rb +5 -0
- data/lib/tasks/gdrive_tasks.rake +4 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5b4055f67e3ba5e6c5f2de05ad020751fc51ef7d
|
4
|
+
data.tar.gz: 006aa241b5e0e22456bfdaeaed6aff83195cc2a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea9d2d23d9ad9ad822941dc95dbb6bebeeb382487e2a7c7bf724adbac65bf3358fa25dcded385afc6081295d0ae404050da35b6e5ffa870cbf3c5434faac3d8e
|
7
|
+
data.tar.gz: 71df6aab9f2617604644af92f7f95c5bf7e44ed922c039ba435de0a58da7a0a8d0cf363eda7bf224e627758b81965a9bcf51f10d9c422df7309dba8a39dd39c4
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Gdrive
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'gdrive'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install gdrive
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Gdrive'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
16
|
+
|
17
|
+
body, html {
|
18
|
+
font-family: sans-serif;
|
19
|
+
margin: 20px;
|
20
|
+
-webkit-font-smoothing: antialiased;
|
21
|
+
}
|
22
|
+
|
23
|
+
h1 {
|
24
|
+
margin-top: 2rem;
|
25
|
+
margin-bottom: 1rem;
|
26
|
+
font-weight: normal;
|
27
|
+
border-bottom: 1px solid black;
|
28
|
+
font-size: 2em;
|
29
|
+
margin: 0.67em 0;
|
30
|
+
}
|
31
|
+
|
32
|
+
h4 {
|
33
|
+
font-weight: bold !important;
|
34
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_dependency "gdrive/application_controller"
|
2
|
+
|
3
|
+
module Gdrive
|
4
|
+
class DriveController < ApplicationController
|
5
|
+
require 'google/apis/drive_v3'
|
6
|
+
require 'google/api_client/client_secrets'
|
7
|
+
|
8
|
+
def index
|
9
|
+
client_secrets = Google::APIClient::ClientSecrets.load
|
10
|
+
auth_client = client_secrets.to_authorization
|
11
|
+
auth_client.update!(
|
12
|
+
:scope => 'https://www.googleapis.com/auth/drive.file',
|
13
|
+
:redirect_uri => Gdrive.mount_url
|
14
|
+
)
|
15
|
+
|
16
|
+
if request["code"] == nil
|
17
|
+
@auth_uri = auth_client.authorization_uri.to_s
|
18
|
+
else
|
19
|
+
auth_code = params[:code]
|
20
|
+
auth_client.code = auth_code
|
21
|
+
auth_client.fetch_access_token!
|
22
|
+
secret_hash = auth_client.as_json.slice("expiry", "refresh_token", "access_token")
|
23
|
+
secret_hash[:expires_at] = auth_client.expires_at
|
24
|
+
secret = Base64.encode64(secret_hash.to_json)
|
25
|
+
@secret_url = "#{Gdrive.mount_url}/sync?key=#{secret}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def sync
|
30
|
+
client_secrets = Google::APIClient::ClientSecrets.load
|
31
|
+
client_params = client_secrets.to_authorization.as_json
|
32
|
+
secret_hash = JSON.parse(Base64.decode64(params[:key]))
|
33
|
+
client_params.merge!(secret_hash)
|
34
|
+
auth_client = Signet::OAuth2::Client.new(client_params)
|
35
|
+
drive = Google::Apis::DriveV3::DriveService.new
|
36
|
+
drive.authorization = auth_client
|
37
|
+
|
38
|
+
folder_name = "Standard Notes"
|
39
|
+
folder_mime = "application/vnd.google-apps.folder"
|
40
|
+
folder_search = drive.list_files(q: "mimeType='#{folder_mime}' and name='#{folder_name}'")
|
41
|
+
if folder_search.files.length > 0
|
42
|
+
folder = folder_search.files[0]
|
43
|
+
else
|
44
|
+
folder_data = {
|
45
|
+
name: folder_name,
|
46
|
+
mime_type: folder_mime
|
47
|
+
}
|
48
|
+
folder = drive.create_file(folder_data, fields: 'id')
|
49
|
+
end
|
50
|
+
|
51
|
+
items = params[:items]
|
52
|
+
if items && items.length > 0
|
53
|
+
items.each do |item|
|
54
|
+
tmp = Tempfile.new(item[:uuid])
|
55
|
+
tmp.write("#{JSON.pretty_generate(item.as_json)}")
|
56
|
+
tmp.rewind
|
57
|
+
file_name = "#{item[:content_type]}-#{item[:uuid]}.txt"
|
58
|
+
existing = drive.list_files(q: "name = '#{file_name}'")
|
59
|
+
if existing.files.length > 0
|
60
|
+
file = existing.files[0]
|
61
|
+
drive.update_file(file.id, upload_source: tmp.path)
|
62
|
+
else
|
63
|
+
file = drive.create_file({:name => file_name, :parents => [folder.id]}, upload_source: tmp.path, content_type: "text/plain")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<h1> Google Drive Data Backup </h1>
|
2
|
+
|
3
|
+
<p> This extension creates real-time backups of your Standard File data to your Google Drive.</p>
|
4
|
+
|
5
|
+
<% if @secret_url %>
|
6
|
+
<p> Your secret URL is: <strong><%= @secret_url %></strong></p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<strong>To register this extension using your secret URL:</strong>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<ol>
|
13
|
+
<li>In the Standard Notes app, find and click "Account" in the lower left corner.</li>
|
14
|
+
<li>Click "Standard File Dashboard".</li>
|
15
|
+
<li>After logging in, click "Extensions" in the left panel.</li>
|
16
|
+
<li>In the add new extension section, paste in the secret URL, and submit.</li>
|
17
|
+
</ol>
|
18
|
+
|
19
|
+
<p>That's it! Now, whenever you make changes to a note or tag, it will automatically be synced to your Drive.<p>
|
20
|
+
|
21
|
+
<% else %>
|
22
|
+
<a href="<%= @auth_uri %>">Link Google Drive</a>
|
23
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Standard File Google Drive Extension</title>
|
5
|
+
<%= stylesheet_link_tag "gdrive/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "gdrive/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
data/lib/gdrive.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sf-gdrive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ''
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: google-api-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Google Drive Ext
|
42
|
+
email:
|
43
|
+
- mo@standardnotes.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/assets/config/gdrive_manifest.js
|
52
|
+
- app/assets/javascripts/gdrive/application.js
|
53
|
+
- app/assets/javascripts/gdrive/drive.js
|
54
|
+
- app/assets/stylesheets/gdrive/application.css
|
55
|
+
- app/assets/stylesheets/gdrive/drive.css
|
56
|
+
- app/controllers/gdrive/application_controller.rb
|
57
|
+
- app/controllers/gdrive/drive_controller.rb
|
58
|
+
- app/helpers/gdrive/application_helper.rb
|
59
|
+
- app/helpers/gdrive/drive_helper.rb
|
60
|
+
- app/jobs/gdrive/application_job.rb
|
61
|
+
- app/mailers/gdrive/application_mailer.rb
|
62
|
+
- app/models/gdrive/application_record.rb
|
63
|
+
- app/views/gdrive/drive/index.html.erb
|
64
|
+
- app/views/layouts/gdrive/application.html.erb
|
65
|
+
- config/routes.rb
|
66
|
+
- lib/gdrive.rb
|
67
|
+
- lib/gdrive/engine.rb
|
68
|
+
- lib/gdrive/version.rb
|
69
|
+
- lib/tasks/gdrive_tasks.rake
|
70
|
+
homepage: https://standardnotes.org
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.4.8
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Google Drive Ext
|
94
|
+
test_files: []
|