diff --git a/src/AStar.Dev.Infrastructure.FilesDb/Data/FilesContext.cs b/src/AStar.Dev.Infrastructure.FilesDb/Data/FilesContext.cs index 5f2460b..a9f1eb1 100644 --- a/src/AStar.Dev.Infrastructure.FilesDb/Data/FilesContext.cs +++ b/src/AStar.Dev.Infrastructure.FilesDb/Data/FilesContext.cs @@ -1,4 +1,4 @@ -using AStar.Dev.Infrastructure.FilesDb.Models; +using AStar.Dev.Infrastructure.FilesDb.Models; using Microsoft.EntityFrameworkCore; namespace AStar.Dev.Infrastructure.FilesDb.Data; @@ -76,7 +76,11 @@ public FilesContext() public DbSet DownloadedFileClassifications { get; set; } = null!; /// - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => _ = optionsBuilder.UseSqlite("Data Source=/home/jbarden/Documents/Scrapper/files.db"); + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if(!optionsBuilder.IsConfigured) + _ = optionsBuilder.UseSqlite("Data Source=/home/jbarden/Documents/Scrapper/files.db"); + } /// /// The overridden OnModelCreating method diff --git a/src/AStar.Dev.Wallpaper.Scrapper/App.axaml.cs b/src/AStar.Dev.Wallpaper.Scrapper/App.axaml.cs index 38f07d3..d2a9da1 100644 --- a/src/AStar.Dev.Wallpaper.Scrapper/App.axaml.cs +++ b/src/AStar.Dev.Wallpaper.Scrapper/App.axaml.cs @@ -88,6 +88,7 @@ public override void OnFrameworkInitializationCompleted() .AddTransient() .AddTransient() .AddTransient() + .AddTransient() .AddTransient>(sp => () => sp.GetRequiredService()) .AddTransient(); diff --git a/src/AStar.Dev.Wallpaper.Scrapper/ApplicationMetadata.cs b/src/AStar.Dev.Wallpaper.Scrapper/ApplicationMetadata.cs index 2bb1b1f..6b6c148 100644 --- a/src/AStar.Dev.Wallpaper.Scrapper/ApplicationMetadata.cs +++ b/src/AStar.Dev.Wallpaper.Scrapper/ApplicationMetadata.cs @@ -8,9 +8,12 @@ public static class ApplicationMetadata { public const string Name = "AStar.Dev.Wallpaper.Scrapper"; public const string Version = "1.0.0"; + public const string Redacted = "REDACTED"; public static string ApplicationFolder => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!.CombinePath("..", "..", ".."); public static string FileClassificationsExportFilePath => SpecialDirectories.MyDocuments.CombinePath("Scrapper", "FileClassifications.json"); + + public static string ScrapeConfigurationExportFilePath => SpecialDirectories.MyDocuments.CombinePath("Scrapper", "ScrapeConfiguration.json"); public static string ScrapedTagsExportFilePath => SpecialDirectories.MyDocuments.CombinePath("Scrapper", "ScrapedTags.json"); } diff --git a/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ConnectionStringsDto.cs b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ConnectionStringsDto.cs new file mode 100644 index 0000000..83c41e3 --- /dev/null +++ b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ConnectionStringsDto.cs @@ -0,0 +1,6 @@ +namespace AStar.Dev.Wallpaper.Scrapper.DTOs; + +public sealed record ConnectionStringsDto +{ + public string Sqlite { get; init; } = string.Empty; +} diff --git a/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ScrapeConfigurationDto.cs b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ScrapeConfigurationDto.cs new file mode 100644 index 0000000..6c3e8a3 --- /dev/null +++ b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ScrapeConfigurationDto.cs @@ -0,0 +1,9 @@ +namespace AStar.Dev.Wallpaper.Scrapper.DTOs; + +public sealed record ScrapeConfigurationDto +{ + public ConnectionStringsDto ConnectionStrings { get; init; } = new(); + public UserConfigurationDto UserConfiguration { get; init; } = new(); + public SearchConfigurationDto SearchConfiguration { get; init; } = new(); + public ScrapeDirectoriesDto ScrapeDirectories { get; init; } = new(); +} diff --git a/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ScrapeConfigurationDtoExtensions.cs b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ScrapeConfigurationDtoExtensions.cs new file mode 100644 index 0000000..a6fe900 --- /dev/null +++ b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ScrapeConfigurationDtoExtensions.cs @@ -0,0 +1,109 @@ +using ScrapeConfigurationEntityDomain = AStar.Dev.Infrastructure.FilesDb.Models.ScrapeConfigurationEntity; +using SearchCategoriesDomain = AStar.Dev.Infrastructure.FilesDb.Models.SearchCategories; +using ConnectionStringsDomain = AStar.Dev.Infrastructure.FilesDb.Models.ConnectionStrings; +using UserConfigurationDomain = AStar.Dev.Infrastructure.FilesDb.Models.UserConfiguration; +using SearchConfigurationDomain = AStar.Dev.Infrastructure.FilesDb.Models.SearchConfiguration; +using ScrapeDirectoriesDomain = AStar.Dev.Infrastructure.FilesDb.Models.ScrapeDirectories; + +namespace AStar.Dev.Wallpaper.Scrapper.DTOs; + +public static class ScrapeConfigurationDtoExtensions +{ + public static ScrapeConfigurationDto ToDto(this ScrapeConfigurationEntityDomain entity) => new() + { + ConnectionStrings = new ConnectionStringsDto { Sqlite = entity.ConnectionStrings.Sqlite }, + UserConfiguration = new UserConfigurationDto + { + LoginEmailAddress = entity.UserConfiguration.LoginEmailAddress, + Username = entity.UserConfiguration.Username, + Password = ApplicationMetadata.Redacted, + SessionCookie = ApplicationMetadata.Redacted + }, + SearchConfiguration = new SearchConfigurationDto + { + BaseUrl = entity.SearchConfiguration.BaseUrl, + ApiKey = ApplicationMetadata.Redacted, + SearchCategories = [.. entity.SearchConfiguration.SearchCategories.Select(c => new SearchCategoryDto + { + Id = c.Id, + Name = c.Name, + LastKnownImageCount = c.LastKnownImageCount, + LastPageVisited = c.LastPageVisited, + TotalPages = c.TotalPages, + IncludeInSearch = c.IncludeInSearch + })], + SearchString = entity.SearchConfiguration.SearchString, + TopWallpapers = entity.SearchConfiguration.TopWallpapers, + SearchStringPrefix = entity.SearchConfiguration.SearchStringPrefix, + SearchStringSuffix = entity.SearchConfiguration.SearchStringSuffix, + Subscriptions = entity.SearchConfiguration.Subscriptions, + ImagePauseInSeconds = entity.SearchConfiguration.ImagePauseInSeconds, + StartingPageNumber = entity.SearchConfiguration.StartingPageNumber, + TotalPages = entity.SearchConfiguration.TotalPages, + SubscriptionsStartingPageNumber = entity.SearchConfiguration.SubscriptionsStartingPageNumber, + SubscriptionsTotalPages = entity.SearchConfiguration.SubscriptionsTotalPages, + TopWallpapersTotalPages = entity.SearchConfiguration.TopWallpapersTotalPages, + TopWallpapersStartingPageNumber = entity.SearchConfiguration.TopWallpapersStartingPageNumber, + LoginUrl = entity.SearchConfiguration.LoginUrl, + UseHeadless = entity.SearchConfiguration.UseHeadless, + SlowMotionDelay = entity.SearchConfiguration.SlowMotionDelay + }, + ScrapeDirectories = new ScrapeDirectoriesDto + { + RootDirectory = entity.ScrapeDirectories.RootDirectory, + BaseSaveDirectory = entity.ScrapeDirectories.BaseSaveDirectory, + BaseDirectory = entity.ScrapeDirectories.BaseDirectory, + BaseDirectoryFamous = entity.ScrapeDirectories.BaseDirectoryFamous, + SubDirectoryName = entity.ScrapeDirectories.SubDirectoryName + } + }; + + public static ScrapeConfigurationEntityDomain ToDomain(this ScrapeConfigurationDto dto) => new() + { + ConnectionStrings = new ConnectionStringsDomain { Sqlite = dto.ConnectionStrings.Sqlite }, + UserConfiguration = new UserConfigurationDomain + { + LoginEmailAddress = dto.UserConfiguration.LoginEmailAddress, + Username = dto.UserConfiguration.Username, + Password = dto.UserConfiguration.Password, + SessionCookie = dto.UserConfiguration.SessionCookie + }, + SearchConfiguration = new SearchConfigurationDomain + { + BaseUrl = dto.SearchConfiguration.BaseUrl, + ApiKey = dto.SearchConfiguration.ApiKey, + SearchCategories = [.. dto.SearchConfiguration.SearchCategories.Select(c => new SearchCategoriesDomain + { + Id = c.Id, + Name = c.Name, + LastKnownImageCount = c.LastKnownImageCount, + LastPageVisited = c.LastPageVisited, + TotalPages = c.TotalPages, + IncludeInSearch = c.IncludeInSearch + })], + SearchString = dto.SearchConfiguration.SearchString, + TopWallpapers = dto.SearchConfiguration.TopWallpapers, + SearchStringPrefix = dto.SearchConfiguration.SearchStringPrefix, + SearchStringSuffix = dto.SearchConfiguration.SearchStringSuffix, + Subscriptions = dto.SearchConfiguration.Subscriptions, + ImagePauseInSeconds = dto.SearchConfiguration.ImagePauseInSeconds, + StartingPageNumber = dto.SearchConfiguration.StartingPageNumber, + TotalPages = dto.SearchConfiguration.TotalPages, + SubscriptionsStartingPageNumber = dto.SearchConfiguration.SubscriptionsStartingPageNumber, + SubscriptionsTotalPages = dto.SearchConfiguration.SubscriptionsTotalPages, + TopWallpapersTotalPages = dto.SearchConfiguration.TopWallpapersTotalPages, + TopWallpapersStartingPageNumber = dto.SearchConfiguration.TopWallpapersStartingPageNumber, + LoginUrl = dto.SearchConfiguration.LoginUrl, + UseHeadless = dto.SearchConfiguration.UseHeadless, + SlowMotionDelay = dto.SearchConfiguration.SlowMotionDelay + }, + ScrapeDirectories = new ScrapeDirectoriesDomain + { + RootDirectory = dto.ScrapeDirectories.RootDirectory, + BaseSaveDirectory = dto.ScrapeDirectories.BaseSaveDirectory, + BaseDirectory = dto.ScrapeDirectories.BaseDirectory, + BaseDirectoryFamous = dto.ScrapeDirectories.BaseDirectoryFamous, + SubDirectoryName = dto.ScrapeDirectories.SubDirectoryName + } + }; +} diff --git a/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ScrapeDirectoriesDto.cs b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ScrapeDirectoriesDto.cs new file mode 100644 index 0000000..bcadf9a --- /dev/null +++ b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/ScrapeDirectoriesDto.cs @@ -0,0 +1,10 @@ +namespace AStar.Dev.Wallpaper.Scrapper.DTOs; + +public sealed record ScrapeDirectoriesDto +{ + public string RootDirectory { get; init; } = string.Empty; + public string BaseSaveDirectory { get; init; } = string.Empty; + public string BaseDirectory { get; init; } = string.Empty; + public string BaseDirectoryFamous { get; init; } = string.Empty; + public string SubDirectoryName { get; init; } = string.Empty; +} diff --git a/src/AStar.Dev.Wallpaper.Scrapper/DTOs/SearchCategoryDto.cs b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/SearchCategoryDto.cs new file mode 100644 index 0000000..adbd5c0 --- /dev/null +++ b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/SearchCategoryDto.cs @@ -0,0 +1,11 @@ +namespace AStar.Dev.Wallpaper.Scrapper.DTOs; + +public sealed record SearchCategoryDto +{ + public string Id { get; init; } = string.Empty; + public string Name { get; init; } = string.Empty; + public int LastKnownImageCount { get; init; } + public int LastPageVisited { get; init; } + public int TotalPages { get; init; } + public bool IncludeInSearch { get; init; } = true; +} diff --git a/src/AStar.Dev.Wallpaper.Scrapper/DTOs/SearchConfigurationDto.cs b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/SearchConfigurationDto.cs new file mode 100644 index 0000000..221d797 --- /dev/null +++ b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/SearchConfigurationDto.cs @@ -0,0 +1,23 @@ +namespace AStar.Dev.Wallpaper.Scrapper.DTOs; + +public sealed record SearchConfigurationDto +{ + public string BaseUrl { get; init; } = string.Empty; + public string ApiKey { get; init; } = string.Empty; + public List SearchCategories { get; init; } = []; + public string SearchString { get; init; } = string.Empty; + public string TopWallpapers { get; init; } = string.Empty; + public string SearchStringPrefix { get; init; } = string.Empty; + public string SearchStringSuffix { get; init; } = string.Empty; + public string Subscriptions { get; init; } = string.Empty; + public int ImagePauseInSeconds { get; init; } + public int StartingPageNumber { get; init; } + public int TotalPages { get; init; } + public int SubscriptionsStartingPageNumber { get; init; } + public int SubscriptionsTotalPages { get; init; } + public int TopWallpapersTotalPages { get; init; } + public int TopWallpapersStartingPageNumber { get; init; } + public string LoginUrl { get; init; } = string.Empty; + public bool UseHeadless { get; init; } + public float? SlowMotionDelay { get; init; } +} diff --git a/src/AStar.Dev.Wallpaper.Scrapper/DTOs/UserConfigurationDto.cs b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/UserConfigurationDto.cs new file mode 100644 index 0000000..635c72f --- /dev/null +++ b/src/AStar.Dev.Wallpaper.Scrapper/DTOs/UserConfigurationDto.cs @@ -0,0 +1,9 @@ +namespace AStar.Dev.Wallpaper.Scrapper.DTOs; + +public sealed record UserConfigurationDto +{ + public string LoginEmailAddress { get; init; } = string.Empty; + public string Username { get; init; } = string.Empty; + public string Password { get; init; } = string.Empty; + public string SessionCookie { get; init; } = string.Empty; +} diff --git a/src/AStar.Dev.Wallpaper.Scrapper/MainWindow.axaml b/src/AStar.Dev.Wallpaper.Scrapper/MainWindow.axaml index 87f1dd2..b0022fb 100644 --- a/src/AStar.Dev.Wallpaper.Scrapper/MainWindow.axaml +++ b/src/AStar.Dev.Wallpaper.Scrapper/MainWindow.axaml @@ -10,6 +10,8 @@