def library_view(item_type: enums.ItemType = enums.ItemType.Gallery, page: int = 0, limit: int = 100, sort_by: str = "", search_query: str = "", filter_id: int = None, view_filter: enums.ViewType = enums.ViewType.Library, ctx=None): """ Fetch items from the database. Provides pagination. Args: item_type: possible items are :py:attr:`.ItemType.Gallery`, :py:attr:`.ItemType.Collection`, :py:attr:`.ItemType.Grouping` page: current page (zero-indexed) sort_by: name of column to order by ... limit: amount of items per page search_query: filter item by search terms filter_id: current filter list id view_filter: ... Returns: list of item message objects """ utils.require_context(ctx) view_filter = enums.ViewType.get(view_filter) item_type = enums.ItemType.get(item_type) db_msg, db_model = item_type._msg_and_model( (enums.ItemType.Gallery, enums.ItemType.Collection, enums.ItemType.Grouping)) items = message.List(db_model.__name__.lower(), db_msg) model_ids = search_cmd.ModelFilter().run(db_model, search_query) [ items.append(db_msg(x)) for x in database_cmd.GetModelItemByID().run( db_model, model_ids, limit=limit, offset=page * limit) ] return items
def get_image(item_type: enums.ItemType = enums.ItemType.Gallery, item_ids: list = [], size: enums.ImageSize = enums.ImageSize.Medium, url: bool = False, uri: bool = False, ctx=None): """ Get image for item. Image content is base64 encoded. Args: item_type: possible items are :py:attr:`.ItemType.Gallery`, :py:attr:`.ItemType.Artist`, :py:attr:`.ItemType.Collection`, :py:attr:`.ItemType.Grouping`, :py:attr:`.ItemType.Page` item_ids: list of item ids size: size of image url: replace image content with url to image file uri: turn raw base64 string into an URI Returns: ``` { item_id : async_command_id } ``` """ utils.require_context(ctx) item_type = enums.ItemType.get(item_type) size = enums.ImageSize.get(size) _, db_item = item_type._msg_and_model( (enums.ItemType.Gallery, enums.ItemType.Collection, enums.ItemType.Grouping, enums.ItemType.Page, enums.ItemType.Artist)) content = {} command_dec = functools.partial(_get_image, {'url': url, 'uri': uri}) for i in item_ids: c = database_cmd.GetModelCover() services.ImageService.generic.add_command(c, command_dec) content[i] = c.start(db_item, i, size) return message.Identity('image', content)
def get_settings(settings: list = [], ctx=None): """ Set settings Send empty list to get all key:values Args: set_list: a list of setting keys Returns: ``` { 'key.name': value } ``` """ utils.require_context(ctx) values = {} if settings: for set_key in settings: try: ns, key = [x.strip() for x in set_key.strip().split('.') if x] except ValueError: raise exceptions.APIError( utils.this_function(), "Invalid setting: '{}'".format(set_key)) if constants.config.key_exists(ns, key): values[set_key] = constants.config.get(ns, key) elif ns.lower() == 'self' and ctx.config and ctx.config.key_exists( ns, key): values[set_key] = ctx.config.get(ns, key) raise NotImplementedError else: raise exceptions.APIError( utils.this_function(), "Setting doesn't exist: '{}'".format(set_key)) else: raise NotImplementedError return message.Identity('settings', values)
def get_settings(settings: dict = {}, ctx=None): """ Get settings Args: settings: a dict containing ``key.name``:``default value``, send an empty dict to retrieve all settings Returns: ``` { 'key.name': value } ``` """ utils.require_context(ctx) values = {} if settings: for set_key in settings: ns, key, cfg = _get_cfg(set_key, ctx) values[set_key] = cfg.get(ns, key, settings[set_key]) else: raise NotImplementedError return message.Identity('settings', values)