def CheckPermissionToSeeFiles( self, hash_ids ): with self._lock: if self._search_tag_filter.AllowsEverything(): return if self._last_search_results is None: raise HydrusExceptions.BadRequestException( 'It looks like those search results are no longer available--please run the search again!' ) num_files_asked_for = len( hash_ids ) num_files_allowed_to_see = len( self._last_search_results.intersection( hash_ids ) ) if num_files_allowed_to_see != num_files_asked_for: error_text = 'You do not seem to have access to all those files! You asked to see {} files, but you were only authorised to see {} of them!' error_text = error_text.format( HydrusData.ToHumanInt( num_files_asked_for ), HydrusData.ToHumanInt( num_files_allowed_to_see ) ) raise HydrusExceptions.InsufficientCredentialsException( error_text ) self._search_results_timeout = HydrusData.GetNow() + SEARCH_RESULTS_CACHE_TIMEOUT
def _CheckDataUsage(self): if not self._local_booru_service.BandwidthOK(): raise HydrusExceptions.InsufficientCredentialsException( 'This booru has used all its monthly data. Please try again next month.' )
def CheckCanSeeAllFiles( self ): with self._lock: if not ( self._HasPermission( CLIENT_API_PERMISSION_SEARCH_FILES ) and self._search_tag_filter.AllowsEverything() ): raise HydrusExceptions.InsufficientCredentialsException( 'You do not have permission to see all files, so you cannot do this.' )
def CheckAtLeastOnePermission( self, permissions ): with self._lock: if True not in ( self._HasPermission( permission ) for permission in permissions ): raise HydrusExceptions.InsufficientCredentialsException( 'You need at least one these permissions: {}'.format( ', '.join( basic_permission_to_str_lookup[ permission ] for permission in permissions ) ) )
def CheckPermission(self, permission): if not self.HasPermission(permission): raise HydrusExceptions.InsufficientCredentialsException( 'You do not have permission to: {}'.format( basic_permission_to_str_lookup[permission]))
def CheckCanSearchTags(self, tags): with self._lock: if self._search_tag_filter.AllowsEverything(): return if len(tags) > 0: filtered_tags = self._search_tag_filter.Filter(tags) if len(filtered_tags) > 0: return raise HydrusExceptions.InsufficientCredentialsException( 'You do not have permission to do this search. Your tag search permissions are: {}' .format(self._search_tag_filter.ToPermittedString()))
def ParseFileArguments(path, decompression_bombs_ok=False): HydrusImageHandling.ConvertToPNGIfBMP(path) hash = HydrusFileHandling.GetHashFromPath(path) try: mime = HydrusFileHandling.GetMime(path) if mime in HC.DECOMPRESSION_BOMB_IMAGES and not decompression_bombs_ok: if HydrusImageHandling.IsDecompressionBomb(path): raise HydrusExceptions.InsufficientCredentialsException( 'File seemed to be a Decompression Bomb, which you cannot upload!' ) (size, mime, width, height, duration, num_frames, has_audio, num_words) = HydrusFileHandling.GetFileInfo(path, mime) except Exception as e: raise HydrusExceptions.BadRequestException('File ' + hash.hex() + ' could not parse: ' + str(e)) args = ParsedRequestArguments() args['path'] = path args['hash'] = hash args['size'] = size args['mime'] = mime if width is not None: args['width'] = width if height is not None: args['height'] = height if duration is not None: args['duration'] = duration if num_frames is not None: args['num_frames'] = num_frames args['has_audio'] = has_audio if num_words is not None: args['num_words'] = num_words if mime in HC.MIMES_WITH_THUMBNAILS: try: bounding_dimensions = HC.SERVER_THUMBNAIL_DIMENSIONS target_resolution = HydrusImageHandling.GetThumbnailResolution( (width, height), bounding_dimensions) thumbnail_bytes = HydrusFileHandling.GenerateThumbnailBytes( path, target_resolution, mime, duration, num_frames) except Exception as e: tb = traceback.format_exc() raise HydrusExceptions.BadRequestException( 'Could not generate thumbnail from that file:' + os.linesep + tb) args['thumbnail'] = thumbnail_bytes return args