diff --git a/docs/developer_api.md b/docs/developer_api.md index 4aea497ed..be6e305fa 100644 --- a/docs/developer_api.md +++ b/docs/developer_api.md @@ -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. diff --git a/hydrus/client/ClientLocation.py b/hydrus/client/ClientLocation.py index 6f692791f..604c96843 100644 --- a/hydrus/client/ClientLocation.py +++ b/hydrus/client/ClientLocation.py @@ -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": diff --git a/hydrus/client/ClientOptions.py b/hydrus/client/ClientOptions.py index 62667e7de..1ad57cd93 100644 --- a/hydrus/client/ClientOptions.py +++ b/hydrus/client/ClientOptions.py @@ -1111,6 +1111,14 @@ def GetBoolean( self, name ): + def GetAllBooleans( self ): + + with self._lock: + + return self._dictionary[ 'booleans' ] + + + def GetDefaultCollect( self ): with self._lock: @@ -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: @@ -1162,7 +1178,7 @@ def GetDefaultExportFilesMetadataRouters( self ): - def GetDefaultFileImportOptions( self, options_type ): + def GetDefaultFileImportOptions( self, options_type ) -> FileImportOptions.FileImportOptions: with self._lock: @@ -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' ] @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/hydrus/client/media/ClientMedia.py b/hydrus/client/media/ClientMedia.py index 28879c39b..de6a44cd8 100644 --- a/hydrus/client/media/ClientMedia.py +++ b/hydrus/client/media/ClientMedia.py @@ -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 ): diff --git a/hydrus/client/metadata/ClientTagSorting.py b/hydrus/client/metadata/ClientTagSorting.py index 3958d9f61..29af831d5 100644 --- a/hydrus/client/metadata/ClientTagSorting.py +++ b/hydrus/client/metadata/ClientTagSorting.py @@ -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": diff --git a/hydrus/client/networking/ClientLocalServer.py b/hydrus/client/networking/ClientLocalServer.py index b5713495b..c1591cd3f 100644 --- a/hydrus/client/networking/ClientLocalServer.py +++ b/hydrus/client/networking/ClientLocalServer.py @@ -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() diff --git a/hydrus/client/networking/ClientLocalServerResources.py b/hydrus/client/networking/ClientLocalServerResources.py index 121969cc2..057695ab9 100644 --- a/hydrus/client/networking/ClientLocalServerResources.py +++ b/hydrus/client/networking/ClientLocalServerResources.py @@ -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 @@ -1672,6 +1673,7 @@ def _threadDoGETJob( self, request: HydrusServerRequest.HydrusRequest ): return response_context + class HydrusResourceClientAPIRestrictedAddFiles( HydrusResourceClientAPIRestricted ): def _CheckAPIPermissions( self, request: HydrusServerRequest.HydrusRequest ): @@ -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 ): diff --git a/hydrus/client/search/ClientSearch.py b/hydrus/client/search/ClientSearch.py index 6d29243fc..3a7f3a2c7 100644 --- a/hydrus/client/search/ClientSearch.py +++ b/hydrus/client/search/ClientSearch.py @@ -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