unsee: use get_closest_expiration
This commit is contained in:
parent
3c3a101c7a
commit
ec6e5be528
2 changed files with 13 additions and 11 deletions
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.capabilities.paste import ICapPaste, BasePaste
|
||||
from weboob.capabilities.paste import BasePaste
|
||||
from weboob.tools.capabilities.paste import BasePasteBackend
|
||||
from weboob.tools.capabilities.paste import image_mime
|
||||
import re
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ class UnPaste(BasePaste):
|
|||
return 'https://unsee.cc/%s' % id
|
||||
|
||||
|
||||
class UnseeBackend(BaseBackend, ICapPaste):
|
||||
class UnseeBackend(BaseBackend, BasePasteBackend):
|
||||
NAME = 'unsee'
|
||||
DESCRIPTION = u'unsee.cc expiring image hosting'
|
||||
MAINTAINER = u'Vincent A'
|
||||
|
|
@ -45,10 +46,12 @@ class UnseeBackend(BaseBackend, ICapPaste):
|
|||
|
||||
BROWSER = UnseeBrowser
|
||||
|
||||
EXPIRATIONS = {3600: 'hour', 86400: 'day', 86400 * 7: 'week'}
|
||||
|
||||
def can_post(self, contents, title=None, public=None, max_age=None):
|
||||
if re.search(r'[^a-zA-Z0-9=+/\s]', contents):
|
||||
return 0
|
||||
elif max_age < 3600:
|
||||
elif max_age is not None and not self.get_closest_expiration(max_age):
|
||||
return 0
|
||||
else:
|
||||
mime = image_mime(contents, ('gif', 'jpeg', 'png'))
|
||||
|
|
@ -63,7 +66,12 @@ class UnseeBackend(BaseBackend, ICapPaste):
|
|||
return UnPaste(*a, **kw)
|
||||
|
||||
def post_paste(self, paste, max_age=None):
|
||||
d = self.browser.post_image(paste.title, paste.contents.decode('base64'), max_age)
|
||||
if max_age is None:
|
||||
max_code = 'week'
|
||||
else:
|
||||
max_code = self.EXPIRATIONS[self.get_closest_expiration(max_age)]
|
||||
|
||||
d = self.browser.post_image(paste.title, paste.contents.decode('base64'), max_code)
|
||||
paste.id = d['id']
|
||||
return paste
|
||||
|
||||
|
|
|
|||
|
|
@ -77,13 +77,7 @@ class UnseeBrowser(BaseBrowser):
|
|||
headers = {'Content-type': 'multipart/form-data; boundary=%s' % b, 'Content-length': len(data)}
|
||||
return Request(url, data=self._make_multipart(fields, b), headers=headers)
|
||||
|
||||
def post_image(self, name, contents, max_age):
|
||||
if max_age >= 86400:
|
||||
time = 'week'
|
||||
elif max_age >= 3600:
|
||||
time = 'day'
|
||||
else:
|
||||
time = 'hour'
|
||||
def post_image(self, name, contents, time):
|
||||
# time='first' for one-shot view
|
||||
|
||||
params = [('time', time), ('image[]', FileField(name or '-', contents))]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue