mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 23:05:10 +01:00
If redirect detected, button with final uri
This commit is contained in:
12
digimarks.py
12
digimarks.py
@@ -106,6 +106,7 @@ class Bookmark(db.Model):
|
||||
|
||||
# Status code: 200 is OK, 404 is not found, for example (showing an error)
|
||||
http_status = IntegerField(default=200)
|
||||
redirect_uri = None
|
||||
|
||||
created_date = DateTimeField(default=datetime.datetime.now)
|
||||
modified_date = DateTimeField(null=True)
|
||||
@@ -191,6 +192,17 @@ class Bookmark(db.Model):
|
||||
tags_clean = clean_tags(tags_split)
|
||||
self.tags = ','.join(tags_clean)
|
||||
|
||||
def get_redirect_uri(self):
|
||||
if self.redirect_uri:
|
||||
return self.redirect_uri
|
||||
if self.http_status == 301 or self.http_status == 302:
|
||||
result = requests.head(self.url, allow_redirects=True)
|
||||
self.http_status = result.status_code
|
||||
self.redirect_uri = result.url
|
||||
return result.url
|
||||
else:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def strip_url_params(cls, url):
|
||||
parsed = urlparse(url)
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
{% if bookmark.favicon %}
|
||||
<div><img src="{{ url_for('static', filename='favicons/' + bookmark.favicon) }}" class="favicon" /></div>
|
||||
{% endif %}
|
||||
{% if bookmark.http_status != 200 %}
|
||||
{% if bookmark.http_status != 200 and bookmark.http_status != 304 %}
|
||||
<div><i class="small material-icons red-text" title="HTTP status {{ bookmark.http_status }}">report_problem</i></div>
|
||||
{% endif %}
|
||||
{% if bookmark.starred == True %}
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
{% block pageheader %}{{ action }}{% endblock %}
|
||||
{% block pagecontent %}
|
||||
|
||||
{% if bookmark.http_status != 200 %}
|
||||
{% if bookmark.http_status != 200 and bookmark.http_status != 304 %}
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<div class="card-panel red darken-1">
|
||||
<span class="white-text">
|
||||
{% if bookmark.http_status == 404 %}
|
||||
<i class="material-icons">report_problem</i> URL not found (404), broken/outdated link?
|
||||
{% elif bookmark.http_status == 302 %}
|
||||
<i class="material-icons">report_problem</i> HTTP status (302), moved temporarily
|
||||
{% else %}
|
||||
<i class="material-icons">report_problem</i> HTTP status {{ bookmark.http_status }}
|
||||
{% endif %}
|
||||
@@ -48,6 +50,19 @@
|
||||
<i class="material-icons prefix">turned_in</i>
|
||||
<input placeholder="url" type="text" name="url" id="url" value="{{ bookmark.url }}" class="validate" />
|
||||
<label for="url">URL</label>
|
||||
{% if bookmark.get_redirect_uri() %}
|
||||
<div>
|
||||
<a class="waves-effect waves-light btn" id="btn_urlupdate"><i class="material-icons left">turned_in</i>{{ bookmark.get_redirect_uri() }}</a>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
$('#btn_urlupdate').on('click', function () {
|
||||
var text = $('#url');
|
||||
text.val('{{ bookmark.get_redirect_uri() }}');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="input-field col s12">
|
||||
|
||||
Reference in New Issue
Block a user