Major refactor #141

Merged
sim0n00ps merged 55 commits from whimsical-c4lic0/OF-DL:refactor-architecture into master 2026-02-13 00:21:58 +00:00
7 changed files with 133 additions and 118 deletions
Showing only changes of commit 849fbbc919 - Show all commits

View File

@ -0,0 +1,21 @@
using Newtonsoft.Json;
using OF_DL.Models.Dtos.Common;
namespace OF_DL.Models.Dtos.Stories;
public class MediumDto
{
[JsonProperty("id")] public long Id { get; set; }
[JsonProperty("type")] public string Type { get; set; } = "";
[JsonProperty("convertedToVideo")] public bool ConvertedToVideo { get; set; }
[JsonProperty("canView")] public bool CanView { get; set; }
[JsonProperty("hasError")] public bool HasError { get; set; }
[JsonProperty("createdAt")] public DateTime? CreatedAt { get; set; }
[JsonProperty("files")] public FilesDto Files { get; set; } = new();
}

View File

@ -0,0 +1,24 @@
using Newtonsoft.Json;
namespace OF_DL.Models.Dtos.Stories;
public class StoryDto
{
[JsonProperty("id")] public long Id { get; set; }
[JsonProperty("userId")] public long UserId { get; set; }
[JsonProperty("isWatched")] public bool IsWatched { get; set; }
[JsonProperty("isReady")] public bool IsReady { get; set; }
[JsonProperty("media")] public List<MediumDto> Media { get; set; } = [];
[JsonProperty("createdAt")] public DateTime? CreatedAt { get; set; }
[JsonProperty("question")] public object Question { get; set; } = new();
[JsonProperty("canLike")] public bool CanLike { get; set; }
[JsonProperty("isLiked")] public bool IsLiked { get; set; }
}

View File

@ -0,0 +1,16 @@
using OF_DL.Models.Entities.Common;
namespace OF_DL.Models.Entities.Stories;
public class Medium
{
public long Id { get; set; }
public string? Type { get; set; }
public bool CanView { get; set; }
public DateTime? CreatedAt { get; set; }
public Files Files { get; set; } = new();
}

View File

@ -0,0 +1,10 @@
namespace OF_DL.Models.Entities.Stories;
public class Stories
{
public long Id { get; set; }
public DateTime? CreatedAt { get; set; }
public List<Medium> Media { get; set; } = [];
}

View File

@ -0,0 +1,32 @@
using OF_DL.Models.Dtos.Common;
using OF_DL.Models.Dtos.Stories;
using OF_DL.Models.Entities.Common;
using OF_DL.Models.Entities.Stories;
namespace OF_DL.Models.Mappers;
public static class StoriesMapper
{
public static List<Stories> FromDto(List<StoryDto>? dto) =>
dto == null ? [] : dto.Select(MapStory).ToList();
private static Stories MapStory(StoryDto dto) =>
new() { Id = dto.Id, CreatedAt = dto.CreatedAt, Media = MapMedia(dto.Media) };
private static List<Medium> MapMedia(List<MediumDto>? media) =>
media == null ? [] : media.Select(MapMedium).ToList();
private static Medium MapMedium(MediumDto dto) =>
new()
{
Id = dto.Id,
Type = dto.Type,
CanView = dto.CanView,
CreatedAt = dto.CreatedAt,
Files = MapFiles(dto.Files)
};
private static Files MapFiles(FilesDto? dto) => new() { Full = MapFull(dto?.Full) };
private static Full MapFull(FullDto? dto) => new() { Url = dto?.Url };
}

View File

@ -1,90 +0,0 @@
using Newtonsoft.Json;
namespace OF_DL.Models.Stories;
public class Stories
{
public long id { get; set; }
public long userId { get; set; }
public bool isWatched { get; set; }
public bool isReady { get; set; }
public List<Medium> media { get; set; }
public DateTime? createdAt { get; set; }
public object question { get; set; }
public bool canLike { get; set; }
public bool isLiked { get; set; }
public class Files
{
public Full full { get; set; }
public Thumb thumb { get; set; }
public Preview preview { get; set; }
public SquarePreview squarePreview { get; set; }
}
public class Full
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
public long size { get; set; }
public List<object> sources { get; set; }
}
public class Medium
{
public long id { get; set; }
public string type { get; set; }
public bool convertedToVideo { get; set; }
public bool canView { get; set; }
public bool hasError { get; set; }
public DateTime? createdAt { get; set; }
public Files files { get; set; }
}
public class Preview
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
public long size { get; set; }
public Sources sources { get; set; }
}
public class Source
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
public int duration { get; set; }
public long size { get; set; }
public Sources sources { get; set; }
}
public class Sources
{
[JsonProperty("720")] public object _720 { get; set; }
[JsonProperty("240")] public object _240 { get; set; }
public string w150 { get; set; }
public string w480 { get; set; }
}
public class SquarePreview
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
public long size { get; set; }
public Sources sources { get; set; }
}
public class Thumb
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
public long size { get; set; }
}
}

View File

