@@ -571,7 +571,7 @@ def get(self):
571571 zip_fn = '%s_%s.zip' % (
572572 fname , datetime .now ().strftime ('%m%d%y-%H%M%S' ))
573573 self ._set_nginx_headers (zip_fn )
574- else :
574+ elif study_id is not None :
575575 study_id = int (study_id )
576576 try :
577577 study = Study (study_id )
@@ -612,6 +612,53 @@ def get(self):
612612 '%m%d%y-%H%M%S' ))
613613
614614 self ._set_nginx_headers (zip_fn )
615+ else :
616+ prep_id = int (prep_id )
617+ try :
618+ prep = PrepTemplate (prep_id )
619+ except QiitaDBUnknownIDError :
620+ raise HTTPError (422 , reason = 'Prep does not exist' )
621+ else :
622+ public_raw_download = Study (prep .study_id ).public_raw_download
623+ if prep .status != 'public' :
624+ raise HTTPError (404 , reason = 'Prep is not public. If this '
625+ 'is a mistake contact: %s' %
626+ qiita_config .help_email )
627+ elif data == 'raw' and not public_raw_download :
628+ raise HTTPError (422 , reason = 'No raw data access. If this '
629+ 'is a mistake contact: %s'
630+ % qiita_config .help_email )
631+ else :
632+ # raw data
633+ if data == 'raw' :
634+ artifacts = [prep .artifact ]
635+ # bioms
636+ elif data == 'biom' :
637+ artifacts = [a for a in
638+ prep .artifact .descendants .nodes ()
639+ if a .artifact_type == 'BIOM' and
640+ a .visibility == 'public' ]
641+ else :
642+ raise HTTPError (
643+ 422 ,
644+ reason = 'You can only download raw/biom from preps' )
645+ for a in artifacts :
646+ if a .visibility != 'public' or a .has_human :
647+ continue
648+ to_download .extend (self ._list_artifact_files_nginx (a ))
649+
650+ if not to_download :
651+ raise HTTPError (422 , reason = 'Nothing to download. If '
652+ 'this is a mistake contact: %s'
653+ % qiita_config .help_email )
654+ else :
655+ self ._write_nginx_file_list (to_download )
656+
657+ zip_fn = 'prep_%d_%s_%s.zip' % (
658+ prep_id , data , datetime .now ().strftime (
659+ '%m%d%y-%H%M%S' ))
660+
661+ self ._set_nginx_headers (zip_fn )
615662
616663 self .finish ()
617664
0 commit comments