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
cb5adb3a
Commit
cb5adb3a
authored
Sep 09, 2018
by
Virgil Grigoras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display "what's new" information for newer versions than the current one
parent
9616562a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
24 deletions
+105
-24
main.js
cps/static/js/main.js
+26
-11
admin.html
cps/templates/admin.html
+15
-2
web.py
cps/web.py
+64
-11
No files found.
cps/static/js/main.js
View file @
cb5adb3a
...
@@ -110,18 +110,33 @@ $(function() {
...
@@ -110,18 +110,33 @@ $(function() {
url
:
window
.
location
.
pathname
+
"/../../get_update_status"
,
url
:
window
.
location
.
pathname
+
"/../../get_update_status"
,
success
:
function
success
(
data
)
{
success
:
function
success
(
data
)
{
$this
.
html
(
buttonText
);
$this
.
html
(
buttonText
);
if
(
data
.
status
===
true
)
{
$
(
"#check_for_update"
).
addClass
(
"hidden"
);
var
cssClass
=
''
;
$
(
"#perform_update"
).
removeClass
(
"hidden"
);
var
message
=
''
$
(
"#update_info"
)
.
removeClass
(
"hidden"
)
if
(
data
.
success
===
true
)
{
.
find
(
"span"
).
html
(
data
.
commit
);
if
(
data
.
update
===
true
)
{
}
$
(
"#check_for_update"
).
addClass
(
"hidden"
);
if
(
data
.
error
.
length
!=
0
)
{
$
(
"#perform_update"
).
removeClass
(
"hidden"
);
$
(
"#update_error"
)
$
(
"#update_info"
)
.
removeClass
(
"hidden"
)
.
removeClass
(
"hidden"
)
.
find
(
"span"
).
html
(
data
.
error
);
.
find
(
"span"
).
html
(
data
.
commit
);
data
.
history
.
reverse
().
forEach
((
entry
,
index
)
=>
{
$
(
"<tr><td>"
+
entry
[
0
]
+
"</td><td>"
+
entry
[
1
]
+
"</td></tr>"
).
appendTo
(
$
(
"#update_table"
));
});
cssClass
=
'alert-warning'
}
else
{
cssClass
=
'alert-success'
}
}
else
{
cssClass
=
'alert-danger'
}
}
message
=
'<div class="alert '
+
cssClass
+
' fade in"><a href="#" class="close" data-dismiss="alert">×</a>'
+
data
.
message
+
'</div>'
;
$
(
message
).
insertAfter
(
$
(
"#update_table"
));
}
}
});
});
});
});
...
...
cps/templates/admin.html
View file @
cb5adb3a
...
@@ -113,8 +113,21 @@
...
@@ -113,8 +113,21 @@
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col"
>
<div
class=
"col"
>
<h2>
{{_('Update')}}
</h2>
<h2>
{{_('Update')}}
</h2>
<div>
{{_('Current commit timestamp')}}:
<span>
{{commit}}
</span></div>
<table
class=
"table table-striped"
id=
"update_table"
>
<div
class=
"hidden"
id=
"update_info"
>
{{_('Newest commit timestamp')}}:
<span></span></div>
<thead>
<tr>
<th
class=
"col-xs-3"
>
{{_('Version')}}
</th>
<th
class=
"col-xl-8"
>
{{_('Details')}}
</th>
</tr>
</thead>
<tbody>
<tr
id=
"current_version"
>
<td>
{{commit}}
<i>
({{_('current version')}})
</i></td>
<td>
/
</td>
</tr>
</tbody>
</table>
<div
class=
"hidden"
id=
"update_error"
>
<span>
{{update_error}}
</span></div>
<div
class=
"hidden"
id=
"update_error"
>
<span>
{{update_error}}
</span></div>
<div
class=
"btn btn-default"
id=
"check_for_update"
>
{{_('Check for update')}}
</div>
<div
class=
"btn btn-default"
id=
"check_for_update"
>
{{_('Check for update')}}
</div>
<div
class=
"btn btn-default hidden"
id=
"perform_update"
data-toggle=
"modal"
data-target=
"#UpdateprogressDialog"
>
{{_('Perform Update')}}
</div>
<div
class=
"btn btn-default hidden"
id=
"perform_update"
data-toggle=
"modal"
data-target=
"#UpdateprogressDialog"
>
{{_('Perform Update')}}
</div>
...
...
cps/web.py
View file @
cb5adb3a
...
@@ -1085,7 +1085,9 @@ def get_matching_tags():
...
@@ -1085,7 +1085,9 @@ def get_matching_tags():
@
login_required_if_no_ano
@
login_required_if_no_ano
def
get_update_status
():
def
get_update_status
():
status
=
{
status
=
{
'status'
:
False
,
'update'
:
False
,
'success'
:
False
,
'message'
:
''
,
'current_commit_hash'
:
''
'current_commit_hash'
:
''
}
}
repository_url
=
'https://api.github.com/repos/janeczku/calibre-web'
repository_url
=
'https://api.github.com/repos/janeczku/calibre-web'
...
@@ -1106,15 +1108,16 @@ def get_update_status():
...
@@ -1106,15 +1108,16 @@ def get_update_status():
r
.
raise_for_status
()
r
.
raise_for_status
()
commit
=
r
.
json
()
commit
=
r
.
json
()
except
requests
.
exceptions
.
HTTPError
as
ex
:
except
requests
.
exceptions
.
HTTPError
as
ex
:
status
[
'
error
'
]
=
_
(
u'HTTP Error'
)
+
' '
+
str
(
ex
)
status
[
'
message
'
]
=
_
(
u'HTTP Error'
)
+
' '
+
str
(
ex
)
except
requests
.
exceptions
.
ConnectionError
:
except
requests
.
exceptions
.
ConnectionError
:
status
[
'
error
'
]
=
_
(
u'Connection error'
)
status
[
'
message
'
]
=
_
(
u'Connection error'
)
except
requests
.
exceptions
.
Timeout
:
except
requests
.
exceptions
.
Timeout
:
status
[
'
error
'
]
=
_
(
u'Timeout while establishing connection'
)
status
[
'
message
'
]
=
_
(
u'Timeout while establishing connection'
)
except
requests
.
exceptions
.
RequestException
:
except
requests
.
exceptions
.
RequestException
:
status
[
'
error
'
]
=
_
(
u'General error'
)
status
[
'
message
'
]
=
_
(
u'General error'
)
if
'error'
in
status
:
if
status
[
'message'
]
!=
''
:
status
[
'success'
]
=
False
return
json
.
dumps
(
status
)
return
json
.
dumps
(
status
)
if
'object'
in
commit
and
commit
[
'object'
][
'sha'
]
!=
status
[
'current_commit_hash'
]:
if
'object'
in
commit
and
commit
[
'object'
][
'sha'
]
!=
status
[
'current_commit_hash'
]:
...
@@ -1132,17 +1135,67 @@ def get_update_status():
...
@@ -1132,17 +1135,67 @@ def get_update_status():
except
requests
.
exceptions
.
RequestException
:
except
requests
.
exceptions
.
RequestException
:
status
[
'error'
]
=
_
(
u'General error'
)
status
[
'error'
]
=
_
(
u'General error'
)
if
'error'
in
status
:
if
status
[
'message'
]
!=
''
:
status
[
'success'
]
=
False
return
json
.
dumps
(
status
)
return
json
.
dumps
(
status
)
if
'committer'
in
update_data
:
if
'committer'
in
update_data
and
'message'
in
update_data
:
status
[
'status'
]
=
True
parents
=
[]
status
[
'update'
]
=
True
status
[
'success'
]
=
True
status
[
'message'
]
=
_
(
u'A new update is available. Click on the button below update to the latest version.'
)
new_commit_date
=
datetime
.
datetime
.
strptime
(
new_commit_date
=
datetime
.
datetime
.
strptime
(
update_data
[
'committer'
][
'date'
],
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ'
)
-
tz
update_data
[
'committer'
][
'date'
],
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ'
)
-
tz
status
[
'commit'
]
=
format_datetime
(
new_commit_date
,
format
=
'short'
,
locale
=
get_locale
())
parents
.
append
(
[
format_datetime
(
new_commit_date
,
format
=
'short'
,
locale
=
get_locale
()),
update_data
[
'message'
],
update_data
[
'sha'
]
]
)
# it only makes sense to analyze the parents if we know the current commit hash
if
status
[
'current_commit_hash'
]
!=
''
:
try
:
parent_commit
=
update_data
[
'parents'
][
0
]
# limit the maximum search depth
remaining_parents_cnt
=
10
except
IndexError
:
remaining_parents_cnt
=
None
if
remaining_parents_cnt
is
not
None
:
while
True
:
if
remaining_parents_cnt
==
0
:
break
# check if we are more than one update behind if so, go up the tree
if
parent_commit
[
'sha'
]
!=
status
[
'current_commit_hash'
]:
try
:
r
=
requests
.
get
(
parent_commit
[
'url'
])
r
.
raise_for_status
()
parent_data
=
r
.
json
()
parent_commit_date
=
datetime
.
datetime
.
strptime
(
parent_data
[
'committer'
][
'date'
],
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ'
)
-
tz
parent_commit_date
=
format_datetime
(
parent_commit_date
,
format
=
'short'
,
locale
=
get_locale
())
parents
.
append
([
parent_commit_date
,
parent_data
[
'message'
],
parent_data
[
'sha'
]])
parent_commit
=
parent_data
[
'parents'
][
0
]
remaining_parents_cnt
-=
1
except
Exception
:
# it isn't crucial if we can't get information about the parent
break
else
:
# parent is our current version
break
else
:
else
:
status
[
'error'
]
=
_
(
u'Could not fetch update information'
)
status
[
'success'
]
=
False
status
[
'message'
]
=
_
(
u'Could not fetch update information'
)
status
[
'history'
]
=
parents
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