changelog
This commit is contained in:
parent
cfa8b2686b
commit
0815ccd930
6 changed files with 32 additions and 33 deletions
|
@ -35,6 +35,7 @@ class Changelog(db.Model):
|
|||
id = db.Column(db.Integer(), primary_key=True)
|
||||
|
||||
created = db.Column(db.DateTime())
|
||||
timestamp = db.Column(db.BigInteger())
|
||||
|
||||
user_id = db.Column(db.String(43))
|
||||
revision = db.Column(db.BigInteger())
|
||||
|
@ -44,22 +45,18 @@ class Changelog(db.Model):
|
|||
@classmethod
|
||||
def record(cls, user, action, *args):
|
||||
c = cls()
|
||||
c.created = datetime.now()
|
||||
c.created = datetime.utcnow()
|
||||
c.timestamp = int(c.created.strftime('%s'))
|
||||
c.user_id = user.id
|
||||
c.revision = cls.query.filter_by(user_id=user.id).count()
|
||||
c.data = json.dumps([action, args])
|
||||
timestamp = c.timestamp
|
||||
_data = str(c.revision) + str(timestamp) + c.data
|
||||
c.data = json.dumps([action] + list(args))
|
||||
_data = str(c.revision) + str(c.timestamp) + c.data
|
||||
c.sig = settings.sk.sign(_data, encoding='base64')
|
||||
db.session.add(c)
|
||||
db.session.commit()
|
||||
if state.online:
|
||||
state.nodes.queue('peered', 'pushChanges', [c.json()])
|
||||
|
||||
@property
|
||||
def timestamp(self):
|
||||
return self.created.strftime('%s')
|
||||
|
||||
@classmethod
|
||||
def apply_changes(cls, user, changes):
|
||||
for change in changes:
|
||||
|
@ -82,14 +79,15 @@ class Changelog(db.Model):
|
|||
sig = settings.sk.sign(_data, encoding='base64')
|
||||
if valid(user.id, _data, sig):
|
||||
c = cls()
|
||||
c.created = datetime.fromtimestamp(float(timestamp))
|
||||
c.created = datetime.utcnow()
|
||||
c.timestamp = timestamp
|
||||
c.user_id = user.id
|
||||
c.revision = revision
|
||||
c.data = data
|
||||
c.sig = sig
|
||||
action, args = json.loads(data)
|
||||
logger.debug('apply change %s %s', action, args)
|
||||
if getattr(c, 'action_' + action)(user, timestamp, *args):
|
||||
args = json.loads(data)
|
||||
logger.debug('apply change %s', args)
|
||||
if getattr(c, 'action_' + args[0])(user, timestamp, *args[1:]):
|
||||
logger.debug('change applied')
|
||||
db.session.add(c)
|
||||
db.session.commit()
|
||||
|
@ -119,7 +117,8 @@ class Changelog(db.Model):
|
|||
db.session.commit()
|
||||
|
||||
def json(self):
|
||||
return [self.revision, self.timestamp, self.sig, self.data]
|
||||
timestamp = self.timestamp or self.created.strftime('%s')
|
||||
return [self.revision, timestamp, self.sig, self.data]
|
||||
|
||||
@classmethod
|
||||
def restore(cls, user_id, path=None):
|
||||
|
@ -150,7 +149,7 @@ class Changelog(db.Model):
|
|||
return True
|
||||
if not i:
|
||||
i = Item.get_or_create(itemid, info)
|
||||
i.modified = datetime.fromtimestamp(float(timestamp))
|
||||
i.modified = datetime.utcfromtimestamp(float(timestamp))
|
||||
if user not in i.users:
|
||||
i.users.append(user)
|
||||
i.update()
|
||||
|
@ -172,7 +171,7 @@ class Changelog(db.Model):
|
|||
i.update_mainid(key, meta[key])
|
||||
else:
|
||||
i.update_meta(meta)
|
||||
i.modified = datetime.fromtimestamp(float(timestamp))
|
||||
i.modified = datetime.utffromtimestamp(float(timestamp))
|
||||
i.save()
|
||||
return True
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ class ReaderHandler(OMLHandler):
|
|||
self.set_status(404)
|
||||
self.finish()
|
||||
return
|
||||
item.sort_accessed = item.accessed = datetime.now()
|
||||
item.sort_accessed = item.accessed = datetime.utcnow()
|
||||
item.sort_timesaccessed = item.timesaccessed = (item.timesaccessed or 0) + 1
|
||||
item.save()
|
||||
return serve_static(self, os.path.join(settings.static_path, html), 'text/html')
|
||||
|
|
|
@ -49,8 +49,8 @@ class Work(db.Model):
|
|||
|
||||
def __init__(self, id):
|
||||
self.id = id
|
||||
self.created = datetime.now()
|
||||
self.modified = datetime.now()
|
||||
self.created = datetime.utcnow()
|
||||
self.modified = datetime.utcnow()
|
||||
|
||||
class Edition(db.Model):
|
||||
|
||||
|
@ -69,8 +69,8 @@ class Edition(db.Model):
|
|||
|
||||
def __init__(self, id):
|
||||
self.id = id
|
||||
self.created = datetime.now()
|
||||
self.modified = datetime.now()
|
||||
self.created = datetime.utcnow()
|
||||
self.modified = datetime.utcnow()
|
||||
|
||||
user_items = db.Table('useritem',
|
||||
db.Column('user_id', db.String(43), db.ForeignKey('user.id')),
|
||||
|
@ -114,8 +114,8 @@ class Item(db.Model):
|
|||
if isinstance(id, list):
|
||||
id = base64.b32encode(hashlib.sha1(''.join(id)).digest())
|
||||
self.id = id
|
||||
self.created = datetime.now()
|
||||
self.modified = datetime.now()
|
||||
self.created = datetime.utcnow()
|
||||
self.modified = datetime.utcnow()
|
||||
self.info = {}
|
||||
self.meta = {}
|
||||
|
||||
|
@ -262,7 +262,7 @@ class Item(db.Model):
|
|||
self.update_sort()
|
||||
self.update_find()
|
||||
self.update_lists()
|
||||
#self.modified = datetime.now()
|
||||
#self.modified = datetime.utcnow()
|
||||
self.save()
|
||||
|
||||
def save(self):
|
||||
|
@ -273,7 +273,7 @@ class Item(db.Model):
|
|||
if data != self.meta:
|
||||
self.meta = data
|
||||
self.update()
|
||||
self.modified = datetime.now()
|
||||
self.modified = datetime.utcnow()
|
||||
self.save()
|
||||
user = state.user()
|
||||
if user in self.users:
|
||||
|
@ -302,7 +302,7 @@ class Item(db.Model):
|
|||
self.scrape()
|
||||
self.update()
|
||||
self.update_cover()
|
||||
self.modified = datetime.now()
|
||||
self.modified = datetime.utcnow()
|
||||
self.save()
|
||||
user = state.user()
|
||||
if user in self.users:
|
||||
|
@ -347,7 +347,7 @@ class Item(db.Model):
|
|||
u = state.user()
|
||||
if not u in self.users:
|
||||
self.transferprogress = 0
|
||||
self.transferadded = datetime.now()
|
||||
self.transferadded = datetime.utcnow()
|
||||
self.users.append(u)
|
||||
|
||||
def save_file(self, content):
|
||||
|
@ -368,7 +368,7 @@ class Item(db.Model):
|
|||
if u not in self.users:
|
||||
self.users.append(u)
|
||||
self.transferprogress = 1
|
||||
self.added = datetime.now()
|
||||
self.added = datetime.utcnow()
|
||||
Changelog.record(u, 'additem', self.id, self.info)
|
||||
self.update()
|
||||
f.move()
|
||||
|
@ -480,8 +480,8 @@ class File(db.Model):
|
|||
|
||||
def __init__(self, sha1):
|
||||
self.sha1 = sha1
|
||||
self.created = datetime.now()
|
||||
self.modified = datetime.now()
|
||||
self.created = datetime.utcnow()
|
||||
self.modified = datetime.utcnow()
|
||||
|
||||
def fullpath(self):
|
||||
prefs = settings.preferences
|
||||
|
|
|
@ -58,7 +58,7 @@ def add_file(id, f, prefix):
|
|||
Changelog.record(user, 'edititem', item.id, {
|
||||
item.meta['mainid']: item.meta[item.meta['mainid']]
|
||||
})
|
||||
item.added = datetime.now()
|
||||
item.added = datetime.utcnow()
|
||||
item.scrape()
|
||||
item.update_cover()
|
||||
item.save()
|
||||
|
|
|
@ -39,7 +39,7 @@ def reader(id, filename=''):
|
|||
html = 'html/txt.html'
|
||||
else:
|
||||
abort(404)
|
||||
item.sort_accessed = item.accessed = datetime.now()
|
||||
item.sort_accessed = item.accessed = datetime.utcnow()
|
||||
item.sort_timesaccessed = item.timesaccessed = (item.timesaccessed or 0) + 1
|
||||
item.save()
|
||||
return app.send_static_file(html)
|
||||
|
|
|
@ -265,7 +265,7 @@ class Node(Thread):
|
|||
headers = {
|
||||
'User-Agent': settings.USER_AGENT,
|
||||
}
|
||||
t1 = datetime.now()
|
||||
t1 = datetime.utcnow()
|
||||
logger.debug('download %s', url)
|
||||
'''
|
||||
r = requests.get(url, headers=headers)
|
||||
|
@ -290,7 +290,7 @@ class Node(Thread):
|
|||
'''
|
||||
content = r.read()
|
||||
|
||||
t2 = datetime.now()
|
||||
t2 = datetime.utcnow()
|
||||
duration = (t2-t1).total_seconds()
|
||||
if duration:
|
||||
self.download_speed = len(content) / duration
|
||||
|
|
Loading…
Reference in a new issue