nesta-plugin-focus 0.0.16
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +13 -0
- data/Rakefile +2 -0
- data/lib/nesta-plugin-contentfocus.rb +3 -0
- data/lib/nesta-plugin-contentfocus/app.rb +30 -0
- data/lib/nesta-plugin-contentfocus/assets/loading.html +245 -0
- data/lib/nesta-plugin-contentfocus/client.rb +139 -0
- data/lib/nesta-plugin-contentfocus/helpers.rb +39 -0
- data/lib/nesta-plugin-contentfocus/init.rb +5 -0
- data/lib/nesta-plugin-contentfocus/logger.rb +21 -0
- data/lib/nesta-plugin-contentfocus/openuri_monkeypatch.rb +31 -0
- data/lib/nesta-plugin-contentfocus/routes.rb +41 -0
- data/lib/nesta-plugin-contentfocus/version.rb +7 -0
- data/nesta-plugin-contentfocus.gemspec +28 -0
- metadata +158 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2459c95c0addcdd8e1503a9a73e62a77959cf546
|
|
4
|
+
data.tar.gz: 9b3cf9dabb3064b18c8dbfe53b005cc1dc4886e5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c7b4990ee5919a3e7a896810b1774d8146b8bf0cf373a4bedcf2092e8078e05e0a905941b2c2e47f4f871287606a4427542f6e28704281925f5abf390d7dee1a
|
|
7
|
+
data.tar.gz: 9cdccdc948082b8f7706e70fd616a7c382837ecc586d4ce9d9249303685170507bad7d7ce3e30059d54ebfd449f9ac1ae40bc61f54bf630af24615c3a28d3369
|
data/.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Glu IO Pty Ltd, Glenn Gillen
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# ContentFocus
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
## Contributing
|
|
8
|
+
|
|
9
|
+
1. Fork it ( https://github.com/gluio/nesta-plugin-contentfocus/fork )
|
|
10
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
11
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
12
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
13
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require "redcarpet"
|
|
2
|
+
require "nesta-plugin-contentfocus/client"
|
|
3
|
+
require "nesta-plugin-contentfocus/helpers"
|
|
4
|
+
require "nesta-plugin-contentfocus/routes"
|
|
5
|
+
module Nesta
|
|
6
|
+
class App
|
|
7
|
+
include Nesta::Plugin::ContentFocus::Routes
|
|
8
|
+
helpers Nesta::Plugin::ContentFocus::Helpers
|
|
9
|
+
before do
|
|
10
|
+
check_contentfocus
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
not_found do
|
|
14
|
+
if Nesta::Plugin::ContentFocus::Client.syncing?
|
|
15
|
+
filename = File.expand_path("assets/loading.html", File.dirname(__FILE__))
|
|
16
|
+
template = File.read(filename)
|
|
17
|
+
return template
|
|
18
|
+
else
|
|
19
|
+
set_common_variables
|
|
20
|
+
haml(:not_found)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
error do
|
|
25
|
+
set_common_variables
|
|
26
|
+
haml(:error)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Loading content...</title>
|
|
5
|
+
<meta http-equiv="refresh" content="7">
|
|
6
|
+
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet" type="text/css">
|
|
7
|
+
<link href="http://fonts.googleapis.com/css?family=Merriweather:300,400,700,300italic,400italic" rel="stylesheet" type="text/css">
|
|
8
|
+
<style>
|
|
9
|
+
@-webkit-keyframes loader-inner {
|
|
10
|
+
0% {
|
|
11
|
+
top: 45px;
|
|
12
|
+
left: 75px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
100% {
|
|
16
|
+
top: 0px;
|
|
17
|
+
left: 0px;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
@keyframes loader-inner {
|
|
21
|
+
0% {
|
|
22
|
+
top: 45px;
|
|
23
|
+
left: 75px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
100% {
|
|
27
|
+
top: 0px;
|
|
28
|
+
left: 0px;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
body, html {
|
|
32
|
+
height: 100%;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
body {
|
|
36
|
+
background-color: #fff;
|
|
37
|
+
text-align: center;
|
|
38
|
+
font-size: 22px;
|
|
39
|
+
font-weight: 300;
|
|
40
|
+
font-family: freight-text-pro, Merriweather, Georgia, Cambria, 'Times New Roman', Times, serif;
|
|
41
|
+
color: rgba(0, 0, 0, 0.8);
|
|
42
|
+
}
|
|
43
|
+
a {
|
|
44
|
+
color: rgb(77, 204, 75);
|
|
45
|
+
text-decoration: none;
|
|
46
|
+
transition: color 0.5s;
|
|
47
|
+
}
|
|
48
|
+
a:hover {
|
|
49
|
+
color: rgb(119, 63, 60);
|
|
50
|
+
text-decoration: underline;
|
|
51
|
+
}
|
|
52
|
+
h1 {
|
|
53
|
+
font-family: jaf-bernino-sans, 'Open Sans' 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Geneva, Verdana, sans-serif;
|
|
54
|
+
font-weight: 700;
|
|
55
|
+
margin: 1.66em 0 0.83em;
|
|
56
|
+
font-size: 36px;
|
|
57
|
+
line-height: 42px;
|
|
58
|
+
letter-spacing: -0.72px;
|
|
59
|
+
}
|
|
60
|
+
p {
|
|
61
|
+
line-height: 33px;
|
|
62
|
+
max-width: 40em;
|
|
63
|
+
margin: 0 auto;
|
|
64
|
+
}
|
|
65
|
+
.loader {
|
|
66
|
+
border: 5px white;
|
|
67
|
+
overflow: hidden;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.loader-inner {
|
|
71
|
+
display: inline-block;
|
|
72
|
+
width: 100%;
|
|
73
|
+
height: 100%;
|
|
74
|
+
background-color: #9d2d8e;
|
|
75
|
+
top: 0px;
|
|
76
|
+
left: 0px;
|
|
77
|
+
position: relative;
|
|
78
|
+
-webkit-transform: rotate(315deg); /* Chrome, Safari, Opera */
|
|
79
|
+
-webkit-transform: skew(58deg, -32deg);
|
|
80
|
+
-moz-transform: skew(58deg, -32deg);
|
|
81
|
+
-ms-transform: skew(58deg, -32deg);
|
|
82
|
+
-o-transform: skew(58deg, -32deg);
|
|
83
|
+
transform: skew(58deg, -32deg);
|
|
84
|
+
transform: rotate(315deg);
|
|
85
|
+
-webkit-animation: loader-inner 5s ease-in;
|
|
86
|
+
animation: loader-inner 5s ease-in;
|
|
87
|
+
}
|
|
88
|
+
.logo-nestadrop-large {
|
|
89
|
+
background-color: #fff;
|
|
90
|
+
width: 300px;
|
|
91
|
+
height: 300px;
|
|
92
|
+
position: relative;
|
|
93
|
+
overflow: hidden;
|
|
94
|
+
margin: 0 auto;
|
|
95
|
+
-webkit-border-radius: 150px;
|
|
96
|
+
-moz-border-radius: 150px;
|
|
97
|
+
-ms-border-radius: 150px;
|
|
98
|
+
-o-border-radius: 150px;
|
|
99
|
+
border-radius: 150px;
|
|
100
|
+
-webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);
|
|
101
|
+
-webkit-user-select: none;
|
|
102
|
+
-moz-user-select: none;
|
|
103
|
+
-ms-user-select: none;
|
|
104
|
+
-o-user-select: none;
|
|
105
|
+
user-select: none;
|
|
106
|
+
}
|
|
107
|
+
.logo-nestadrop-large div {
|
|
108
|
+
position: absolute;
|
|
109
|
+
background-color: #d15fc2;
|
|
110
|
+
}
|
|
111
|
+
.logo-nestadrop-large div[class*=-none] {
|
|
112
|
+
background-color: #fff;
|
|
113
|
+
}
|
|
114
|
+
.logo-nestadrop-large .base-left {
|
|
115
|
+
-webkit-transform: skew(0, 31deg);
|
|
116
|
+
-moz-transform: skew(0, 31deg);
|
|
117
|
+
-ms-transform: skew(0, 31deg);
|
|
118
|
+
-o-transform: skew(0, 31deg);
|
|
119
|
+
transform: skew(0, 31deg);
|
|
120
|
+
width: 61px;
|
|
121
|
+
height: 79px;
|
|
122
|
+
left: 90px;
|
|
123
|
+
top: 153px;
|
|
124
|
+
}
|
|
125
|
+
.logo-nestadrop-large .base-right {
|
|
126
|
+
-webkit-transform: skew(0, -31deg);
|
|
127
|
+
-moz-transform: skew(0, -31deg);
|
|
128
|
+
-ms-transform: skew(0, -31deg);
|
|
129
|
+
-o-transform: skew(0, -31deg);
|
|
130
|
+
transform: skew(0, -31deg);
|
|
131
|
+
width: 61px;
|
|
132
|
+
height: 79px;
|
|
133
|
+
left: 151px;
|
|
134
|
+
top: 153px;
|
|
135
|
+
}
|
|
136
|
+
.logo-nestadrop-large .base-middle {
|
|
137
|
+
-webkit-border-radius: 100%;
|
|
138
|
+
-moz-border-radius: 100%;
|
|
139
|
+
-ms-border-radius: 100%;
|
|
140
|
+
-o-border-radius: 100%;
|
|
141
|
+
border-radius: 100%;
|
|
142
|
+
width: 8px;
|
|
143
|
+
height: 76px;
|
|
144
|
+
left: 147px;
|
|
145
|
+
top: 171px;
|
|
146
|
+
}
|
|
147
|
+
.logo-nestadrop-large .cover-left-none {
|
|
148
|
+
-webkit-transform: skew(-50deg, 34deg);
|
|
149
|
+
-moz-transform: skew(-50deg, 34deg);
|
|
150
|
+
-ms-transform: skew(-50deg, 34deg);
|
|
151
|
+
-o-transform: skew(-50deg, 34deg);
|
|
152
|
+
transform: skew(-50deg, 34deg);
|
|
153
|
+
width: 62px;
|
|
154
|
+
height: 40px;
|
|
155
|
+
left: 70px;
|
|
156
|
+
top: 152px;
|
|
157
|
+
}
|
|
158
|
+
.logo-nestadrop-large .cover-right-none {
|
|
159
|
+
-webkit-transform: skew(50deg, -34deg);
|
|
160
|
+
-moz-transform: skew(50deg, -34deg);
|
|
161
|
+
-ms-transform: skew(50deg, -34deg);
|
|
162
|
+
-o-transform: skew(50deg, -34deg);
|
|
163
|
+
transform: skew(50deg, -34deg);
|
|
164
|
+
width: 62px;
|
|
165
|
+
height: 40px;
|
|
166
|
+
left: 170px;
|
|
167
|
+
top: 152px;
|
|
168
|
+
}
|
|
169
|
+
.logo-nestadrop-large .cover-top {
|
|
170
|
+
-webkit-transform: skew(51deg, -33deg);
|
|
171
|
+
-moz-transform: skew(51deg, -33deg);
|
|
172
|
+
-ms-transform: skew(51deg, -33deg);
|
|
173
|
+
-o-transform: skew(51deg, -33deg);
|
|
174
|
+
transform: skew(51deg, -33deg);
|
|
175
|
+
width: 60px;
|
|
176
|
+
height: 37px;
|
|
177
|
+
left: 71px;
|
|
178
|
+
top: 79px;
|
|
179
|
+
}
|
|
180
|
+
.logo-nestadrop-large .cover-bottom {
|
|
181
|
+
-webkit-transform: skew(51deg, -33deg);
|
|
182
|
+
-moz-transform: skew(51deg, -33deg);
|
|
183
|
+
-ms-transform: skew(51deg, -33deg);
|
|
184
|
+
-o-transform: skew(51deg, -33deg);
|
|
185
|
+
transform: skew(51deg, -33deg);
|
|
186
|
+
width: 60px;
|
|
187
|
+
height: 37px;
|
|
188
|
+
left: 171px;
|
|
189
|
+
top: 148px;
|
|
190
|
+
}
|
|
191
|
+
.logo-nestadrop-large .cover-right {
|
|
192
|
+
-webkit-transform: skew(-51deg, 33deg);
|
|
193
|
+
-moz-transform: skew(-51deg, 33deg);
|
|
194
|
+
-ms-transform: skew(-51deg, 33deg);
|
|
195
|
+
-o-transform: skew(-51deg, 33deg);
|
|
196
|
+
transform: skew(-51deg, 33deg);
|
|
197
|
+
width: 60px;
|
|
198
|
+
height: 37px;
|
|
199
|
+
left: 171px;
|
|
200
|
+
top: 79px;
|
|
201
|
+
}
|
|
202
|
+
.logo-nestadrop-large .cover-left {
|
|
203
|
+
-webkit-transform: skew(-51deg, 33deg);
|
|
204
|
+
-moz-transform: skew(-51deg, 33deg);
|
|
205
|
+
-ms-transform: skew(-51deg, 33deg);
|
|
206
|
+
-o-transform: skew(-51deg, 33deg);
|
|
207
|
+
transform: skew(-51deg, 33deg);
|
|
208
|
+
width: 60px;
|
|
209
|
+
height: 37px;
|
|
210
|
+
left: 71px;
|
|
211
|
+
top: 148px;
|
|
212
|
+
}
|
|
213
|
+
.logo-nestadrop-large .box-none {
|
|
214
|
+
-webkit-transform: skew(-58deg, 32deg);
|
|
215
|
+
-moz-transform: skew(-58deg, 32deg);
|
|
216
|
+
-ms-transform: skew(-58deg, 32deg);
|
|
217
|
+
-o-transform: skew(-58deg, 32deg);
|
|
218
|
+
transform: skew(-58deg, 32deg);
|
|
219
|
+
width: 60px;
|
|
220
|
+
height: 38px;
|
|
221
|
+
left: 121px;
|
|
222
|
+
top: 113px;
|
|
223
|
+
}
|
|
224
|
+
</style>
|
|
225
|
+
</head>
|
|
226
|
+
<body>
|
|
227
|
+
<h1>Just a moment…</h1>
|
|
228
|
+
<div class="logo-nestadrop-large">
|
|
229
|
+
<div class="base-left loader"></div>
|
|
230
|
+
<div class="base-right loader"></div>
|
|
231
|
+
<div class="base-middle"></div>
|
|
232
|
+
<div class="cover-left-none"></div>
|
|
233
|
+
<div class="cover-right-none"></div>
|
|
234
|
+
<div class="cover-top"></div>
|
|
235
|
+
<div class="cover-right"></div>
|
|
236
|
+
<div class="cover-bottom"></div>
|
|
237
|
+
<div class="cover-left"></div>
|
|
238
|
+
<div class="box-none loader"><span class="loader-inner"></span></div>
|
|
239
|
+
</div>
|
|
240
|
+
<p>This site uses <a href="https://nestadrop.io">nestadrop.io</a> to
|
|
241
|
+
make managing its content easier. We're downloading the latest
|
|
242
|
+
changes now, it will only take a second or two.
|
|
243
|
+
</p>
|
|
244
|
+
</body>
|
|
245
|
+
</html>
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require 'rest_client'
|
|
2
|
+
require 'yajl'
|
|
3
|
+
require 'nesta-plugin-contentfocus/logger'
|
|
4
|
+
module Nesta
|
|
5
|
+
module Plugin
|
|
6
|
+
module ContentFocus
|
|
7
|
+
class Client
|
|
8
|
+
def self.host
|
|
9
|
+
ENV["CONTENTFOCUS_URL"]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.userinfo
|
|
13
|
+
URI.parse(host).userinfo.split(":")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.lock
|
|
17
|
+
@lock ||= Mutex.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.confirm_synced!
|
|
21
|
+
return true if contentfocus_synced?
|
|
22
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Syncing with Dropbox filesystem."
|
|
23
|
+
File.open("/tmp/.contentfocus", "w+") do |f|
|
|
24
|
+
f.write "synced"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.syncing?
|
|
29
|
+
lock.synchronize do
|
|
30
|
+
@syncing
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.contentfocus_synced?
|
|
35
|
+
File.exists?("/tmp/.contentfocus")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.contentfocus_configured?
|
|
39
|
+
return true if contentfocus_synced?
|
|
40
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Checking if account is linked to Dropbox."
|
|
41
|
+
json = RestClient.get "#{host}account", {
|
|
42
|
+
accept: :json, x_contentfocus_version: Nesta::Plugin::ContentFocus::VERSION }
|
|
43
|
+
account = Yajl::Parser.parse json
|
|
44
|
+
account["uid"] && account["token"] && account["domain"]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.bounce_server!
|
|
48
|
+
return if syncing?
|
|
49
|
+
Nesta::Plugin::ContentFocus.logger.info "CONTENTFOCUS: Purging nesta file cache."
|
|
50
|
+
Nesta::FileModel.purge_cache
|
|
51
|
+
Nesta::Plugin::ContentFocus.logger.info "CONTENTFOCUS: Restarting server..."
|
|
52
|
+
unless system("bundle exec pumactl -S /tmp/.app_state phased-restart")
|
|
53
|
+
Thread.new do
|
|
54
|
+
Nesta::Plugin::ContentFocus.logger.info "CONTENTFOCUS: Waiting for server to load before restarting."
|
|
55
|
+
sleep(3)
|
|
56
|
+
bounce_server!
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.files
|
|
62
|
+
lock.synchronize do
|
|
63
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Retrieving file list..."
|
|
64
|
+
@files ||= Yajl::Parser.parse(RestClient.get "#{host}files", {
|
|
65
|
+
accept: :json, x_contentfocus_version: Nesta::Plugin::ContentFocus::VERSION })
|
|
66
|
+
end
|
|
67
|
+
@files
|
|
68
|
+
rescue RestClient::Unauthorized
|
|
69
|
+
return []
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.uncached_files
|
|
73
|
+
@uncached_files
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def self.uncached_files=(val)
|
|
77
|
+
lock.synchronize do
|
|
78
|
+
@uncached_files ||= val
|
|
79
|
+
end
|
|
80
|
+
@uncached_files
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def self.cache_file(file)
|
|
84
|
+
confirm_synced!
|
|
85
|
+
local_path = [Nesta::App.root, file].join("/")
|
|
86
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Caching '#{file}' to local filesystem at '#{local_path}'..."
|
|
87
|
+
FileUtils.mkdir_p(File.dirname(local_path))
|
|
88
|
+
file_contents = RestClient.get "#{host}file?file=#{URI.encode(file)}"
|
|
89
|
+
File.open(local_path, 'w') do |fo|
|
|
90
|
+
fo.write file_contents
|
|
91
|
+
end
|
|
92
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Cached '#{local_path}'."
|
|
93
|
+
bounce_server!
|
|
94
|
+
rescue RuntimeError => ex
|
|
95
|
+
puts ex
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def self.cache_files
|
|
99
|
+
self.uncached_files = Client.files
|
|
100
|
+
return unless uncached_files.size > 0
|
|
101
|
+
@syncing = true
|
|
102
|
+
threads = []
|
|
103
|
+
5.times do
|
|
104
|
+
threads << Thread.new do
|
|
105
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Creating worker thread to cache files..."
|
|
106
|
+
file = nil
|
|
107
|
+
while self.uncached_files.size > 0
|
|
108
|
+
lock.synchronize do
|
|
109
|
+
file = self.uncached_files.pop
|
|
110
|
+
end
|
|
111
|
+
cache_file(file) if file
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Worker thread complete."
|
|
115
|
+
end
|
|
116
|
+
threads.each(&:join)
|
|
117
|
+
@syncing = false
|
|
118
|
+
bounce_server!
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def self.remove_file(file)
|
|
122
|
+
local_path = [Nesta::App.root, file].join("/")
|
|
123
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Removing locally cached file at '#{local_path}'."
|
|
124
|
+
FileUtils.rm_r(File.dirname(local_path), secure: true)
|
|
125
|
+
bounce_server!
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def self.bootstrap!
|
|
129
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Bootstrapping local instance..."
|
|
130
|
+
unless contentfocus_synced?
|
|
131
|
+
Thread.new do
|
|
132
|
+
cache_files
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'nesta-plugin-contentfocus/logger'
|
|
2
|
+
module Nesta
|
|
3
|
+
module Plugin
|
|
4
|
+
module ContentFocus
|
|
5
|
+
module Helpers
|
|
6
|
+
def contentfocus_configured?
|
|
7
|
+
Client.contentfocus_configured?
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def setup_contentfocus
|
|
11
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Redirecting to contentfocus.io to complete account setup."
|
|
12
|
+
redirect to("#{Nesta::Plugin::ContentFocus::Client.host}account/setup?domain=#{request.host}")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def check_contentfocus
|
|
16
|
+
return if request.path_info =~ %r{\A/contentfocus\z}
|
|
17
|
+
setup_contentfocus unless contentfocus_configured?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def contentfocus_request?
|
|
21
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Authenticating Dropbox webhook request..."
|
|
22
|
+
expected_user, expected_pass = Client.userinfo
|
|
23
|
+
auth = Rack::Auth::Basic::Request.new(request.env)
|
|
24
|
+
if auth.provided? && auth.basic? && auth.credentials == [expected_user, expected_pass]
|
|
25
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Authenticated."
|
|
26
|
+
return true
|
|
27
|
+
else
|
|
28
|
+
Nesta::Plugin::ContentFocus.logger.debug "CONTENTFOCUS: Authentication failed."
|
|
29
|
+
return false
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def site_domain
|
|
34
|
+
request.host
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
module Nesta
|
|
3
|
+
module Plugin
|
|
4
|
+
module ContentFocus
|
|
5
|
+
def self.logger
|
|
6
|
+
return @logger if @logger
|
|
7
|
+
@logger = Logger.new(STDOUT)
|
|
8
|
+
@logger.level = Logger::WARN
|
|
9
|
+
if level = ENV["CONTENTFOCUS_LOG_LEVEL"]
|
|
10
|
+
levels = ["FATAL", "ERROR", "WARN", "INFO", "DEBUG"]
|
|
11
|
+
if levels.include? level.upcase
|
|
12
|
+
@logger.level = Logger.const_get(level.upcase.to_sym)
|
|
13
|
+
else
|
|
14
|
+
@logger.warn "Log level '#{level.upcase}' is unknown. Supported levels are: #{levels.join(", ")}."
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
@logger
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "uri"
|
|
2
|
+
module OpenURI
|
|
3
|
+
class <<self
|
|
4
|
+
alias_method :open_uri_original, :open_uri
|
|
5
|
+
alias_method :redirectable_cautious?, :redirectable?
|
|
6
|
+
|
|
7
|
+
def redirectable_baller? uri1, uri2
|
|
8
|
+
valid = /\A(?:https?|ftp)\z/i
|
|
9
|
+
valid =~ uri1.scheme.downcase && valid =~ uri2.scheme
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# The original open_uri takes *args but then doesn't do anything with them.
|
|
14
|
+
# Assume we can only handle a hash.
|
|
15
|
+
def self.open_uri name, options = {}
|
|
16
|
+
value = options.delete :allow_unsafe_redirects
|
|
17
|
+
if value
|
|
18
|
+
class <<self
|
|
19
|
+
remove_method :redirectable?
|
|
20
|
+
alias_method :redirectable?, :redirectable_baller?
|
|
21
|
+
end
|
|
22
|
+
else
|
|
23
|
+
class <<self
|
|
24
|
+
remove_method :redirectable?
|
|
25
|
+
alias_method :redirectable?, :redirectable_cautious?
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
self.open_uri_original name, options
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Nesta
|
|
2
|
+
module Plugin
|
|
3
|
+
module ContentFocus
|
|
4
|
+
module Routes
|
|
5
|
+
def self.included(app)
|
|
6
|
+
app.post "/contentfocus" do
|
|
7
|
+
if !contentfocus_request?
|
|
8
|
+
status 404
|
|
9
|
+
else
|
|
10
|
+
if params["file"]
|
|
11
|
+
Thread.new do
|
|
12
|
+
Nesta::Plugin::ContentFocus::Client.cache_file(params["file"])
|
|
13
|
+
end
|
|
14
|
+
else
|
|
15
|
+
Thread.new do
|
|
16
|
+
Nesta::Plugin::ContentFocus::Client.cache_files
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
status 200
|
|
20
|
+
""
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
app.delete "/contentfocus" do
|
|
25
|
+
if !contentfocus_request?
|
|
26
|
+
status 404
|
|
27
|
+
else
|
|
28
|
+
if params["file"]
|
|
29
|
+
Thread.new do
|
|
30
|
+
Nesta::Plugin::ContentFocus::Client.remove_file(params["file"])
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
status 200
|
|
34
|
+
""
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'nesta-plugin-contentfocus/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "nesta-plugin-focus"
|
|
8
|
+
spec.version = Nesta::Plugin::ContentFocus::VERSION
|
|
9
|
+
spec.authors = ["Glenn Gillen"]
|
|
10
|
+
spec.email = ["me@glenngillen.com"]
|
|
11
|
+
spec.summary = %q{NestaCMS and Dropbox integration.}
|
|
12
|
+
spec.description = %q{Allows you to sync web content on Dropbox with a Ruby-based CMS}
|
|
13
|
+
spec.homepage = "https://contentfocus.io/"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
spec.add_runtime_dependency 'nesta', '>= 0.11.0'
|
|
24
|
+
spec.add_runtime_dependency 'redcarpet', '~> 3.2.2'
|
|
25
|
+
spec.add_runtime_dependency 'tilt', '~> 1.4.0'
|
|
26
|
+
spec.add_runtime_dependency 'rest-client'
|
|
27
|
+
spec.add_runtime_dependency 'yajl-ruby'
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nesta-plugin-focus
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.16
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Glenn Gillen
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-05-03 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.6'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.6'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: nesta
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.11.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.11.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: redcarpet
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 3.2.2
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 3.2.2
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: tilt
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 1.4.0
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 1.4.0
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rest-client
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :runtime
|
|
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: yajl-ruby
|
|
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
|
+
description: Allows you to sync web content on Dropbox with a Ruby-based CMS
|
|
112
|
+
email:
|
|
113
|
+
- me@glenngillen.com
|
|
114
|
+
executables: []
|
|
115
|
+
extensions: []
|
|
116
|
+
extra_rdoc_files: []
|
|
117
|
+
files:
|
|
118
|
+
- ".gitignore"
|
|
119
|
+
- Gemfile
|
|
120
|
+
- LICENSE.txt
|
|
121
|
+
- README.md
|
|
122
|
+
- Rakefile
|
|
123
|
+
- lib/nesta-plugin-contentfocus.rb
|
|
124
|
+
- lib/nesta-plugin-contentfocus/app.rb
|
|
125
|
+
- lib/nesta-plugin-contentfocus/assets/loading.html
|
|
126
|
+
- lib/nesta-plugin-contentfocus/client.rb
|
|
127
|
+
- lib/nesta-plugin-contentfocus/helpers.rb
|
|
128
|
+
- lib/nesta-plugin-contentfocus/init.rb
|
|
129
|
+
- lib/nesta-plugin-contentfocus/logger.rb
|
|
130
|
+
- lib/nesta-plugin-contentfocus/openuri_monkeypatch.rb
|
|
131
|
+
- lib/nesta-plugin-contentfocus/routes.rb
|
|
132
|
+
- lib/nesta-plugin-contentfocus/version.rb
|
|
133
|
+
- nesta-plugin-contentfocus.gemspec
|
|
134
|
+
homepage: https://contentfocus.io/
|
|
135
|
+
licenses:
|
|
136
|
+
- MIT
|
|
137
|
+
metadata: {}
|
|
138
|
+
post_install_message:
|
|
139
|
+
rdoc_options: []
|
|
140
|
+
require_paths:
|
|
141
|
+
- lib
|
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
|
+
requirements:
|
|
144
|
+
- - ">="
|
|
145
|
+
- !ruby/object:Gem::Version
|
|
146
|
+
version: '0'
|
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
|
+
requirements:
|
|
149
|
+
- - ">="
|
|
150
|
+
- !ruby/object:Gem::Version
|
|
151
|
+
version: '0'
|
|
152
|
+
requirements: []
|
|
153
|
+
rubyforge_project:
|
|
154
|
+
rubygems_version: 2.2.2
|
|
155
|
+
signing_key:
|
|
156
|
+
specification_version: 4
|
|
157
|
+
summary: NestaCMS and Dropbox integration.
|
|
158
|
+
test_files: []
|