Skip to content

Commit

Permalink
Add API endpoint for getting client options (#1460)
Browse files Browse the repository at this point in the history
* Add API endpoint for getting client options

* Add "simple" options endpoint

* Remove simple options endpoint

* Move get_client_options to manage_database

* Add docs for get_client_options api
  • Loading branch information
floogulinc authored Nov 4, 2023
1 parent 9dc8aeb commit 919c0ec
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/developer_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2848,3 +2848,21 @@ Arguments (in percent-encoded JSON):
```

The arguments here are the same as for [GET /get\_files/search\_files](#get_files_search_files). You can set any or none of them to set a search domain like in the dialog.

### **GET `/manage_database/get_client_options`** { id="manage_database_get_client_options" }

!!! warning "Unstable Response"
The response for this path is unstable and subject to change without warning. No examples are given.


_Gets the current options from the client._

Restricted access:
: YES. Manage Database permission needed.

Required Headers: n/a

Arguments: n/a

Response:
: A JSON dump of nearly all options set in the client. The format of this is based on internal hydrus structures and is subject to change without warning with new hydrus versions. Do not rely on anything you find here to continue to exist and don't rely on the structure to be the same.
8 changes: 8 additions & 0 deletions hydrus/client/ClientLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ def ToString( self, name_method ):
return prefix + service_string


def ToDictForAPI( self ):

return {
'current_service_keys' : [ service_key.hex() for service_key in self.current_service_keys ],
'deleted_service_keys' : [ service_key.hex() for service_key in self.deleted_service_keys ]
}


@staticmethod
def STATICCreateAllCurrent( current_service_keys ) -> "LocationContext":

Expand Down
77 changes: 75 additions & 2 deletions hydrus/client/ClientOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,14 @@ def GetBoolean( self, name ):



def GetAllBooleans( self ):

with self._lock:

return self._dictionary[ 'booleans' ]



def GetDefaultCollect( self ):

with self._lock:
Expand All @@ -1134,6 +1142,14 @@ def GetColour( self, colour_type, colourset = None ):



def GetAllColours( self ):

with self._lock:

return self._dictionary[ 'colours' ]



def GetCustomDefaultSystemPredicates( self, predicate_type = None, comparable_predicate = None ):

with self._lock:
Expand Down Expand Up @@ -1162,7 +1178,7 @@ def GetDefaultExportFilesMetadataRouters( self ):



def GetDefaultFileImportOptions( self, options_type ):
def GetDefaultFileImportOptions( self, options_type ) -> FileImportOptions.FileImportOptions:

with self._lock:

Expand Down Expand Up @@ -1308,12 +1324,36 @@ def GetInteger( self, name ):
return self._dictionary[ 'integers' ][ name ]



def GetAllIntegers( self):

with self._lock:

return self._dictionary[ 'integers' ]



def GetKeyHex( self, name ):

with self._lock:

return self._dictionary[ 'keys' ][ name ]



def GetKey( self, name ):

with self._lock:

return bytes.fromhex( self._dictionary[ 'keys' ][ name ] )
return bytes.fromhex( self.GetKeyHex( name ) )



def GetAllKeysHex( self ):

with self._lock:

return self._dictionary[ 'keys' ]



Expand Down Expand Up @@ -1406,6 +1446,14 @@ def GetNoneableInteger( self, name ):



def GetAllNoneableIntegers( self ):

with self._lock:

return self._dictionary[ 'noneable_integers' ]



def GetNoneableString( self, name ):

with self._lock:
Expand All @@ -1414,6 +1462,14 @@ def GetNoneableString( self, name ):



def GetAllNoneableStrings( self ):

with self._lock:

return self._dictionary[ 'noneable_strings' ]



def GetPreviewShowAction( self, mime ):

with self._lock:
Expand Down Expand Up @@ -1506,6 +1562,14 @@ def GetString( self, name ):



def GetAllStrings( self ):

with self._lock:

return self._dictionary[ 'strings' ]



def GetStringList( self, name ):

with self._lock:
Expand Down Expand Up @@ -1533,6 +1597,15 @@ def GetSuggestedTagsFavourites( self, service_key ):



def GetAllSuggestedTagsFavourites( self ):

with self._lock:

return self._dictionary[ 'suggested_tags' ][ 'favourites' ]




def GetTagSummaryGenerator( self, name ):

with self._lock:
Expand Down
31 changes: 31 additions & 0 deletions hydrus/client/media/ClientMedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,37 @@ def ToString( self ):
return '{}, {}'.format( sort_type_string, sort_order_string )


def ToDictForAPI( self ):

( sort_metatype, sort_data ) = self.sort_type

data = {
'sort_metatype' : sort_metatype,
'sort_order' : self.sort_order,
'tag_context': self.tag_context.ToDictForAPI(),
}

if sort_metatype == 'system':

data[ 'sort_type' ] = sort_data

elif sort_metatype == 'namespaces':

(namespaces, tag_display_type) = sort_data

data[ 'namespaces' ] = self.GetNamespaces()
data[ 'tag_display_type' ] = tag_display_type

elif sort_metatype == 'rating':

service_key = sort_data

data[ 'service_key' ] = service_key.hex()

return data



HydrusSerialisable.SERIALISABLE_TYPES_TO_OBJECT_TYPES[ HydrusSerialisable.SERIALISABLE_TYPE_MEDIA_SORT ] = MediaSort

class SortedList( object ):
Expand Down
10 changes: 10 additions & 0 deletions hydrus/client/metadata/ClientTagSorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ def ToString( self ):
)


def ToDictForAPI( self ):

return {
'sort_type' : self.sort_type,
'sort_order' : self.sort_order,
'use_siblings': self.use_siblings,
'group_by' : self.group_by
}


@staticmethod
def STATICGetTextASCDefault() -> "TagSort":

Expand Down
1 change: 1 addition & 0 deletions hydrus/client/networking/ClientLocalServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def _InitRoot( self ):
manage_database.putChild( b'mr_bones', ClientLocalServerResources.HydrusResourceClientAPIRestrictedManageDatabaseMrBones( self._service, self._client_requests_domain ) )
manage_database.putChild( b'lock_on', ClientLocalServerResources.HydrusResourceClientAPIRestrictedManageDatabaseLockOn( self._service, self._client_requests_domain ) )
manage_database.putChild( b'lock_off', ClientLocalServerResources.HydrusResourceClientAPIRestrictedManageDatabaseLockOff( self._service, self._client_requests_domain ) )
manage_database.putChild( b'get_client_options', ClientLocalServerResources.HydrusResourceClientAPIRestrictedManageDatabaseGetClientOptions( self._service, self._client_requests_domain ) )

manage_file_relationships = NoResource()

Expand Down
47 changes: 47 additions & 0 deletions hydrus/client/networking/ClientLocalServerResources.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from hydrus.core.networking import HydrusServerResources

from hydrus.client import ClientAPI
from hydrus.client import ClientOptions
from hydrus.client import ClientConstants as CC
from hydrus.client import ClientLocation
from hydrus.client import ClientThreading
Expand Down Expand Up @@ -1672,6 +1673,7 @@ def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):
return response_context



class HydrusResourceClientAPIRestrictedAddFiles( HydrusResourceClientAPIRestricted ):

def _CheckAPIPermissions( self, request: HydrusServerRequest.HydrusRequest ):
Expand Down Expand Up @@ -3908,6 +3910,51 @@ def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):



class HydrusResourceClientAPIRestrictedManageDatabaseGetClientOptions( HydrusResourceClientAPIRestrictedManageDatabase ):

def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ):

old_options = HG.client_controller.options

new_options: ClientOptions.ClientOptions = HG.client_controller.new_options

options_dict = {
'booleans' : new_options.GetAllBooleans(),
'strings' : new_options.GetAllStrings(),
'noneable_strings' : new_options.GetAllNoneableStrings(),
'integers' : new_options.GetAllIntegers(),
'noneable_integers' : new_options.GetAllNoneableIntegers(),
'keys' : new_options.GetAllKeysHex(),
'colors' : new_options.GetAllColours(),
'media_zooms' : new_options.GetMediaZooms(),
'slideshow_durations' : new_options.GetSlideshowDurations(),
'default_file_import_options' : {
'loud' : new_options.GetDefaultFileImportOptions('loud').GetSummary(),
'quiet' : new_options.GetDefaultFileImportOptions('quiet').GetSummary()
},
'default_namespace_sorts' : [ sort.ToDictForAPI() for sort in new_options.GetDefaultNamespaceSorts() ],
'default_sort' : new_options.GetDefaultSort().ToDictForAPI(),
'default_tag_sort' : new_options.GetDefaultTagSort().ToDictForAPI(),
'fallback_sort' : new_options.GetFallbackSort().ToDictForAPI(),
'suggested_tags_favourites' : new_options.GetAllSuggestedTagsFavourites(),
'default_local_location_context' : new_options.GetDefaultLocalLocationContext().ToDictForAPI()
}

body_dict = {
'old_options' : old_options,
'options' : options_dict,
'services' : GetServicesDict()
}


body = Dumps( body_dict, request.preferred_mime )

response_context = HydrusServerResources.ResponseContext( 200, mime = request.preferred_mime, body = body )

return response_context



class HydrusResourceClientAPIRestrictedManageFileRelationships( HydrusResourceClientAPIRestricted ):

def _CheckAPIPermissions( self, request: HydrusServerRequest.HydrusRequest ):
Expand Down
10 changes: 10 additions & 0 deletions hydrus/client/search/ClientSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,16 @@ def ToString( self, name_method ):
return name_method( self.service_key )


def ToDictForAPI( self ):

return {
'service_key' : self.service_key.hex(),
'include_current_tags' : self.include_current_tags,
'include_pending_tags' : self.include_pending_tags,
'display_service_key' : self.display_service_key.hex()
}



HydrusSerialisable.SERIALISABLE_TYPES_TO_OBJECT_TYPES[ HydrusSerialisable.SERIALISABLE_TYPE_tag_context ] = TagContext

Expand Down

0 comments on commit 919c0ec

Please sign in to comment.