Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
f477d48c
Commit
f477d48c
authored
Sep 09, 2018
by
Virgil Grigoras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More robust handling while checking for new updates
parent
919de60e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
13 deletions
+55
-13
main.js
cps/static/js/main.js
+6
-0
admin.html
cps/templates/admin.html
+1
-0
web.py
cps/web.py
+48
-13
No files found.
cps/static/js/main.js
View file @
f477d48c
...
@@ -104,6 +104,7 @@ $(function() {
...
@@ -104,6 +104,7 @@ $(function() {
var
$this
=
$
(
this
);
var
$this
=
$
(
this
);
var
buttonText
=
$this
.
html
();
var
buttonText
=
$this
.
html
();
$this
.
html
(
"..."
);
$this
.
html
(
"..."
);
$
(
"#update_error"
).
addClass
(
"hidden"
)
$
.
ajax
({
$
.
ajax
({
dataType
:
"json"
,
dataType
:
"json"
,
url
:
window
.
location
.
pathname
+
"/../../get_update_status"
,
url
:
window
.
location
.
pathname
+
"/../../get_update_status"
,
...
@@ -116,6 +117,11 @@ $(function() {
...
@@ -116,6 +117,11 @@ $(function() {
.
removeClass
(
"hidden"
)
.
removeClass
(
"hidden"
)
.
find
(
"span"
).
html
(
data
.
commit
);
.
find
(
"span"
).
html
(
data
.
commit
);
}
}
if
(
data
.
error
.
length
!=
0
)
{
$
(
"#update_error"
)
.
removeClass
(
"hidden"
)
.
find
(
"span"
).
html
(
data
.
error
);
}
}
}
});
});
});
});
...
...
cps/templates/admin.html
View file @
f477d48c
...
@@ -93,6 +93,7 @@
...
@@ -93,6 +93,7 @@
<h2>
{{_('Administration')}}
</h2>
<h2>
{{_('Administration')}}
</h2>
<div>
{{_('Current commit timestamp')}}:
<span>
{{commit}}
</span></div>
<div>
{{_('Current commit timestamp')}}:
<span>
{{commit}}
</span></div>
<div
class=
"hidden"
id=
"update_info"
>
{{_('Newest commit timestamp')}}:
<span></span></div>
<div
class=
"hidden"
id=
"update_info"
>
{{_('Newest commit timestamp')}}:
<span></span></div>
<div
class=
"hidden"
id=
"update_error"
>
<span>
{{update_error}}
</span></div>
<p></p>
<p></p>
<div
class=
"btn btn-default"
id=
"restart_database"
>
{{_('Reconnect to Calibre DB')}}
</div>
<div
class=
"btn btn-default"
id=
"restart_database"
>
{{_('Reconnect to Calibre DB')}}
</div>
<div
class=
"btn btn-default"
data-toggle=
"modal"
data-target=
"#RestartDialog"
>
{{_('Restart Calibre-Web')}}
</div>
<div
class=
"btn btn-default"
data-toggle=
"modal"
data-target=
"#RestartDialog"
>
{{_('Restart Calibre-Web')}}
</div>
...
...
cps/web.py
View file @
f477d48c
...
@@ -1082,23 +1082,58 @@ def get_matching_tags():
...
@@ -1082,23 +1082,58 @@ def get_matching_tags():
@
app
.
route
(
"/get_update_status"
,
methods
=
[
'GET'
])
@
app
.
route
(
"/get_update_status"
,
methods
=
[
'GET'
])
@
login_required_if_no_ano
@
login_required_if_no_ano
def
get_update_status
():
def
get_update_status
():
status
=
{}
status
=
{
'status'
:
False
}
repository_url
=
'https://api.github.com/repos/janeczku/calibre-web'
tz
=
datetime
.
timedelta
(
seconds
=
time
.
timezone
if
(
time
.
localtime
()
.
tm_isdst
==
0
)
else
time
.
altzone
)
tz
=
datetime
.
timedelta
(
seconds
=
time
.
timezone
if
(
time
.
localtime
()
.
tm_isdst
==
0
)
else
time
.
altzone
)
if
request
.
method
==
"GET"
:
if
request
.
method
==
"GET"
:
# should be automatically replaced by git with current commit hash
# should be automatically replaced by git with current commit hash
commit_id
=
'$Format:
%
H$'
current_commit_id
=
'$Format:
%
H$'
# ToDo: Handle server not reachable -> ValueError:
commit
=
requests
.
get
(
'https://api.github.com/repos/janeczku/calibre-web/git/refs/heads/master'
)
.
json
()
try
:
if
"object"
in
commit
and
commit
[
'object'
][
'sha'
]
!=
commit_id
:
r
=
requests
.
get
(
repository_url
+
'/git/refs/heads/master'
)
status
[
'status'
]
=
True
r
.
raise_for_status
()
commitdate
=
requests
.
get
(
'https://api.github.com/repos/janeczku/calibre-web/git/commits/'
+
commit
[
'object'
][
'sha'
])
.
json
()
commit
=
r
.
json
()
if
"committer"
in
commitdate
:
except
requests
.
exceptions
.
HTTPError
as
ex
:
form_date
=
datetime
.
datetime
.
strptime
(
commitdate
[
'committer'
][
'date'
],
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ"
)
-
tz
status
[
'error'
]
=
_
(
u'HTTP Error'
)
+
' '
+
str
(
ex
)
status
[
'commit'
]
=
format_datetime
(
form_date
,
format
=
'short'
,
locale
=
get_locale
())
except
requests
.
exceptions
.
ConnectionError
:
status
[
'error'
]
=
_
(
u'Connection error'
)
except
requests
.
exceptions
.
Timeout
:
status
[
'error'
]
=
_
(
u'Timeout while establishing connection'
)
except
requests
.
exceptions
.
RequestException
:
status
[
'error'
]
=
_
(
u'General error'
)
if
'error'
in
status
:
return
json
.
dumps
(
status
)
if
'object'
in
commit
and
commit
[
'object'
][
'sha'
]
!=
current_commit_id
:
# a new update is available
try
:
r
=
requests
.
get
(
repository_url
+
'/git/commits/'
+
commit
[
'object'
][
'sha'
])
r
.
raise_for_status
()
update_data
=
r
.
json
()
except
requests
.
exceptions
.
HTTPError
as
ex
:
status
[
'error'
]
=
_
(
u'HTTP Error'
)
+
' '
+
str
(
ex
)
except
requests
.
exceptions
.
ConnectionError
:
status
[
'error'
]
=
_
(
u'Connection error'
)
except
requests
.
exceptions
.
Timeout
:
status
[
'error'
]
=
_
(
u'Timeout while establishing connection'
)
except
requests
.
exceptions
.
RequestException
:
status
[
'error'
]
=
_
(
u'General error'
)
if
'error'
in
status
:
return
json
.
dumps
(
status
)
if
'committer'
in
update_data
:
status
[
'status'
]
=
True
new_commit_date
=
datetime
.
datetime
.
strptime
(
update_data
[
'committer'
][
'date'
],
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ'
)
-
tz
status
[
'commit'
]
=
format_datetime
(
new_commit_date
,
format
=
'short'
,
locale
=
get_locale
())
else
:
else
:
status
[
'commit'
]
=
u'Unknown'
status
[
'error'
]
=
_
(
u'Could not fetch update information'
)
else
:
status
[
'status'
]
=
False
return
json
.
dumps
(
status
)
return
json
.
dumps
(
status
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment