Browse Source

record client-side filenames

master
lilydjwg 2 years ago
parent
commit
34d01f8c3a
3 changed files with 6 additions and 4 deletions
  1. +1
    -0
      elimage.sql
  2. +1
    -1
      main.py
  3. +4
    -3
      models.py

+ 1
- 0
elimage.sql View File

@@ -11,6 +11,7 @@ CREATE TABLE image (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
uid INTEGER NOT NULL REFERENCES "user" ("id"),
name VARCHAR(40) NOT NULL,
filename VARCHAR(256) 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)
model.add_image(uid, h, file['filename'])
d = h[:2]
f = h[2:]
p = os.path.join(self.settings['datadir'], d)


+ 4
- 3
models.py View File

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

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

@log


Loading…
Cancel
Save