1
0
mirror of https://github.com/aquatix/digimarks.git synced 2025-12-06 20:55:10 +01:00

Also accept http202; try fixing encoding issue

This commit is contained in:
2017-12-19 22:03:51 +01:00
parent 2cc2d382c1
commit 53887c8ece
2 changed files with 7 additions and 6 deletions

View File

@@ -247,6 +247,7 @@ class Bookmark(db.Model):
# Status code: 200 is OK, 404 is not found, for example (showing an error)
HTTP_CONNECTIONERROR = 0
HTTP_OK = 200
HTTP_ACCEPTED = 202
HTTP_MOVEDTEMPORARILY = 304
HTTP_NOTFOUND = 404
@@ -279,7 +280,7 @@ class Bookmark(db.Model):
def set_hash(self):
""" Generate hash """
self.url_hash = hashlib.md5(self.url).hexdigest()
self.url_hash = hashlib.md5(self.url.encode('utf-8')).hexdigest()
def set_title_from_source(self):
""" Request the title by requesting the source url """
@@ -289,7 +290,7 @@ class Bookmark(db.Model):
except:
# For example 'MissingSchema: Invalid URL 'abc': No schema supplied. Perhaps you meant http://abc?'
self.http_status = 404
if self.http_status == 200:
if self.http_status == 200 or self.http_status == 202:
html = bs4.BeautifulSoup(result.text, 'html.parser')
try:
self.title = html.title.text.strip()
@@ -346,8 +347,8 @@ class Bookmark(db.Model):
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
self.redirect_uri = result.url.encode('utf-8')
return result.url.encode('utf-8')
else:
return None
@@ -575,7 +576,7 @@ def updatebookmark(userkey, request, urlhash = None):
else:
bookmark.set_status_code()
if bookmark.http_status == 200:
if bookmark.http_status == 200 or bookmark.http_status == 202:
try:
bookmark.set_favicon()
except IOError:

View File

@@ -3,7 +3,7 @@
{% block pageheader %}{{ action }}{% endblock %}
{% block pagecontent %}
{% if bookmark.http_status != 200 and bookmark.http_status != 304 %}
{% if bookmark.http_status != 200 and bookmark.http_status != 202 and bookmark.http_status != 304 %}
<div class="row">
<div class="col s12">
<div class="card-panel {{ theme.ERRORMESSAGE_BACKGROUND }}">