Beispiel #1
0
        public ActionResult <QueryResult <UserItemDataDto> > GetUserDataQuery(
            [FromRoute] Guid checkpointID,
            [FromQuery] string?includeItemTypes,
            [FromQuery] int?startIndex,
            [FromQuery] int?limit)
        {
            var request = new GetUserDataQuery
            {
                CheckpointID     = checkpointID,
                IncludeItemTypes = includeItemTypes,
                StartIndex       = startIndex,
                Limit            = limit
            };

            try
            {
                return(_service.Get(request));
            }
            catch (ArgumentException e)
            {
                return(BadRequest(e.Message));
            }
            catch (ResourceNotFoundException e)
            {
                return(NotFound(e.Message));
            }
        }
Beispiel #2
0
        public QueryResult <UserItemDataDto> Get(GetUserDataQuery request)
        {
            _logger.LogDebug($"InfuseSync: User data requested for CheckpointID '{request.CheckpointID}'");

            var checkpoint = Plugin.Instance.Db.GetCheckpoint(request.CheckpointID);

            if (checkpoint == null)
            {
                throw new ResourceNotFoundException($"Checkpoint with ID '{request.CheckpointID}' not found.");
            }
            if (checkpoint.SyncTimestamp == null)
            {
                throw new ArgumentException($"Sync session should be started before using the checkpoint.");
            }

            var includeTypes = request.IncludeItemTypes?.Split(',');

            var updatedUserData = Plugin.Instance.Db.GetUserInfos(
                checkpoint.Timestamp,
                checkpoint.SyncTimestamp.Value,
                checkpoint.UserId,
                includeTypes,
                request.StartIndex ?? 0,
                request.Limit ?? int.MaxValue
                );

            var totalCount = Plugin.Instance.Db.UserInfoCount(
                checkpoint.Timestamp,
                checkpoint.SyncTimestamp.Value,
                checkpoint.UserId,
                includeTypes
                );

            var user = _userManager.GetUserById(Guid.Parse(checkpoint.UserId));

            if (user == null)
            {
                throw new ResourceNotFoundException($"User not found for checkpoint with ID '{request.CheckpointID}'.");
            }

            var userData = updatedUserData
#if EMBY
                           .Select(data => new KeyValuePair <string, BaseItem>(data.ItemId, _libraryManager.GetItemById(data.Guid)))
#else
                           .Select(data => KeyValuePair.Create(data.Guid, _libraryManager.GetItemById(data.Guid)))
#endif
                           .Where(pair => pair.Value != null)
                           .Select(pair => {
                var dto = _userDataManager.GetUserDataDto(pair.Value, user);
#if EMBY
                dto.ItemId = pair.Key;
#else
                dto.ItemId = pair.Key.ToString("N", CultureInfo.InvariantCulture);
#endif
                return(dto);
            })
                           .ToArray();

            return(new QueryResult <UserItemDataDto> {
                Items = userData,
#if JELLYFIN
                StartIndex = request.StartIndex ?? 0,
#endif
                TotalRecordCount = totalCount
            });
        }