Add API endpoint for getting client options (#1460)
* 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
This commit is contained in:
parent
9dc8aeb263
commit
919c0ecacf
|
@ -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.
|
||||
|
|
|
@ -314,6 +314,14 @@ class LocationContext( HydrusSerialisable.SerialisableBase ):
|
|||
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":
|
||||
|
||||
|
|
|
@ -1111,6 +1111,14 @@ class ClientOptions( HydrusSerialisable.SerialisableBase ):
|
|||
|
||||
|
||||
|
||||
def GetAllBooleans( self ):
|
||||
|
||||
with self._lock:
|
||||
|
||||
return self._dictionary[ 'booleans' ]
|
||||
|
||||
|
||||
|
||||
def GetDefaultCollect( self ):
|
||||
|
||||
with self._lock:
|
||||
|
@ -1134,6 +1142,14 @@ class ClientOptions( HydrusSerialisable.SerialisableBase ):
|
|||
|
||||
|
||||
|
||||
def GetAllColours( self ):
|
||||
|
||||
with self._lock:
|
||||
|
||||
return self._dictionary[ 'colours' ]
|
||||
|
||||
|
||||
|
||||
def GetCustomDefaultSystemPredicates( self, predicate_type = None, comparable_predicate = None ):
|
||||
|
||||
with self._lock:
|
||||
|
@ -1162,7 +1178,7 @@ class ClientOptions( HydrusSerialisable.SerialisableBase ):
|
|||
|
||||
|
||||
|
||||
def GetDefaultFileImportOptions( self, options_type ):
|
||||
def GetDefaultFileImportOptions( self, options_type ) -> FileImportOptions.FileImportOptions:
|
||||
|
||||
with self._lock:
|
||||
|
||||
|
@ -1308,12 +1324,36 @@ class ClientOptions( HydrusSerialisable.SerialisableBase ):
|
|||
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' ]
|
||||
|
||||
|
||||
|
||||
|
@ -1406,6 +1446,14 @@ class ClientOptions( HydrusSerialisable.SerialisableBase ):
|
|||
|
||||
|
||||
|
||||
def GetAllNoneableIntegers( self ):
|
||||
|
||||
with self._lock:
|
||||
|
||||
return self._dictionary[ 'noneable_integers' ]
|
||||
|
||||
|
||||
|
||||
def GetNoneableString( self, name ):
|
||||
|
||||
with self._lock:
|
||||
|
@ -1414,6 +1462,14 @@ class ClientOptions( HydrusSerialisable.SerialisableBase ):
|
|||
|
||||
|
||||
|
||||
def GetAllNoneableStrings( self ):
|
||||
|
||||
with self._lock:
|
||||
|
||||
return self._dictionary[ 'noneable_strings' ]
|
||||
|
||||
|
||||
|
||||
def GetPreviewShowAction( self, mime ):
|
||||
|
||||
with self._lock:
|
||||
|
@ -1506,6 +1562,14 @@ class ClientOptions( HydrusSerialisable.SerialisableBase ):
|
|||
|
||||
|
||||
|
||||
def GetAllStrings( self ):
|
||||
|
||||
with self._lock:
|
||||
|
||||
return self._dictionary[ 'strings' ]
|
||||
|
||||
|
||||
|
||||
def GetStringList( self, name ):
|
||||
|
||||
with self._lock:
|
||||
|
@ -1533,6 +1597,15 @@ class ClientOptions( HydrusSerialisable.SerialisableBase ):
|
|||
|
||||
|
||||
|
||||
def GetAllSuggestedTagsFavourites( self ):
|
||||
|
||||
with self._lock:
|
||||
|
||||
return self._dictionary[ 'suggested_tags' ][ 'favourites' ]
|
||||
|
||||
|
||||
|
||||
|
||||
def GetTagSummaryGenerator( self, name ):
|
||||
|
||||
with self._lock:
|
||||
|
|
|
@ -2697,6 +2697,37 @@ class MediaSort( HydrusSerialisable.SerialisableBase ):
|
|||
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 ):
|
||||
|
|
|
@ -76,6 +76,16 @@ class TagSort( HydrusSerialisable.SerialisableBase ):
|
|||
)
|
||||
|
||||
|
||||
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":
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@ class HydrusServiceClientAPI( HydrusClientService ):
|
|||
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()
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ from hydrus.core.networking import HydrusServerRequest
|
|||
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
|
||||
|
@ -1672,6 +1673,7 @@ class HydrusResourceClientAPIRestrictedGetServices( HydrusResourceClientAPIRestr
|
|||
return response_context
|
||||
|
||||
|
||||
|
||||
class HydrusResourceClientAPIRestrictedAddFiles( HydrusResourceClientAPIRestricted ):
|
||||
|
||||
def _CheckAPIPermissions( self, request: HydrusServerRequest.HydrusRequest ):
|
||||
|
@ -3908,6 +3910,51 @@ class HydrusResourceClientAPIRestrictedManageDatabaseMrBones( HydrusResourceClie
|
|||
|
||||
|
||||
|
||||
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 ):
|
||||
|
|
|
@ -1294,6 +1294,16 @@ class TagContext( HydrusSerialisable.SerialisableBase ):
|
|||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue