Beispiel #1
0
 public async Task CanGetReuploadRights()
 {
     Assert.Equal(HTMLInterface.PermissionValue.No, await HTMLInterface.GetUploadPermissions(Game.SkyrimSpecialEdition, 266));
     Assert.Equal(HTMLInterface.PermissionValue.Yes, await HTMLInterface.GetUploadPermissions(Game.SkyrimSpecialEdition, 1137));
     Assert.Equal(HTMLInterface.PermissionValue.Hidden, await HTMLInterface.GetUploadPermissions(Game.SkyrimSpecialEdition, 34604));
     Assert.Equal(HTMLInterface.PermissionValue.NotFound, await HTMLInterface.GetUploadPermissions(Game.SkyrimSpecialEdition, 24287));
 }
Beispiel #2
0
        protected override async Task <ExitCode> Run()
        {
            var game = GameRegistry.GetByFuzzyName(GameName).Game;
            var p    = await HTMLInterface.GetUploadPermissions(game, ModId);

            Console.WriteLine($"Game: {game}");
            Console.WriteLine($"ModId: {ModId}");
            Console.WriteLine($"Permissions: {p}");
            return(ExitCode.Ok);
        }
Beispiel #3
0
        public async Task <NexusApiClient.GetModFilesResponse> GetModFiles(string GameName, long ModId)
        {
            //_logger.Log(LogLevel.Information, $"{GameName} {ModId}");
            var game   = GameRegistry.GetByFuzzyName(GameName).Game;
            var result = await _sql.GetModFiles(game, ModId);

            string method = "CACHED";

            if (result == null)
            {
                var api = await GetClient();

                var permission = HTMLInterface.GetUploadPermissions(game, ModId);
                try
                {
                    result = await api.GetModFiles(game, ModId, false);
                }
                catch (HttpException ex)
                {
                    if (ex.Code == 403)
                    {
                        result = new NexusApiClient.GetModFilesResponse {
                            files = new List <NexusFileInfo>()
                        }
                    }
                    ;
                    else
                    {
                        throw;
                    }
                }

                var date = result.files.Select(f => f.uploaded_time).OrderByDescending(o => o).FirstOrDefault();
                date = date == default ? DateTime.UtcNow : date;
                await _sql.AddNexusModFiles(game, ModId, date, result);

                await _sql.SetNexusPermission(game, ModId, await permission);

                method = "NOT_CACHED";
                Interlocked.Increment(ref ForwardCount);
            }
            else
            {
                Interlocked.Increment(ref CachedCount);
            }
            Response.Headers.Add("x-cache-result", method);
            return(result);
        }
        public override async Task <int> Execute()
        {
            await _sql.UpdateGameMetadata();


            var data = await _sql.ModListArchives();

            var nexusArchives = data.Select(a => a.State).OfType <NexusDownloader.State>().Select(d => (d.Game, d.ModID))
                                .Where(g => g.Game.MetaData().NexusGameId != 0)
                                .Distinct()
                                .ToList();

            _logger.LogInformation($"Starting nexus permissions updates for {nexusArchives.Count} mods");

            using var queue = new WorkQueue();

            var prev = await _sql.GetHiddenNexusMods();

            _logger.LogInformation($"Found {prev.Count} hidden nexus mods to check");

            await prev.PMap(queue, async archive =>
            {
                var(game, modID) = archive.Key;
                _logger.LogInformation($"Checking permissions for {game} {modID}");
                var result = await HTMLInterface.GetUploadPermissions(game, modID);
                await _sql.SetNexusPermission(game, modID, result);

                if (archive.Value != result)
                {
                    await _discord.Send(Channel.Ham,
                                        new DiscordMessage {
                        Content = $"Permissions status of {game} {modID} was {archive.Value} is now {result}"
                    });
                    await _sql.PurgeNexusCache(modID);
                    await _quickSync.Notify <ListValidator>();
                }
            });

            return(1);
        }