def _threadDoGETJob( self, request ): self._checkBandwidth( request ) # no permission check as any functional account can get thumbnails hash = request.parsed_request_args[ 'hash' ] ( valid, mime ) = HG.server_controller.Read( 'service_has_file', self._service_key, hash ) if not valid: raise HydrusExceptions.NotFoundException( 'Thumbnail not found on this service!' ) if mime not in HC.MIMES_WITH_THUMBNAILS: raise HydrusExceptions.NotFoundException( 'That mime should not have a thumbnail!' ) path = ServerFiles.GetThumbnailPath( hash ) response_context = HydrusServerResources.ResponseContext( 200, mime = HC.APPLICATION_OCTET_STREAM, path = path ) return response_context
def _GetInfo(self, share_key): try: info = self._keys_to_infos[share_key] except: raise HydrusExceptions.NotFoundException( 'Did not find that share on this booru.') if info is None: info = self._controller.Read('local_booru_share', share_key) hashes = info['hashes'] info['hashes_set'] = set(hashes) media_results = self._controller.Read('media_results', hashes) info['media_results'] = media_results hashes_to_media_results = { media_result.GetHash(): media_result for media_result in media_results } info['hashes_to_media_results'] = hashes_to_media_results self._keys_to_infos[share_key] = info return info
def GetThumbnailPath(hash): path = GetExpectedThumbnailPath(hash) if not os.path.exists(path): raise HydrusExceptions.NotFoundException('Thumbnail not found!') return path
def GetFilePath(hash): path = GetExpectedFilePath(hash) if not os.path.exists(path): raise HydrusExceptions.NotFoundException('File not found!') return path
def _CheckFileAuthorised( self, share_key, hash ): self._CheckShareAuthorised( share_key ) info = self._GetInfo( share_key ) if hash not in info[ 'hashes_set' ]: raise HydrusExceptions.NotFoundException( 'That file was not found in that share.' )
def _CheckShareAuthorised(self, share_key): self._CheckDataUsage() info = self._GetInfo(share_key) timeout = info['timeout'] if timeout is not None and HydrusData.TimeHasPassed(timeout): raise HydrusExceptions.NotFoundException('This share has expired.')
def _threadDoGETJob( self, request ): self._checkBandwidth( request ) # no permissions check as any functional account can get updates update_hash = request.parsed_request_args[ 'update_hash' ] if not self._service.HasUpdateHash( update_hash ): raise HydrusExceptions.NotFoundException( 'This update hash does not exist on this service!' ) path = ServerFiles.GetFilePath( update_hash ) response_context = HydrusServerResources.ResponseContext( 200, mime = HC.APPLICATION_OCTET_STREAM, path = path ) return response_context
def _GetServiceKeyToWorkOn( self ): if len( self._go_faster ) > 0: service_keys_that_need_work = list( self._go_faster ) else: service_keys_that_need_work = [ service_key for ( service_key, needs_work ) in self._service_keys_to_needs_work.items() if needs_work ] if len( service_keys_that_need_work ) == 0: raise HydrusExceptions.NotFoundException( 'No service keys need work!' ) ( service_key, ) = random.sample( service_keys_that_need_work, 1 ) return service_key
def _threadDoGETJob(self, request: HydrusServerRequest.HydrusRequest): if 'subject_identifier' not in request.parsed_request_args: raise HydrusExceptions.BadRequestException( 'I was expecting an account identifier for the subject, but did not get one!' ) subject_identifier = request.parsed_request_args['subject_identifier'] if subject_identifier.HasAccountKey(): subject_account_key = subject_identifier.GetAccountKey() try: subject_account = HG.server_controller.Read( 'account', self._service_key, subject_account_key) except HydrusExceptions.InsufficientCredentialsException as e: raise HydrusExceptions.NotFoundException(e) elif subject_identifier.HasContent(): subject_content = subject_identifier.GetContent() subject_account = HG.server_controller.Read( 'account_from_content', self._service_key, subject_content) else: raise HydrusExceptions.BadRequestException( 'The subject\'s account identifier did not include an account key or content!' ) body = HydrusNetworkVariableHandling.DumpHydrusArgsToNetworkBytes( {'account': subject_account}) response_context = HydrusServerResources.ResponseContext(200, body=body) return response_context
def _threadDoGETJob( self, request ): self._checkBandwidth( request ) # no permission check as any functional account can get files hash = request.parsed_request_args[ 'hash' ] ( valid, mime ) = HG.server_controller.Read( 'service_has_file', self._service_key, hash ) if not valid: raise HydrusExceptions.NotFoundException( 'File not found on this service!' ) path = ServerFiles.GetFilePath( hash ) response_context = HydrusServerResources.ResponseContext( 200, mime = mime, path = path ) return response_context