sf-gdrive 0.1.6 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/gdrive/drive_controller.rb +45 -30
- data/app/views/gdrive/drive/index.html.erb +1 -1
- data/lib/gdrive/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3ed7032ea6bd565bbc2836aa197ba77d634ca5c
|
4
|
+
data.tar.gz: 1dd04d7c1acc8cdd036fd7e5e90da750de04bede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4207683d8a46ad9cb8f48044fc325eb05e7d307172cb331ef7088de1e5ece0abf872c8f1f5e38c172a7fe9c2bbc57f724be5273893d17d6c0c5b7bac090cbc7b
|
7
|
+
data.tar.gz: 376b631f8fd605ad657facdc75ffaa877ec0e24d7e6cb7c2fe32dc5ea0078901f3691569b70838fee721bf5b9cdb08b022582e55e37b8c8ec598cc7ed3804270
|
@@ -25,11 +25,11 @@ module Gdrive
|
|
25
25
|
auth_client.fetch_access_token!
|
26
26
|
secret_hash = auth_client.as_json.slice("expiry", "refresh_token", "access_token")
|
27
27
|
if secret_hash["refresh_token"] == nil
|
28
|
-
@error = 'You have already authorized this application. In order to re-configure, go to https://myaccount.google.com/permissions and revoke access to "Standard File".'
|
28
|
+
@error = 'You have already authorized this application. In order to re-configure, go to <a href="https://myaccount.google.com/permissions">https://myaccount.google.com/permissions</a> and revoke access to "Standard File".'
|
29
29
|
else
|
30
30
|
secret_hash[:expires_at] = auth_client.expires_at
|
31
31
|
secret = Base64.encode64(secret_hash.to_json)
|
32
|
-
@secret_url = "#{Gdrive.mount_url}/sync?key=#{secret}"
|
32
|
+
@secret_url = CGI.escape("#{Gdrive.mount_url}/sync?key=#{secret}")
|
33
33
|
redirect_to "#{session["redirect_url"]}&gdrive_secret_url=#{@secret_url}"
|
34
34
|
end
|
35
35
|
rescue
|
@@ -62,22 +62,13 @@ module Gdrive
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
66
|
-
client_secrets = Google::APIClient::ClientSecrets.load
|
67
|
-
client_params = client_secrets.to_authorization.as_json
|
68
|
-
secret_hash = JSON.parse(Base64.decode64(params[:key]))
|
69
|
-
client_params.merge!(secret_hash)
|
70
|
-
auth_client = Signet::OAuth2::Client.new(client_params)
|
71
|
-
drive = Google::Apis::DriveV3::DriveService.new
|
72
|
-
drive.authorization = auth_client
|
73
|
-
|
74
|
-
folder_name = "Standard Notes"
|
65
|
+
def find_or_create_folder(drive, folder_name, parent_folder)
|
75
66
|
folder_mime = "application/vnd.google-apps.folder"
|
76
|
-
|
77
67
|
folder_search = nil
|
78
68
|
begin
|
79
69
|
folder_search = drive.list_files(q: "mimeType='#{folder_mime}' and name='#{folder_name}'")
|
80
|
-
rescue
|
70
|
+
rescue Exception => e
|
71
|
+
puts "\n\n find_or_create_folder exception: #{e}\n\n"
|
81
72
|
return
|
82
73
|
end
|
83
74
|
|
@@ -88,29 +79,53 @@ module Gdrive
|
|
88
79
|
name: folder_name,
|
89
80
|
mime_type: folder_mime
|
90
81
|
}
|
82
|
+
if parent_folder
|
83
|
+
folder_data[:parents] = [parent_folder.id]
|
84
|
+
end
|
91
85
|
folder = drive.create_file(folder_data, fields: 'id')
|
92
86
|
end
|
93
87
|
|
94
|
-
|
88
|
+
return folder
|
89
|
+
end
|
95
90
|
|
96
|
-
|
91
|
+
def sync
|
92
|
+
client_secrets = Google::APIClient::ClientSecrets.load
|
93
|
+
client_params = client_secrets.to_authorization.as_json
|
94
|
+
secret_hash = JSON.parse(Base64.decode64(params[:key]))
|
95
|
+
client_params.merge!(secret_hash)
|
96
|
+
auth_client = Signet::OAuth2::Client.new(client_params)
|
97
|
+
drive = Google::Apis::DriveV3::DriveService.new
|
98
|
+
drive.authorization = auth_client
|
99
|
+
|
100
|
+
parent = nil
|
101
|
+
folders = ["Standard Notes", "#{Time.current.year}", "#{DateTime.now.strftime("%B")}"]
|
102
|
+
resolved_folders = []
|
103
|
+
folders.each do |current_folder_name|
|
104
|
+
result = find_or_create_folder(drive, current_folder_name, parent)
|
105
|
+
resolved_folders.push(result)
|
106
|
+
parent = result
|
107
|
+
end
|
108
|
+
|
109
|
+
folder = resolved_folders.last
|
97
110
|
|
111
|
+
self.sync_decrypt_file(drive, resolved_folders.first)
|
112
|
+
|
113
|
+
auth_params = params[:auth_params]
|
98
114
|
items = params[:items]
|
99
115
|
if items && items.length > 0
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
116
|
+
tmp = Tempfile.new(SecureRandom.hex)
|
117
|
+
payload = { "items" => items}
|
118
|
+
payload["auth_params"] = auth_params if auth_params != nil
|
119
|
+
tmp.write("#{JSON.pretty_generate(payload.as_json)}")
|
120
|
+
tmp.rewind
|
121
|
+
|
122
|
+
file_name = "#{DateTime.now.strftime("%B %-d, %Y").sub(',', '')}.txt"
|
123
|
+
existing = drive.list_files(q: "name = '#{file_name}'")
|
124
|
+
if existing.files.length > 0
|
125
|
+
file = existing.files[0]
|
126
|
+
drive.update_file(file.id, upload_source: tmp.path)
|
127
|
+
else
|
128
|
+
file = drive.create_file({:name => file_name, :parents => [folder.id]}, upload_source: tmp.path, content_type: "text/plain")
|
114
129
|
end
|
115
130
|
end
|
116
131
|
|
@@ -19,7 +19,7 @@
|
|
19
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
20
|
|
21
21
|
<% elsif @error %>
|
22
|
-
<strong style="color: red;">Error:</strong> <%= @error %>
|
22
|
+
<strong style="color: red;">Error:</strong> <%= @error.html_safe %>
|
23
23
|
<% else %>
|
24
24
|
<a href="<%= @auth_uri %>">Link Google Drive</a>
|
25
25
|
<% end %>
|
data/lib/gdrive/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sf-gdrive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@StandardNotes"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -69,7 +69,7 @@ files:
|
|
69
69
|
- lib/tasks/gdrive_tasks.rake
|
70
70
|
homepage: https://standardnotes.org
|
71
71
|
licenses:
|
72
|
-
-
|
72
|
+
- GPL-3.0
|
73
73
|
metadata: {}
|
74
74
|
post_install_message:
|
75
75
|
rdoc_options: []
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.6.12
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: Google Drive Extension for Standard File/Standard Notes.
|