<s> import ClientConstants as CC <EOL> import ClientFiles <EOL> import HydrusConstants as HC <EOL> import HydrusData <EOL> import HydrusGlobals <EOL> import HydrusServerResources <EOL> import os <EOL> from twisted . web . static import File as FileResource <EOL> local_booru_css = FileResource ( os . path . join ( HC . STATIC_DIR , '<STR_LIT>' ) , defaultType = '<STR_LIT>' ) <EOL> class HydrusResourceCommandBooru ( HydrusServerResources . HydrusResourceCommand ) : <EOL> def _recordDataUsage ( self , request ) : <EOL> path = request . path [ <NUM_LIT:1> : ] <EOL> if request . method == '<STR_LIT:GET>' : method = HC . GET <EOL> else : method = HC . POST <EOL> if ( HC . LOCAL_BOORU , method , path ) in HC . BANDWIDTH_CONSUMING_REQUESTS : <EOL> num_bytes = request . hydrus_request_data_usage <EOL> HydrusGlobals . client_controller . pub ( '<STR_LIT>' , { CC . LOCAL_BOORU_SERVICE_KEY : [ HydrusData . ServiceUpdate ( HC . SERVICE_UPDATE_REQUEST_MADE , num_bytes ) ] } ) <EOL> def _callbackCheckRestrictions ( self , request ) : <EOL> self . _checkServerBusy ( ) <EOL> self . _checkUserAgent ( request ) <EOL> self . _domain . CheckValid ( request . getClientIP ( ) ) <EOL> return request <EOL> class HydrusResourceCommandBooruFile ( HydrusResourceCommandBooru ) : <EOL> def _threadDoGETJob ( self , request ) : <EOL> share_key = request . hydrus_args [ '<STR_LIT>' ] <EOL> hash = request . hydrus_args [ '<STR_LIT>' ] <EOL> local_booru_manager = HydrusGlobals . client_controller . GetManager ( '<STR_LIT>' ) <EOL> local_booru_manager . CheckFileAuthorised ( share_key , hash ) <EOL> client_files_manager = HydrusGlobals . client_controller . GetClientFilesManager ( ) <EOL> path = client_files_manager . GetFilePath ( hash ) <EOL> response_context = HydrusServerResources . ResponseContext ( <NUM_LIT:200> , path = path ) <EOL> return response_context <EOL> class HydrusResourceCommandBooruGallery ( HydrusResourceCommandBooru ) : <EOL> def _threadDoGETJob ( self , request ) : <EOL> share_key = request . hydrus_args [ '<STR_LIT>' ] <EOL> local_booru_manager = HydrusGlobals . client_controller . GetManager ( '<STR_LIT>' ) <EOL> local_booru_manager . CheckShareAuthorised ( share_key ) <EOL> ( name , text , timeout , media_results ) = local_booru_manager . GetGalleryInfo ( share_key ) <EOL> body = '''<STR_LIT>''' <EOL> if name == '<STR_LIT>' : body += '''<STR_LIT>''' <EOL> else : body += '''<STR_LIT>''' + name + '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' <EOL> ( thumbnail_width , thumbnail_height ) = HC . options [ '<STR_LIT>' ] <EOL> body += '''<STR_LIT>''' + str ( thumbnail_width ) + '''<STR_LIT>''' + str ( thumbnail_height ) + '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' + HydrusData . ConvertTimestampToPrettyExpires ( timeout ) + '''<STR_LIT>''' <EOL> if name != '<STR_LIT>' : body += '''<STR_LIT>''' + name + '''<STR_LIT>''' <EOL> if text != '<STR_LIT>' : <EOL> newline = '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' + text . replace ( os . linesep , newline ) . replace ( '<STR_LIT:\n>' , newline ) + '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' <EOL> for media_result in media_results : <EOL> hash = media_result . GetHash ( ) <EOL> mime = media_result . GetMime ( ) <EOL> body += '''<STR_LIT>''' + share_key . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + hash . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + share_key . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + hash . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' <EOL> response_context = HydrusServerResources . ResponseContext ( <NUM_LIT:200> , mime = HC . TEXT_HTML , body = body ) <EOL> return response_context <EOL> class HydrusResourceCommandBooruPage ( HydrusResourceCommandBooru ) : <EOL> def _threadDoGETJob ( self , request ) : <EOL> share_key = request . hydrus_args [ '<STR_LIT>' ] <EOL> hash = request . hydrus_args [ '<STR_LIT>' ] <EOL> local_booru_manager = HydrusGlobals . client_controller . GetManager ( '<STR_LIT>' ) <EOL> local_booru_manager . CheckFileAuthorised ( share_key , hash ) <EOL> ( name , text , timeout , media_result ) = local_booru_manager . GetPageInfo ( share_key , hash ) <EOL> body = '''<STR_LIT>''' <EOL> if name == '<STR_LIT>' : body += '''<STR_LIT>''' <EOL> else : body += '''<STR_LIT>''' + name + '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' + HydrusData . ConvertTimestampToPrettyExpires ( timeout ) + '''<STR_LIT>''' <EOL> if name != '<STR_LIT>' : body += '''<STR_LIT>''' + name + '''<STR_LIT>''' <EOL> if text != '<STR_LIT>' : <EOL> newline = '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' + text . replace ( os . linesep , newline ) . replace ( '<STR_LIT:\n>' , newline ) + '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' <EOL> mime = media_result . GetMime ( ) <EOL> if mime in HC . IMAGES : <EOL> ( width , height ) = media_result . GetResolution ( ) <EOL> body += '''<STR_LIT>''' + str ( width ) + '''<STR_LIT>''' + str ( height ) + '''<STR_LIT>''' + share_key . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + hash . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' <EOL> elif mime in HC . VIDEO : <EOL> ( width , height ) = media_result . GetResolution ( ) <EOL> body += '''<STR_LIT>''' + str ( width ) + '''<STR_LIT>''' + str ( height ) + '''<STR_LIT>''' + share_key . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + hash . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + share_key . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + hash . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + HC . mime_string_lookup [ mime ] + '''<STR_LIT>''' <EOL> elif mime == HC . APPLICATION_FLASH : <EOL> ( width , height ) = media_result . GetResolution ( ) <EOL> body += '''<STR_LIT>''' + str ( width ) + '''<STR_LIT>''' + str ( height ) + '''<STR_LIT>''' + share_key . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + hash . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + share_key . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + hash . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + HC . mime_string_lookup [ mime ] + '''<STR_LIT>''' <EOL> else : <EOL> body += '''<STR_LIT>''' + share_key . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + hash . encode ( '<STR_LIT>' ) + '''<STR_LIT>''' + HC . mime_string_lookup [ mime ] + '''<STR_LIT>''' <EOL> body += '''<STR_LIT>''' <EOL> response_context = HydrusServerResources . ResponseContext ( <NUM_LIT:200> , mime = HC . TEXT_HTML , body = body ) <EOL> return response_context <EOL> class HydrusResourceCommandBooruThumbnail ( HydrusResourceCommandBooru ) : <EOL> def _threadDoGETJob ( self , request ) : <EOL> share_key = request . hydrus_args [ '<STR_LIT>' ] <EOL> hash = request . hydrus_args [ '<STR_LIT>' ] <EOL> local_booru_manager = HydrusGlobals . client_controller . GetManager ( '<STR_LIT>' ) <EOL> local_booru_manager . CheckFileAuthorised ( share_key , hash ) <EOL> media_result = local_booru_manager . GetMediaResult ( share_key , hash ) <EOL> mime = media_result . GetMime ( ) <EOL> if mime in HC . MIMES_WITH_THUMBNAILS : path = ClientFiles . GetThumbnailPath ( hash , full_size = False ) <EOL> elif mime in HC . AUDIO : path = os . path . join ( HC . STATIC_DIR , '<STR_LIT>' ) <EOL> elif mime == HC . APPLICATION_PDF : path = os . path . join ( HC . STATIC_DIR , '<STR_LIT>' ) <EOL> else : path = os . path . join ( HC . STATIC_DIR , '<STR_LIT>' ) <EOL> response_context = HydrusServerResources . ResponseContext ( <NUM_LIT:200> , path = path ) <EOL> return response_context <EOL> class HydrusResourceCommandLocalFile ( HydrusServerResources . HydrusResourceCommand ) : <EOL> def _threadDoGETJob ( self , request ) : <EOL> hash = request . hydrus_args [ '<STR_LIT>' ] <EOL> client_files_manager = HydrusGlobals . client_controller . GetClientFilesManager ( ) <EOL> path = client_files_manager . GetFilePath ( hash ) <EOL> response_context = HydrusServerResources . ResponseContext ( <NUM_LIT:200> , path = path ) <EOL> return response_context <EOL> class HydrusResourceCommandLocalThumbnail ( HydrusServerResources . HydrusResourceCommand ) : <EOL> def _threadDoGETJob ( self , request ) : <EOL> hash = request . hydrus_args [ '<STR_LIT>' ] <EOL> path = ClientFiles . GetThumbnailPath ( hash ) <EOL> response_context = HydrusServerResources . ResponseContext ( <NUM_LIT:200> , path = path ) <EOL> return response_context </s>
