<commit_before>﻿using Fan.Blog.Enums;
using Fan.Blog.Services;
using Fan.Medias;
using Fan.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace Fan.Web.Pages.Admin
{
    public class MediaModel : PageModel
    {
        private readonly IBlogService _blogSvc;
        private readonly IMediaService _mediaSvc;
        private readonly UserManager<User> _userManager;

        public MediaModel(
            IBlogService blogSvc,
            IMediaService mediaSvc,
            UserManager<User> userManager)
        {
            _blogSvc = blogSvc;
            _mediaSvc = mediaSvc;
            _userManager = userManager;
        }

        // -------------------------------------------------------------------- Helper Classes

        public class ImageVM : Media
        {
            public string FileType { get; set; }
            public string UploadDate { get; set; }
            public string UploadVia { get; set; }
            /// <summary>
            /// The gallery image dialog shows small image as thumbs.
            /// </summary>
            public string UrlSmall { get; set; }
            /// <summary>
            /// The composer inserts medium image.
            /// </summary>
            public string UrlMedium { get; set; }
            /// <summary>
            /// The gallery image dialog preview shows the large image.
            /// </summary>
            public string UrlLarge { get; set; }
            /// <summary>
            /// The gallery image dialog sidebar shows the original url.
            /// </summary>
            public string UrlOriginal { get; set; }

            public bool Selected { get; set; }
        }

        public class ImageData
        {
            public IEnumerable<ImageVM> Images { get; set; }

            public string ErrorMessage { get; set; }
          
            public string ImagesJson => 
                (Images == null || Images.Count() <=0) ? "" : 
                JsonConvert.SerializeObject(Images);
        }

        // -------------------------------------------------------------------- consts & properties

        /// <summary>
        /// Display 96 images at a time.
        /// </summary>
        public const int PAGE_SIZE = 96;

        /// <summary>
        /// Total number of images.
        /// </summary>
        public int ImageCount { get; set; }

        /// <summary>
        /// The json data to bootstrap page initially.<commit_msg>fix: Media Gallery throws js exception "Unexpected token" when there is no image #210<commit_after>﻿using Fan.Blog.Enums;
using Fan.Blog.Services;
using Fan.Medias;
using Fan.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace Fan.Web.Pages.Admin
{
    public class MediaModel : PageModel
    {
        private readonly IBlogService _blogSvc;
        private readonly IMediaService _mediaSvc;
        private readonly UserManager<User> _userManager;

        public MediaModel(
            IBlogService blogSvc,
            IMediaService mediaSvc,
            UserManager<User> userManager)
        {
            _blogSvc = blogSvc;
            _mediaSvc = mediaSvc;
            _userManager = userManager;
        }

        // -------------------------------------------------------------------- Helper Classes

        public class ImageVM : Media
        {
            public string FileType { get; set; }
            public string UploadDate { get; set; }
            public string UploadVia { get; set; }
            /// <summary>
            /// The gallery image dialog shows small image as thumbs.
            /// </summary>
            public string UrlSmall { get; set; }
            /// <summary>
            /// The composer inserts medium image.
            /// </summary>
            public string UrlMedium { get; set; }
            /// <summary>
            /// The gallery image dialog preview shows the large image.
            /// </summary>
            public string UrlLarge { get; set; }
            /// <summary>
            /// The gallery image dialog sidebar shows the original url.
            /// </summary>
            public string UrlOriginal { get; set; }

            public bool Selected { get; set; }
        }

        public class ImageData
        {
            public IEnumerable<ImageVM> Images { get; set; }

            public string ErrorMessage { get; set; }
          
            public string ImagesJson => 
                (Images == null || Images.Count() <=0) ? "[]" : 
                JsonConvert.SerializeObject(Images);
        }

        // -------------------------------------------------------------------- consts & properties

        /// <summary>
        /// Display 96 images at a time.
        /// </summary>
        public const int PAGE_SIZE = 96;

        /// <summary>
        /// Total number of images.
        /// </summary>
        public int ImageCount { get; set; }

        /// <summary>
        /// The json data to bootstrap page initially.
{'fraction_non_alphanumeric': 0.14002932551319647, 'fraction_numerical': 0.0023826979472140763, 'mean_word_length': 1.4405187835420394, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, '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': '1996962', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1306, 'n_words': 414}