@ -6,21 +6,22 @@ using System.Xml.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using OF_DL.Models; using OF_DL.Models;
using OF_DL.Models.Stories;
using OF_DL.Models.Streams; using OF_DL.Models.Streams;
using OF_DL.Enumerations; using OF_DL.Enumerations;
using ArchivedDtos = OF_DL.Models.Dtos.Archived; using ArchivedDtos = OF_DL.Models.Dtos.Archived;
using PostDtos = OF_DL.Models.Dtos.Posts;
using MessageDtos = OF_DL.Models.Dtos.Messages;
using PurchasedDtos = OF_DL.Models.Dtos.Purchased;
using ListDtos = OF_DL.Models.Dtos.Lists;
using HighlightDtos = OF_DL.Models.Dtos.Highlights; using HighlightDtos = OF_DL.Models.Dtos.Highlights;
using ListDtos = OF_DL.Models.Dtos.Lists;
using MessageDtos = OF_DL.Models.Dtos.Messages;
using PostDtos = OF_DL.Models.Dtos.Posts;
using PurchasedDtos = OF_DL.Models.Dtos.Purchased;
using StoriesDtos = OF_DL.Models.Dtos.Stories;
using ArchivedEntities = OF_DL.Models.Entities.Archived; using ArchivedEntities = OF_DL.Models.Entities.Archived;
using HighlightEntities = OF_DL.Models.Entities.Highlights; using HighlightEntities = OF_DL.Models.Entities.Highlights;
using ListEntities = OF_DL.Models.Entities.Lists; using ListEntities = OF_DL.Models.Entities.Lists;
using MessageEntities = OF_DL.Models.Entities.Messages; using MessageEntities = OF_DL.Models.Entities.Messages;
using PostEntities = OF_DL.Models.Entities.Posts; using PostEntities = OF_DL.Models.Entities.Posts;
using PurchasedEntities = OF_DL.Models.Entities.Purchased; using PurchasedEntities = OF_DL.Models.Entities.Purchased;
using StoriesEntities = OF_DL.Models.Entities.Stories;
using OF_DL.Models.Mappers; using OF_DL.Models.Mappers;
using OF_DL.Widevine; using OF_DL.Widevine;
using Serilog; using Serilog;
@ -393,60 +394,61 @@ public class APIService(IAuthService authService, IConfigService configService,
{ {
Log.Debug("Media Stories - " + endpoint); Log.Debug("Media Stories - " + endpoint);
List<Stories> stories = JsonConvert.DeserializeObject<List<Stories>>(body, m_JsonSerializerSettings) ?? List<StoriesDtos.StoryDto>? storiesDto =
new List<Stories>(); JsonConvert.DeserializeObject<List<StoriesDtos.StoryDto>>(body, m_JsonSerializerSettings);
List<StoriesEntities.Stories> stories = StoriesMapper.FromDto(storiesDto);
foreach (Stories story in stories) foreach (StoriesEntities.Stories story in stories)
{ {
if (story.media[0].createdAt.HasValue) if (story.Media[0].CreatedAt.HasValue)
{ {
await dbService.AddStory(folder, story.id, string.Empty, "0", false, false, await dbService.AddStory(folder, story.Id, string.Empty, "0", false, false,
story.media[0].createdAt.Value); story.Media[0].CreatedAt.Value);
} }
else if (story.createdAt.HasValue) else if (story.CreatedAt.HasValue)
{ {
await dbService.AddStory(folder, story.id, string.Empty, "0", false, false, await dbService.AddStory(folder, story.Id, string.Empty, "0", false, false,
story.createdAt.Value); story.CreatedAt.Value);
} }
else else
{ {
await dbService.AddStory(folder, story.id, string.Empty, "0", false, false, DateTime.Now); await dbService.AddStory(folder, story.Id, string.Empty, "0", false, false, DateTime.Now);
} }
if (story.media != null && story.media.Count > 0) if (story.Media != null && story.Media.Count > 0)
{ {
foreach (Stories.Medium medium in story.media) foreach (StoriesEntities.Medium medium in story.Media)
{ {
await dbService.AddMedia(folder, medium.id, story.id, medium.files.full.url, null, null, await dbService.AddMedia(folder, medium.Id, story.Id, medium.Files.Full.Url, null, null,
null, "Stories", null, "Stories",
medium.type == "photo" ? "Images" : medium.Type == "photo" ? "Images" :
medium.type == "video" || medium.type == "gif" ? "Videos" : medium.Type == "video" || medium.Type == "gif" ? "Videos" :
medium.type == "audio" ? "Audios" : null, false, false, null); medium.Type == "audio" ? "Audios" : null, false, false, null);
if (medium.type == "photo" && !configService.CurrentConfig.DownloadImages) if (medium.Type == "photo" && !configService.CurrentConfig.DownloadImages)
{ {
continue; continue;
} }
if (medium.type == "video" && !configService.CurrentConfig.DownloadVideos) if (medium.Type == "video" && !configService.CurrentConfig.DownloadVideos)
{ {
continue; continue;
} }
if (medium.type == "gif" && !configService.CurrentConfig.DownloadVideos) if (medium.Type == "gif" && !configService.CurrentConfig.DownloadVideos)
{ {
continue; continue;
} }
if (medium.type == "audio" && !configService.CurrentConfig.DownloadAudios) if (medium.Type == "audio" && !configService.CurrentConfig.DownloadAudios)
{ {
continue; continue;
} }
if (medium.canView) if (medium.CanView)
{ {
if (!return_urls.ContainsKey(medium.id)) if (!return_urls.ContainsKey(medium.Id))
{ {
return_urls.Add(medium.id, medium.files.full.url); return_urls.Add(medium.Id, medium.Files.Full.Url);
} }
} }
} }