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:
11
digimarks.py
11
digimarks.py
@@ -247,6 +247,7 @@ class Bookmark(db.Model):
|
|||||||
# Status code: 200 is OK, 404 is not found, for example (showing an error)
|
# Status code: 200 is OK, 404 is not found, for example (showing an error)
|
||||||
HTTP_CONNECTIONERROR = 0
|
HTTP_CONNECTIONERROR = 0
|
||||||
HTTP_OK = 200
|
HTTP_OK = 200
|
||||||
|
HTTP_ACCEPTED = 202
|
||||||
HTTP_MOVEDTEMPORARILY = 304
|
HTTP_MOVEDTEMPORARILY = 304
|
||||||
HTTP_NOTFOUND = 404
|
HTTP_NOTFOUND = 404
|
||||||
|
|
||||||
@@ -279,7 +280,7 @@ class Bookmark(db.Model):
|
|||||||
|
|
||||||
def set_hash(self):
|
def set_hash(self):
|
||||||
""" Generate hash """
|
""" 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):
|
def set_title_from_source(self):
|
||||||
""" Request the title by requesting the source url """
|
""" Request the title by requesting the source url """
|
||||||
@@ -289,7 +290,7 @@ class Bookmark(db.Model):
|
|||||||
except:
|
except:
|
||||||
# For example 'MissingSchema: Invalid URL 'abc': No schema supplied. Perhaps you meant http://abc?'
|
# For example 'MissingSchema: Invalid URL 'abc': No schema supplied. Perhaps you meant http://abc?'
|
||||||
self.http_status = 404
|
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')
|
html = bs4.BeautifulSoup(result.text, 'html.parser')
|
||||||
try:
|
try:
|
||||||
self.title = html.title.text.strip()
|
self.title = html.title.text.strip()
|
||||||
@@ -346,8 +347,8 @@ class Bookmark(db.Model):
|
|||||||
if self.http_status == 301 or self.http_status == 302:
|
if self.http_status == 301 or self.http_status == 302:
|
||||||
result = requests.head(self.url, allow_redirects=True)
|
result = requests.head(self.url, allow_redirects=True)
|
||||||
self.http_status = result.status_code
|
self.http_status = result.status_code
|
||||||
self.redirect_uri = result.url
|
self.redirect_uri = result.url.encode('utf-8')
|
||||||
return result.url
|
return result.url.encode('utf-8')
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -575,7 +576,7 @@ def updatebookmark(userkey, request, urlhash = None):
|
|||||||
else:
|
else:
|
||||||
bookmark.set_status_code()
|
bookmark.set_status_code()
|
||||||
|
|
||||||
if bookmark.http_status == 200:
|
if bookmark.http_status == 200 or bookmark.http_status == 202:
|
||||||
try:
|
try:
|
||||||
bookmark.set_favicon()
|
bookmark.set_favicon()
|
||||||
except IOError:
|
except IOError:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
{% block pageheader %}{{ action }}{% endblock %}
|
{% block pageheader %}{{ action }}{% endblock %}
|
||||||
{% block pagecontent %}
|
{% 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="row">
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
<div class="card-panel {{ theme.ERRORMESSAGE_BACKGROUND }}">
|
<div class="card-panel {{ theme.ERRORMESSAGE_BACKGROUND }}">
|
||||||
|
|||||||
Reference in New Issue
Block a user