5K size limit has been added to get file content task

This commit is contained in:
Tuncay ÇOLAK 2020-04-28 01:30:10 +03:00
parent 1e9c4af168
commit 58a7e84fc9
2 changed files with 17 additions and 6 deletions

View File

@ -462,3 +462,5 @@ class Util:
return desktop_env

View File

@ -23,21 +23,30 @@ class GetFileContent(AbstractPlugin):
if self.is_exist(file_path):
self.logger.info("File exists: " + file_path)
is_file_exists = True
file_content = self.read_file(file_path)
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='Dosya içeriği başarıyla alındı..',
data=json.dumps({'file_exists': is_file_exists, 'file_content': file_content}),
content_type=self.get_content_type().APPLICATION_JSON.value)
# if the file size is less than 5K
file_size = self.get_size(file_path) / 1024
if file_size <= 5:
file_content = self.read_file(file_path)
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='Dosya içeriği başarıyla alındı..',
data=json.dumps({'file_exists': is_file_exists, 'file_content': file_content}),
content_type=self.get_content_type().APPLICATION_JSON.value)
else:
self.logger.error("File size is too large. File Size: {0}K ".format(str(file_size)))
self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='Dosya içeriği getirilemedi. Dosya boyutu çok büyük.',
content_type=self.get_content_type().APPLICATION_JSON.value)
else:
self.context.create_response(code=self.message_code.TASK_PROCESSED.value,
message='Dosya bulunamadı..',
content_type=self.get_content_type().APPLICATION_JSON.value)
except Exception as e:
self.logger.error(str(e))
self.context.create_response(code=self.message_code.TASK_ERROR.value,
message='Dosya içeriği alınırken hata oluştu: {0}'.format(str(e)))
def handle_task(task, context):
plugin = GetFileContent(task, context)
plugin.handle_task()