mirror of
https://github.com/Ikatono/ComiServ.git
synced 2025-10-28 20:45:35 -05:00
Rearranged repo to make room for additional projects
This commit is contained in:
6
ComiServ/Models/AuthorResponse.cs
Normal file
6
ComiServ/Models/AuthorResponse.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public record class AuthorResponse(string Name, int WorkCount)
|
||||
{
|
||||
|
||||
}
|
||||
40
ComiServ/Models/ComicData.cs
Normal file
40
ComiServ/Models/ComicData.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using ComiServ.Entities;
|
||||
|
||||
namespace ComiServ.Models
|
||||
{
|
||||
public class ComicData
|
||||
{
|
||||
public string Handle { get; set; }
|
||||
public bool Exists { get; set; }
|
||||
public string Filepath { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int PageCount { get; set; }
|
||||
public long SizeBytes { get; set; }
|
||||
public string FileXxhash64 { get; set; }
|
||||
public List<string> Authors { get; set; }
|
||||
public List<string> Tags { get; set; }
|
||||
public ComicData(Comic comic)
|
||||
{
|
||||
Handle = comic.Handle;
|
||||
Exists = comic.Exists;
|
||||
Filepath = comic.Filepath;
|
||||
Title = comic.Title;
|
||||
PageCount = comic.PageCount;
|
||||
SizeBytes = comic.SizeBytes;
|
||||
FileXxhash64 = "";
|
||||
var unsigned = (UInt64)comic.FileXxhash64;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
var c = unsigned % 16;
|
||||
if (c < 10)
|
||||
FileXxhash64 += ((char)('0' + c)).ToString();
|
||||
else
|
||||
FileXxhash64 += ((char)('A' + c - 10)).ToString();
|
||||
unsigned /= 16;
|
||||
}
|
||||
Authors = comic.ComicAuthors.Select(a => a.Author.Name).ToList();
|
||||
Tags = comic.ComicTags.Select(a => a.Tag.Name).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
ComiServ/Models/ComicDeleteRequest.cs
Normal file
7
ComiServ/Models/ComicDeleteRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ComiServ.Models;
|
||||
|
||||
//handle is taken from URL
|
||||
public record class ComicDeleteRequest
|
||||
(
|
||||
bool DeleteIfFileExists
|
||||
);
|
||||
22
ComiServ/Models/ComicDuplicateList.cs
Normal file
22
ComiServ/Models/ComicDuplicateList.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using ComiServ.Entities;
|
||||
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class ComicDuplicateList
|
||||
{
|
||||
public long Hash { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<ComicData> Comics { get; set; }
|
||||
public ComicDuplicateList(long hash, IEnumerable<Comic> comics)
|
||||
{
|
||||
Hash = hash;
|
||||
Comics = comics.Select(c => new ComicData(c)).ToList();
|
||||
Count = Comics.Count;
|
||||
}
|
||||
public ComicDuplicateList(long hash, IEnumerable<ComicData> comics)
|
||||
{
|
||||
Hash = hash;
|
||||
Comics = comics.ToList();
|
||||
Count = Comics.Count;
|
||||
}
|
||||
}
|
||||
9
ComiServ/Models/ComicMetadataUpdateRequest.cs
Normal file
9
ComiServ/Models/ComicMetadataUpdateRequest.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class ComicMetadataUpdateRequest
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public List<string>? Tags { get; set; }
|
||||
public List<string>? Authors { get; set; }
|
||||
}
|
||||
5
ComiServ/Models/LibraryResponse.cs
Normal file
5
ComiServ/Models/LibraryResponse.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public record class LibraryResponse(int ComicCount, int UniqueFiles)
|
||||
{
|
||||
}
|
||||
95
ComiServ/Models/Paginated.cs
Normal file
95
ComiServ/Models/Paginated.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComiServ.Models;
|
||||
public class Paginated<T>
|
||||
{
|
||||
public int Max { get; }
|
||||
public int Page { get; }
|
||||
public bool Last { get; }
|
||||
public int Count { get; }
|
||||
public List<T> Items { get; }
|
||||
public Paginated(int max, int page, IEnumerable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
if (page < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(page), page, "must be greater than or equal to 0");
|
||||
}
|
||||
Max = max;
|
||||
Page = page;
|
||||
Items = iter.Skip(max * page).Take(max + 1).ToList();
|
||||
if (Items.Count > max)
|
||||
{
|
||||
Last = false;
|
||||
Items.RemoveAt(max);
|
||||
}
|
||||
else
|
||||
{
|
||||
Last = true;
|
||||
}
|
||||
Count = Items.Count;
|
||||
}
|
||||
private Paginated(int max, int page, bool last, List<T> items)
|
||||
{
|
||||
Max = max;
|
||||
Page = page;
|
||||
Last = last;
|
||||
Items = items;
|
||||
Count = Items.Count;
|
||||
}
|
||||
public static async Task<Paginated<T>> CreateAsync(int max, int page, IQueryable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
if (page < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(page), page, "must be greater than or equal to 0");
|
||||
}
|
||||
var items = await iter.Skip(max * page).Take(max + 1).ToListAsync();
|
||||
bool last = true;
|
||||
if (items.Count > max)
|
||||
{
|
||||
last = false;
|
||||
items.RemoveAt(max);
|
||||
}
|
||||
return new(max, page, last, items);
|
||||
}
|
||||
public static async Task<Paginated<T>> CreateAsync(int max, int page, IAsyncEnumerable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
if (page < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(page), page, "must be greater than or equal to 0");
|
||||
}
|
||||
List<T> items = [];
|
||||
var skip = max * page;
|
||||
await foreach (T item in iter)
|
||||
{
|
||||
if (skip > 0)
|
||||
{
|
||||
skip--;
|
||||
continue;
|
||||
}
|
||||
items.Add(item);
|
||||
if (items.Count >= max + 1)
|
||||
break;
|
||||
}
|
||||
var last = true;
|
||||
if (items.Count > max)
|
||||
{
|
||||
last = false;
|
||||
items.RemoveAt(max);
|
||||
}
|
||||
return new(max, page, last, items);
|
||||
}
|
||||
}
|
||||
51
ComiServ/Models/RequestError.cs
Normal file
51
ComiServ/Models/RequestError.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class RequestError : IEnumerable<string>
|
||||
{
|
||||
public static RequestError InvalidHandle => new("Invalid handle");
|
||||
public static RequestError ComicNotFound => new("Comic not found");
|
||||
public static RequestError CoverNotFound => new("Cover not found");
|
||||
public static RequestError PageNotFound => new("Page not found");
|
||||
public static RequestError FileNotFound => new("File not found");
|
||||
public static RequestError ThumbnailNotFound => new("Thumbnail not found");
|
||||
public static RequestError NotAuthenticated => new("Not authenticated");
|
||||
public static RequestError NoAccess => new("User does not have access to this resource");
|
||||
public static RequestError UserNotFound => new("User not found");
|
||||
public static RequestError ComicFileExists => new("Comic file exists so comic not deleted");
|
||||
public static RequestError UserSpecificEndpoint => new("Endpoint is user-specific, requires login");
|
||||
public string[] Errors { get; }
|
||||
public RequestError(string ErrorMessage)
|
||||
{
|
||||
Errors = [ErrorMessage];
|
||||
}
|
||||
public RequestError()
|
||||
{
|
||||
Errors = [];
|
||||
}
|
||||
public RequestError(IEnumerable<string> ErrorMessages)
|
||||
{
|
||||
Errors = ErrorMessages.ToArray();
|
||||
}
|
||||
public RequestError And(RequestError other)
|
||||
{
|
||||
return new RequestError(Errors.Concat(other.Errors));
|
||||
}
|
||||
public RequestError And(string other)
|
||||
{
|
||||
return new RequestError(Errors.Append(other));
|
||||
}
|
||||
public RequestError And(IEnumerable<string> other)
|
||||
{
|
||||
return new RequestError(Errors.Concat(other));
|
||||
}
|
||||
public IEnumerator<string> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<string>)Errors).GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
6
ComiServ/Models/TagResponse.cs
Normal file
6
ComiServ/Models/TagResponse.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public record class TagResponse(string Name, int WorkCount)
|
||||
{
|
||||
|
||||
}
|
||||
75
ComiServ/Models/Truncated.cs
Normal file
75
ComiServ/Models/Truncated.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Reflection.PortableExecutable;
|
||||
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class Truncated<T>
|
||||
{
|
||||
public int Max { get; }
|
||||
public int Count { get; }
|
||||
public bool Complete { get; }
|
||||
public List<T> Items { get; }
|
||||
public Truncated(int max, IEnumerable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
Max = max;
|
||||
Items = iter.Take(max+1).ToList();
|
||||
if (Items.Count <= max)
|
||||
{
|
||||
Complete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Items.RemoveAt(max);
|
||||
Complete = false;
|
||||
}
|
||||
Count = Items.Count;
|
||||
}
|
||||
private Truncated(int max, bool complete, List<T> items)
|
||||
{
|
||||
Max = max;
|
||||
Complete = complete;
|
||||
Count = items.Count;
|
||||
Items = items;
|
||||
}
|
||||
public static async Task<Truncated<T>> CreateAsync(int max, IQueryable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
var items = await iter.Take(max+1).ToListAsync();
|
||||
var complete = true;
|
||||
if (items.Count < max)
|
||||
{
|
||||
items.RemoveAt(max);
|
||||
complete = false;
|
||||
}
|
||||
return new(max, complete, items);
|
||||
}
|
||||
public static async Task<Truncated<T>> CreateAsync(int max, IAsyncEnumerable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
List<T> items = [];
|
||||
await foreach (T item in iter)
|
||||
{
|
||||
items.Add(item);
|
||||
if (items.Count > max)
|
||||
break;
|
||||
}
|
||||
var complete = true;
|
||||
if (items.Count <= max)
|
||||
{
|
||||
items.RemoveAt(max);
|
||||
complete = false;
|
||||
}
|
||||
return new Truncated<T>(max, complete, items);
|
||||
}
|
||||
}
|
||||
11
ComiServ/Models/UserCreateRequest.cs
Normal file
11
ComiServ/Models/UserCreateRequest.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using ComiServ.Entities;
|
||||
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class UserCreateRequest
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public UserTypeEnum UserType { get; set; }
|
||||
//NOT HASHED do not persist this object
|
||||
public string Password { get; set; }
|
||||
}
|
||||
6
ComiServ/Models/UserDescription.cs
Normal file
6
ComiServ/Models/UserDescription.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public record class UserDescription(string Username, string Usertype)
|
||||
{
|
||||
|
||||
}
|
||||
10
ComiServ/Models/UserModifyRequest.cs
Normal file
10
ComiServ/Models/UserModifyRequest.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using ComiServ.Entities;
|
||||
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class UserModifyRequest
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string? NewUsername { get; set; }
|
||||
public UserTypeEnum? NewUserType { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user