async def get(self, *, rid: objectid.ObjectId): rdoc = await record.get(rid) if not rdoc or rdoc['type'] != constant.record.TYPE_PRETEST: raise error.RecordNotFoundError(rid) if not self.own(rdoc, builtin.PRIV_READ_PRETEST_DATA_SELF, 'uid'): self.check_priv(builtin.PRIV_READ_PRETEST_DATA) if not rdoc.get('data_id'): raise error.RecordDataNotFoundError(rdoc['_id']) secret = await fs.get_secret(rdoc['data_id']) if not secret: raise error.RecordDataNotFoundError(rdoc['_id']) self.redirect(options.cdn_prefix.rstrip('/') + \ self.reverse_url('fs_get', domain_id=builtin.DOMAIN_ID_SYSTEM, secret=secret))
async def get(self, *, rid: objectid.ObjectId): rdoc = await record.get(rid) if not rdoc or rdoc['type'] != constant.record.TYPE_SUBMISSION: raise error.RecordNotFoundError(rid) if not self.own(rdoc, field='uid') and not self.has_priv(builtin.PRIV_READ_RECORD_CODE): self.check_perm(builtin.PERM_READ_RECORD_CODE) if not rdoc.get('code') or rdoc['code_type'] == constant.record.FILE_TYPE_TEXT: raise error.RecordDataNotFoundError(rdoc['_id']) secret = await fs.get_secret(rdoc['code']) if not secret: raise error.RecordDataNotFoundError(rdoc['_id']) self.redirect(options.cdn_prefix.rstrip('/') + \ self.reverse_url('fs_get', domain_id=builtin.DOMAIN_ID_SYSTEM, secret=secret))
async def get(self, *, rid: objectid.ObjectId): rdoc = await record.get(rid) if not rdoc or rdoc['type'] != constant.record.TYPE_PRETEST: raise error.RecordNotFoundError(rid) if not self.own(rdoc, builtin.PRIV_READ_PRETEST_DATA_SELF, 'uid'): self.check_priv(builtin.PRIV_READ_PRETEST_DATA) ddoc = await document.get(rdoc['domain_id'], document.TYPE_PRETEST_DATA, rdoc['data_id']) if not ddoc: raise error.RecordDataNotFoundError(rdoc['_id']) output_buffer = io.BytesIO() zip_file = zipfile.ZipFile(output_buffer, 'a', zipfile.ZIP_DEFLATED) config_content = str(len(ddoc['content'])) + '\n' for i, (data_input, data_output) in enumerate(ddoc['content']): input_file = 'input{0}.txt'.format(i) output_file = 'output{0}.txt'.format(i) config_content += '{0}|{1}|1|10|262144\n'.format( input_file, output_file) zip_file.writestr('Input/{0}'.format(input_file), data_input) zip_file.writestr('Output/{0}'.format(output_file), data_output) zip_file.writestr('Config.ini', config_content) # mark all files as created in Windows :p for zfile in zip_file.filelist: zfile.create_system = 0 zip_file.close() await self.binary(output_buffer.getvalue(), 'application/zip')