|
3 | 3 | using System.ComponentModel.DataAnnotations;
|
4 | 4 | using System.IO;
|
5 | 5 | using System.Linq;
|
6 |
| -// using ImageMagick; |
| 6 | +using ImageMagick; |
7 | 7 | using Newtonsoft.Json;
|
8 | 8 | using Newtonsoft.Json.Converters;
|
9 | 9 | using Shoko.Commons.Extensions;
|
10 | 10 | using Shoko.Models.Enums;
|
11 | 11 | using Shoko.Server.Extensions;
|
12 | 12 | using Shoko.Server.ImageDownload;
|
13 | 13 | using Shoko.Server.Repositories;
|
| 14 | +using Shoko.Server.Utilities; |
14 | 15 |
|
| 16 | +#nullable enable |
15 | 17 | namespace Shoko.Server.API.v3.Models.Common;
|
16 | 18 |
|
17 | 19 | /// <summary>
|
@@ -41,7 +43,7 @@ public class Image
|
41 | 43 | /// The relative path from the base image directory. A client with access to the server's filesystem can map
|
42 | 44 | /// these for quick access and no need for caching
|
43 | 45 | /// </summary>
|
44 |
| - public string RelativeFilepath { get; set; } |
| 46 | + public string? RelativeFilepath { get; set; } |
45 | 47 |
|
46 | 48 | /// <summary>
|
47 | 49 | /// Is it marked as default. Only one default is possible for a given <see cref="Image.Type"/>.
|
@@ -71,24 +73,20 @@ public Image(int id, ImageEntityType type, bool preferred = false, bool disabled
|
71 | 73 | throw new ArgumentException("Static Resources do not use an integer ID");
|
72 | 74 | }
|
73 | 75 |
|
74 |
| - RelativeFilepath = GetImagePath(type, id)?.Replace(ImageUtils.GetBaseImagesPath(), "").Replace("\\", "/"); |
75 |
| - /* |
76 | 76 | var imagePath = GetImagePath(type, id);
|
77 |
| - if (string.IsNullOrEmpty(imagePath)) { |
78 |
| - RelativeFilepath = null; |
79 |
| - Width = null; |
80 |
| - Height = null; |
81 |
| - } |
82 |
| - // This causes serious IO lag on some systems. Removing until we have better Image data structures |
83 |
| - else |
| 77 | + if (!string.IsNullOrEmpty(imagePath)) |
84 | 78 | {
|
85 |
| - var info = new MagickImageInfo(imagePath); |
86 | 79 | RelativeFilepath = imagePath.Replace(ImageUtils.GetBaseImagesPath(), "").Replace("\\", "/");
|
87 | 80 | if (!RelativeFilepath.StartsWith("/"))
|
88 | 81 | RelativeFilepath = "/" + RelativeFilepath;
|
89 |
| - Width = info.Width; |
90 |
| - Height = info.Height; |
91 |
| - }*/ |
| 82 | + // This causes serious IO lag on some systems. Enable at own risk. |
| 83 | + if (Utils.SettingsProvider.GetSettings().LoadImageMetadata) |
| 84 | + { |
| 85 | + var info = new MagickImageInfo(imagePath); |
| 86 | + Width = info.Width; |
| 87 | + Height = info.Height; |
| 88 | + } |
| 89 | + } |
92 | 90 | }
|
93 | 91 |
|
94 | 92 | public Image(string id, ImageEntityType type, bool preferred = false, bool disabled = false)
|
@@ -241,7 +239,7 @@ public static ImageSizeType GetImageSizeTypeFromType(ImageType imageType)
|
241 | 239 | };
|
242 | 240 | }
|
243 | 241 |
|
244 |
| - public static string GetImagePath(ImageEntityType type, int id) |
| 242 | + public static string? GetImagePath(ImageEntityType type, int id) |
245 | 243 | {
|
246 | 244 | string path;
|
247 | 245 |
|
@@ -528,7 +526,7 @@ internal static ImageSource GetRandomImageSource(ImageType imageType)
|
528 | 526 | .Where(a => a != null && !a.GetAllTags().Contains("18 restricted"))
|
529 | 527 | .SelectMany(a => RepoFactory.CrossRef_Anime_Staff.GetByAnimeID(a.AnimeID))
|
530 | 528 | .Where(a => a.RoleType == (int)StaffRoleType.Seiyuu && a.RoleID.HasValue)
|
531 |
| - .Select(a => RepoFactory.AnimeCharacter.GetByID(a.RoleID.Value)) |
| 529 | + .Select(a => RepoFactory.AnimeCharacter.GetByID(a.RoleID!.Value)) |
532 | 530 | .GetRandomElement()?.CharacterID,
|
533 | 531 | ImageEntityType.Staff => RepoFactory.AniDB_Anime.GetAll()
|
534 | 532 | .Where(a => a != null && !a.GetAllTags().Contains("18 restricted"))
|
@@ -620,8 +618,8 @@ public class DefaultImageBody
|
620 | 618 | /// from the API. Also see <seealso cref="Image.ID"/>.
|
621 | 619 | /// </summary>
|
622 | 620 | /// <value></value>
|
623 |
| - [Required] |
624 |
| - public string ID { get; set; } |
| 621 | + [Required, MinLength(1)] |
| 622 | + public string ID { get; set; } = ""; |
625 | 623 |
|
626 | 624 | /// <summary>
|
627 | 625 | /// The image source.
|
|
0 commit comments