Add secure filename for modesl and services

This commit is contained in:
stephan 2020-02-17 14:57:24 +01:00
parent 4f5aeed215
commit 241a40ef44
3 changed files with 32 additions and 5 deletions

View File

@ -297,6 +297,7 @@ class Job(db.Model):
end_date = db.Column(db.DateTime())
mem_mb = db.Column(db.Integer)
n_cores = db.Column(db.Integer)
secure_filename = db.Column(db.String(32))
service = db.Column(db.String(64))
'''
' Service specific arguments as string list.
@ -323,8 +324,7 @@ class Job(db.Model):
"""
Takes the job.title string nad cratesa a secure filename from this.
"""
filename = secure_filename(self.title)
return filename
self.secure_filename = secure_filename(self.title)
def delete(self):
"""

View File

@ -37,12 +37,9 @@ def service(service):
return make_response(add_job_form.errors, 400)
service_args = []
if service == 'nlp':
logger.warning(add_job_form.check_encoding)
service_args.append('-l {}'.format(add_job_form.language.data))
logger.warning("Service args: {}".format(service_args))
if add_job_form.check_encoding.data:
service_args.append('--check-encoding')
logger.warning("Service args: {}".format(service_args))
if service == 'ocr':
service_args.append('-l {}'.format(add_job_form.language.data))
if not add_job_form.binarization.data:
@ -54,6 +51,8 @@ def service(service):
service=service, service_args=json.dumps(service_args),
service_version=add_job_form.version.data,
status='preparing', title=add_job_form.title.data)
if job.service != 'corpus_analysis':
job.create_secure_filename()
db.session.add(job)
db.session.commit()
relative_dir = os.path.join(str(job.user_id), 'jobs', str(job.id))

View File

@ -0,0 +1,28 @@
"""empty message
Revision ID: 7378391345fa
Revises: 6227310c2112
Create Date: 2020-02-17 12:29:17.851954
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7378391345fa'
down_revision = '6227310c2112'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('jobs', sa.Column('secure_filename', sa.String(length=32), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('jobs', 'secure_filename')
# ### end Alembic commands ###