diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-04-27 00:01:17 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-04-27 00:01:17 +0200 |
| commit | 8e9214f5d4d2a725eecdb11368451d99168ae240 (patch) | |
| tree | 08afd2bd7d4d12ae30611f56ff7d4300b6a641bf /check/app/models/sql_factory.py | |
| parent | 539755ce75ed90946c012d00c7647692aeb1de71 (diff) | |
storing urls in database
Diffstat (limited to 'check/app/models/sql_factory.py')
| -rw-r--r-- | check/app/models/sql_factory.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/check/app/models/sql_factory.py b/check/app/models/sql_factory.py index 68c2e30..5433b67 100644 --- a/check/app/models/sql_factory.py +++ b/check/app/models/sql_factory.py @@ -32,7 +32,8 @@ class FileTable(Base): __tablename__ = 'files' id = Column(Integer, primary_key=True) sha256 = Column(String(64, convert_unicode=True), nullable=False) - phash = Column(BigInteger, nullable=False) + url = Column(String(255, convert_unicode=True), nullable=False) + phash = Column(BigInteger, nullable=False, index=True) ext = Column(String(4, convert_unicode=True), nullable=False) def toJSON(self): return { @@ -64,11 +65,9 @@ def search_by_hash(hash): match = session.query(FileTable).filter(FileTable.sha256 == hash) return match.first() -def add_phash(sha256, phash, ext): +def add_phash(sha256, phash, ext, url): """Add a file to the table""" - rec = FileTable( - sha256=sha256, phash=phash, ext=ext, - ) + rec = FileTable(sha256=sha256, phash=phash, ext=ext, url=url) session = Session() session.add(rec) session.commit() @@ -93,4 +92,4 @@ def add_phash_by_filename(path): hash = sha256(path) - add_phash(sha256=hash, phash=phash, ext=ext) + add_phash(sha256=hash, phash=phash, ext=ext, url=path) |
