diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-06-23 23:18:07 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-06-23 23:18:07 +0200 |
| commit | 3cf70771cb45cc16ec33ffe44e7a1a4799d8f395 (patch) | |
| tree | 55f0edb53141d5f043b486d722f507bfd94abdea /animism-align/cli/app/sql/models/upload.py | |
| parent | 014816dc724c1be60b7dd28d4e608c89b4ed451c (diff) | |
adding web app base
Diffstat (limited to 'animism-align/cli/app/sql/models/upload.py')
| -rw-r--r-- | animism-align/cli/app/sql/models/upload.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/animism-align/cli/app/sql/models/upload.py b/animism-align/cli/app/sql/models/upload.py new file mode 100644 index 0000000..5863b07 --- /dev/null +++ b/animism-align/cli/app/sql/models/upload.py @@ -0,0 +1,44 @@ +from sqlalchemy import create_engine, Table, Column, String, Integer, DateTime +import sqlalchemy.sql.functions as func +from sqlalchemy_utc import UtcDateTime, utcnow +from wtforms_alchemy import ModelForm + +from app.sql.common import db, Base, Session + +from app.utils.file_utils import sha256_tree +from app.settings import app_cfg + +from os.path import join + +class Upload(Base): + """Table for storing references to various media""" + __tablename__ = 'upload' + id = Column(Integer, primary_key=True) + sha256 = Column(String(256), nullable=False) + fn = Column(String(256), nullable=False) + ext = Column(String(4, convert_unicode=True), nullable=False) + username = Column(String(16, convert_unicode=True), nullable=False) + created_at = Column(UtcDateTime(), default=utcnow()) + + def toJSON(self): + return { + 'id': self.id, + 'sha256': self.sha256, + 'fn': self.fn, + 'ext': self.ext, + 'username': self.username, + 'url': self.url(), + 'created_at': self.created_at, + } + + def filename(self): + return "{}{}".format(self.fn) + + def filepath(self): + return join(app_cfg.DIR_UPLOADS, sha256_tree(self.sha256)) + + def fullpath(self): + return join(self.filepath(), self.filename()) + + def url(self): + return join(app_cfg.URL_UPLOADS, sha256_tree(self.sha256), self.filename()) |
