Browse Source

save file size in database too

master
lilydjwg 1 year ago
parent
commit
22be04e934
4 changed files with 6 additions and 5 deletions
  1. BIN
      elimage.db.sample
  2. +1
    -0
      elimage.sql
  3. +1
    -1
      main.py
  4. +4
    -4
      models.py

BIN
elimage.db.sample View File


+ 1
- 0
elimage.sql View File

@@ -12,6 +12,7 @@ CREATE TABLE image (
uid INTEGER NOT NULL REFERENCES "user" ("id"),
name VARCHAR(40) NOT NULL,
filename VARCHAR(256) NOT NULL,
size INTEGER NOT NULL,
time TIMESTAMP
);



+ 1
- 1
main.py View File

@@ -107,7 +107,7 @@ class IndexHandler(tornado.web.RequestHandler):
m = hashlib.sha1()
m.update(file['body'])
h = m.hexdigest()
model.add_image(uid, h, file['filename'])
model.add_image(uid, h, file['filename'], len(file['body']))
d = h[:2]
f = h[2:]
p = os.path.join(self.settings['datadir'], d)


+ 4
- 4
models.py View File

@@ -62,10 +62,10 @@ class Model:
return self.cur.lastrowid

@log
def add_image(self, uid, fname, filename):
self.cur.execute('''insert into image (uid, name, time, filename)
values (?, ?, ?, ?)''',
(uid, fname, int(time.time()), filename))
def add_image(self, uid, fname, filename, size):
self.cur.execute('''insert into image (uid, name, time, filename, size)
values (?, ?, ?, ?, ?)''',
(uid, fname, int(time.time()), filename, size))
self.conn.commit()

@log


Loading…
Cancel
Save