<commit_before>﻿using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Bit.Admin.Models;
using Microsoft.AspNetCore.Authorization;
using Bit.Core;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using System.Linq;

namespace Bit.Admin.Controllers
{
    public class HomeController : Controller
    {
        private readonly GlobalSettings _globalSettings;
        private HttpClient _httpClient = new HttpClient();

        public HomeController(GlobalSettings globalSettings)
        {
            _globalSettings = globalSettings;
        }

        [Authorize]
        public IActionResult Index()
        {
            return View(new HomeModel
            {
                GlobalSettings = _globalSettings,
                CurrentVersion = Core.Utilities.CoreHelpers.GetVersion()
            });
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel
            {
                RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
            });
        }

        public async Task<IActionResult> GetLatestDockerHubVersion(string repository)
        {
            try
            {
                var response = await _httpClient.GetAsync(
                $"https://hub.docker.com/v2/repositories/bitwarden/{repository}/tags/");
                if(response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();
                    var data = JObject.Parse(json);
                    var results = data["results"] as JArray;
                    foreach(var result in results)
                    {
                        var name = result["name"].ToString();
                        if(name.Count(c => c == '.') > 2)
                        {
                            return new JsonResult(name);
                        }
                    }
                }
            }
            catch(HttpRequestException) { }

            return new JsonResult("-");
        }

        public async Task<IActionResult> GetInstalledWebVersion()
        {<commit_msg>dockerhub version by first character number<commit_after>﻿using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Bit.Admin.Models;
using Microsoft.AspNetCore.Authorization;
using Bit.Core;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using System.Linq;

namespace Bit.Admin.Controllers
{
    public class HomeController : Controller
    {
        private readonly GlobalSettings _globalSettings;
        private HttpClient _httpClient = new HttpClient();

        public HomeController(GlobalSettings globalSettings)
        {
            _globalSettings = globalSettings;
        }

        [Authorize]
        public IActionResult Index()
        {
            return View(new HomeModel
            {
                GlobalSettings = _globalSettings,
                CurrentVersion = Core.Utilities.CoreHelpers.GetVersion()
            });
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel
            {
                RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
            });
        }

        public async Task<IActionResult> GetLatestDockerHubVersion(string repository)
        {
            try
            {
                var response = await _httpClient.GetAsync(
                $"https://hub.docker.com/v2/repositories/bitwarden/{repository}/tags/");
                if(response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();
                    var data = JObject.Parse(json);
                    var results = data["results"] as JArray;
                    foreach(var result in results)
                    {
                        var name = result["name"].ToString();
                        if(string.IsNullOrWhiteSpace(name) && name.Length > 0 && char.IsNumber(name[0]))
                        {
                            return new JsonResult(name);
                        }
                    }
                }
            }
            catch(HttpRequestException) { }

            return new JsonResult("-");
        }

        public async Task<IActionResult> GetInstalledWebVersion()
        {
{'fraction_non_alphanumeric': 0.0816, 'fraction_numerical': 0.001142857142857143, 'mean_word_length': 1.551603498542274, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2479160', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1010, 'n_words': 216}