]> git.ipfire.org Git - ipfire.org.git/commitdiff
nopaste: Cleanup expiry time calculation
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Oct 2018 13:21:53 +0000 (14:21 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Oct 2018 13:21:53 +0000 (14:21 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/nopaste.py

index bab855bab6ffac114669c3fbdbdb780d2107a2ff..cb621cd9615eeb8937739b95e8135bafbec343b9 100644 (file)
@@ -1,4 +1,6 @@
-#!/usr/bin/python
+#!/usr/bin/python3
+
+import datetime
 
 from .misc import Object
 
@@ -10,12 +12,13 @@ class Nopaste(Object):
                if account:
                        uid = account.uid
 
+               if expires:
+                       expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=expires)
+
                # http://blog.00null.net/easily-generating-random-strings-in-postgresql/
                res = self.db.get("INSERT INTO nopaste(uuid, subject, content, time_expires, address, \
-                       uid, mimetype, size) VALUES(random_slug(), %s, %s, \
-                               (CASE WHEN %s = 0 THEN NULL ELSE NOW() + INTERVAL '%s seconds' END), \
-                       %s, %s, %s, %s) RETURNING uuid",
-                       subject, content, expires, expires, address, uid, mimetype, len(content))
+                       uid, mimetype, size) VALUES(random_slug(), %s, %s, %s, %s, %s, %s, %s) RETURNING uuid",
+                       subject, content, expires, address, uid, mimetype, len(content))
 
                if res:
                        return res.uuid