From dcd77a4014e1f98a1534533ace77b76663bd8bfc Mon Sep 17 00:00:00 2001 From: Jake <49795711+Rarisma@users.noreply.github.com> Date: Wed, 24 Jul 2024 00:22:38 +0100 Subject: [PATCH] Clean up --- ArticleDB.sql | 7 ++- Firehose/App.xaml | 2 +- Firehose/App.xaml.cs | 26 +++++---- Firehose/Glob.cs | 20 +++++-- Firehose/MainPage.xaml | 32 ----------- Firehose/MainPage.xaml.cs | 40 -------------- Firehose/Platforms/Android/Main.Android.cs | 2 +- .../Platforms/Android/MainActivity.Android.cs | 2 +- Firehose/Platforms/Desktop/Program.cs | 4 +- .../Platforms/MacCatalyst/Main.maccatalyst.cs | 2 +- Firehose/Platforms/WebAssembly/Program.cs | 2 +- Firehose/Platforms/iOS/Main.iOS.cs | 2 +- Firehose/Preferences/PreferencesModel.cs | 36 +++++++----- Firehose/UI/ArticleList.xaml | 11 ++-- Firehose/UI/ArticleList.xaml.cs | 9 ++- Firehose/UI/Controls/ArticleSelector.cs | 2 +- Firehose/UI/Controls/CommonNavigationBar.xaml | 2 +- .../UI/Controls/CommonNavigationBar.xaml.cs | 8 +-- Firehose/UI/Controls/Filters.xaml | 2 +- Firehose/UI/Controls/Filters.xaml.cs | 4 +- Firehose/UI/Controls/LoadableCommand.cs | 2 +- Firehose/UI/Controls/PublisherFilter.xaml | 2 +- Firehose/UI/Controls/PublisherFilter.xaml.cs | 2 +- .../UI/Controls/PublisherInformation.xaml | 2 +- .../UI/Controls/PublisherInformation.xaml.cs | 4 +- Firehose/UI/Dialogs/AIFeedbackDialog.xaml | 2 +- Firehose/UI/Dialogs/AIFeedbackDialog.xaml.cs | 5 +- Firehose/UI/Dialogs/QuickView.xaml | 2 +- Firehose/UI/Dialogs/QuickView.xaml.cs | 4 +- Firehose/UI/Preferences.xaml | 16 ++++-- Firehose/UI/Preferences.xaml.cs | 7 +-- Firehose/UI/ReaderView.xaml | 6 +- Firehose/UI/ReaderView.xaml.cs | 7 ++- Firehose/UI/WebView.xaml | 7 ++- Firehose/UI/WebView.xaml.cs | 13 ++++- Firehose/Viewmodels/AppDataVM.cs | 2 +- Firehose/Viewmodels/ShellVM.cs | 43 ++++++++------- Firehose/Viewmodels/ThemeVM.cs | 2 +- Hydrant/API.cs | 14 ++++- Hydrant/SQL.cs | 55 ++++++++++--------- 40 files changed, 205 insertions(+), 207 deletions(-) delete mode 100644 Firehose/MainPage.xaml delete mode 100644 Firehose/MainPage.xaml.cs diff --git a/ArticleDB.sql b/ArticleDB.sql index cdc610a..d6fd62a 100644 --- a/ArticleDB.sql +++ b/ArticleDB.sql @@ -43,6 +43,7 @@ BEGIN END // DELIMITER ; -select * from Articles; -SELECT ARTICLE_TEXT FROM ARTICLES WHERE URL = - +SELECT * +FROM ARTICLES +WHERE created_at >= NOW() - INTERVAL 2 DAY + AND created_at < NOW() - INTERVAL 1 DAY; diff --git a/Firehose/App.xaml b/Firehose/App.xaml index 20e807b..d406ee9 100644 --- a/Firehose/App.xaml +++ b/Firehose/App.xaml @@ -1,4 +1,4 @@ - @@ -28,12 +30,7 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args) PreferencesModel.Load(); configureIOC(); - App.Current.UnhandledException += Current_UnhandledException; - - if (MainWindow.Content is not MainPage) - { - // Place the frame in the current Window - } + Current.UnhandledException += Current_UnhandledException; Glob.Publications = await new API().GetPublications(); @@ -46,8 +43,15 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args) Glob.DoNavi(new ArticleList()); } + //Set window info and show it. + MainWindow.SetWindowIcon(); + MainWindow.Title = $"Firehose News {Package.Current.Id.Version.Major}." + + $"{Package.Current.Id.Version.Minor}.{Package.Current.Id.Version.Build}"; - // Ensure the current window is active + if (Debugger.IsAttached) + { + MainWindow.Title += " (DEV)"; + } MainWindow.Activate(); } diff --git a/Firehose/Glob.cs b/Firehose/Glob.cs index 9f4c5e7..066f482 100644 --- a/Firehose/Glob.cs +++ b/Firehose/Glob.cs @@ -1,12 +1,24 @@ using Windows.UI.Core; -using Firehose.Preferences; +using FirehoseApp.Preferences; using HYDRANT.Definitions; + //I'VE GOT A RECKLESS TONGUE -namespace Firehose; +namespace FirehoseApp; public static class Glob { + /// + /// Is the user part of the test group + /// + public static bool TestGroup = true; + + /// + /// Does the user have a FHN+ subscription? + /// (Not implemented, does nothing if set to true) + /// + public static bool FNHPlus = false; + public static Stack NaviStack = new(); - public static PreferencesModel Model; + public static PreferencesModel? Model; public static XamlRoot? XamlRoot; /// @@ -19,7 +31,7 @@ public static class Glob /// The built-in navigation within Frames doesn't work /// like I want it to work, so we persist the page items properly. /// - public static void DoNavi() + private static void DoNavi() { App.MainWindow.Content = (UIElement)NaviStack.First(); } diff --git a/Firehose/MainPage.xaml b/Firehose/MainPage.xaml deleted file mode 100644 index 1131239..0000000 --- a/Firehose/MainPage.xaml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Firehose/MainPage.xaml.cs b/Firehose/MainPage.xaml.cs deleted file mode 100644 index 9be43f4..0000000 --- a/Firehose/MainPage.xaml.cs +++ /dev/null @@ -1,40 +0,0 @@ -using CommunityToolkit.Mvvm.DependencyInjection; -using Firehose.UI; -using Firehose.Viewmodels; -using Microsoft.UI; - -namespace Firehose; - -public sealed partial class MainPage : Page -{ - private ShellVM ShellVM = Ioc.Default.GetRequiredService(); - public MainPage() - { - InitializeComponent(); - //OnLayoutUpdated(null, null); - - } - - private void Loaded(object sender, RoutedEventArgs e) - { - if (Display.CurrentLayout >= Uno.Toolkit.UI.Layout.Wide) - { - Glob.NaviStack.Push(new StackPanel - { - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - Children = { new TextBlock - { - Text = "Click an article on the left to open it", - HorizontalTextAlignment = TextAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - HorizontalAlignment = HorizontalAlignment.Center - } } - }); - } - else - { - Glob.DoNavi(new ArticleList()); - } - } -} diff --git a/Firehose/Platforms/Android/Main.Android.cs b/Firehose/Platforms/Android/Main.Android.cs index 4244620..fe41ed4 100644 --- a/Firehose/Platforms/Android/Main.Android.cs +++ b/Firehose/Platforms/Android/Main.Android.cs @@ -11,7 +11,7 @@ using Com.Nostra13.Universalimageloader.Core; using Microsoft.UI.Xaml.Media; -namespace Firehose.Droid; +namespace FirehoseApp.Droid; [global::Android.App.ApplicationAttribute( Label = "@string/ApplicationName", Icon = "@mipmap/icon", diff --git a/Firehose/Platforms/Android/MainActivity.Android.cs b/Firehose/Platforms/Android/MainActivity.Android.cs index 3ada673..4319fa2 100644 --- a/Firehose/Platforms/Android/MainActivity.Android.cs +++ b/Firehose/Platforms/Android/MainActivity.Android.cs @@ -5,7 +5,7 @@ using Android.Views; using Android.Widget; -namespace Firehose.Droid; +namespace FirehoseApp.Droid; [Activity( MainLauncher = true, ConfigurationChanges = global::Uno.UI.ActivityHelper.AllConfigChanges, diff --git a/Firehose/Platforms/Desktop/Program.cs b/Firehose/Platforms/Desktop/Program.cs index 46bf311..220dd2c 100644 --- a/Firehose/Platforms/Desktop/Program.cs +++ b/Firehose/Platforms/Desktop/Program.cs @@ -1,6 +1,7 @@ +using Uno.Resizetizer; using Uno.UI.Runtime.Skia; -namespace Firehose; +namespace FirehoseApp; public class Program { [STAThread] @@ -17,5 +18,6 @@ public static void Main(string[] args) .Build(); host.Run(); + } } diff --git a/Firehose/Platforms/MacCatalyst/Main.maccatalyst.cs b/Firehose/Platforms/MacCatalyst/Main.maccatalyst.cs index 5f54281..6ce7430 100644 --- a/Firehose/Platforms/MacCatalyst/Main.maccatalyst.cs +++ b/Firehose/Platforms/MacCatalyst/Main.maccatalyst.cs @@ -1,6 +1,6 @@ using UIKit; -namespace Firehose.MacCatalyst; +namespace FirehoseApp.MacCatalyst; public class EntryPoint { // This is the main entry point of the application. diff --git a/Firehose/Platforms/WebAssembly/Program.cs b/Firehose/Platforms/WebAssembly/Program.cs index 095c8bb..c18d092 100644 --- a/Firehose/Platforms/WebAssembly/Program.cs +++ b/Firehose/Platforms/WebAssembly/Program.cs @@ -1,4 +1,4 @@ -namespace Firehose; +namespace FirehoseApp. public class Program { diff --git a/Firehose/Platforms/iOS/Main.iOS.cs b/Firehose/Platforms/iOS/Main.iOS.cs index 9421e30..d62ad37 100644 --- a/Firehose/Platforms/iOS/Main.iOS.cs +++ b/Firehose/Platforms/iOS/Main.iOS.cs @@ -1,6 +1,6 @@ using UIKit; -namespace Firehose.iOS; +namespace FirehoseApp.iOS; public class EntryPoint { // This is the main entry point of the application. diff --git a/Firehose/Preferences/PreferencesModel.cs b/Firehose/Preferences/PreferencesModel.cs index 6b4b668..e3291e1 100644 --- a/Firehose/Preferences/PreferencesModel.cs +++ b/Firehose/Preferences/PreferencesModel.cs @@ -1,17 +1,25 @@ using System.Text.Json; using HYDRANT.Definitions; -namespace Firehose.Preferences; +namespace FirehoseApp.Preferences; public class PreferencesModel { - + /// + /// the folder where the preferences are saved to + /// static StorageFolder SaveFolder = ApplicationData.Current.LocalFolder; + + /// + /// The file path to prefs.json + /// static string SavePath = Path.Combine(SaveFolder.Path, "prefs.json"); public PreferencesModel() { Proxy = string.Empty; - ArticleFetchLimit = 20; + ArticleFetchLimit = 50; BookmarkedArticles = new(); + OpenInMode = 0; + UserGeneratedContent = false; } /// @@ -20,29 +28,31 @@ public PreferencesModel() public string Proxy { get; set; } /// - /// Don't use web view, jump to reader mode. + /// Controls what articles are opened in + /// 0 - Article WebView + /// 1 - Reader Mode + /// 2 - Default Web Browser /// - public bool AlwaysOpenReader { get; set; } + public int OpenInMode { get; set; } /// /// Article fetch limit /// public int ArticleFetchLimit { get; set; } - + /// - /// Article Objects that the user has bookmarked + /// Article fetch limit /// - public List
BookmarkedArticles { get; set; } + public bool UserGeneratedContent { get; set; } /// - /// Tapping/clicking an article will open the summary - /// instead of opening the article itself. + /// Article Objects that the user has bookmarked /// - public bool ArticleTapOpensSummary { get; set; } + public List
BookmarkedArticles { get; set; } /// - /// write prefs model + /// write this model /// public static void Save() { @@ -60,7 +70,7 @@ public static void Save() } /// - /// Load prefs model. + /// Load this model. /// public static void Load() { diff --git a/Firehose/UI/ArticleList.xaml b/Firehose/UI/ArticleList.xaml index 4ef7d64..e785d48 100644 --- a/Firehose/UI/ArticleList.xaml +++ b/Firehose/UI/ArticleList.xaml @@ -1,5 +1,5 @@  @@ -35,7 +36,7 @@ - + @@ -61,7 +62,7 @@ - + - + @@ -125,7 +126,7 @@ - diff --git a/Firehose/UI/ArticleList.xaml.cs b/Firehose/UI/ArticleList.xaml.cs index 671762c..9f0bb87 100644 --- a/Firehose/UI/ArticleList.xaml.cs +++ b/Firehose/UI/ArticleList.xaml.cs @@ -1,12 +1,12 @@ using CommunityToolkit.Mvvm.DependencyInjection; -using Firehose.UI.Controls; -using Firehose.Viewmodels; +using FirehoseApp.UI.Controls; +using FirehoseApp.Viewmodels; using HYDRANT.Definitions; using Microsoft.UI; using Microsoft.UI.Xaml.Media.Imaging; using Uno.Extensions; -namespace Firehose.UI; +namespace FirehoseApp.UI; public sealed partial class ArticleList : Page { @@ -54,8 +54,7 @@ public ArticleList() private void OpenSettings(object sender, RoutedEventArgs e) { - Glob.NaviStack.Push(new Preferences()); - Glob.DoNavi(); + Glob.DoNavi(new Preferences()); } /// diff --git a/Firehose/UI/Controls/ArticleSelector.cs b/Firehose/UI/Controls/ArticleSelector.cs index d2a4d1a..8958830 100644 --- a/Firehose/UI/Controls/ArticleSelector.cs +++ b/Firehose/UI/Controls/ArticleSelector.cs @@ -1,7 +1,7 @@ using HYDRANT.Definitions; //LIVING WITH DETERMINATION -namespace Firehose.UI.Controls; +namespace FirehoseApp.UI.Controls; /// /// This determines how an article is displayed in article view. diff --git a/Firehose/UI/Controls/CommonNavigationBar.xaml b/Firehose/UI/Controls/CommonNavigationBar.xaml index a333f7c..a9cf9bb 100644 --- a/Firehose/UI/Controls/CommonNavigationBar.xaml +++ b/Firehose/UI/Controls/CommonNavigationBar.xaml @@ -1,5 +1,5 @@ (); diff --git a/Firehose/UI/Controls/LoadableCommand.cs b/Firehose/UI/Controls/LoadableCommand.cs index ec9a0ae..85b8bb3 100644 --- a/Firehose/UI/Controls/LoadableCommand.cs +++ b/Firehose/UI/Controls/LoadableCommand.cs @@ -1,5 +1,5 @@ //Copied from UNO UI Loadable page -namespace Firehose.UI.Controls; +namespace FirehoseApp.UI.Controls; public class AsyncCommand : ICommand, ILoadable { public event EventHandler? CanExecuteChanged; diff --git a/Firehose/UI/Controls/PublisherFilter.xaml b/Firehose/UI/Controls/PublisherFilter.xaml index aa9f9ea..972521f 100644 --- a/Firehose/UI/Controls/PublisherFilter.xaml +++ b/Firehose/UI/Controls/PublisherFilter.xaml @@ -1,5 +1,5 @@  /// An empty page that can be used on its own or navigated to within a Frame. diff --git a/Firehose/UI/Controls/PublisherInformation.xaml b/Firehose/UI/Controls/PublisherInformation.xaml index 433f5e2..5b7795d 100644 --- a/Firehose/UI/Controls/PublisherInformation.xaml +++ b/Firehose/UI/Controls/PublisherInformation.xaml @@ -1,5 +1,5 @@ (); diff --git a/Firehose/UI/Dialogs/AIFeedbackDialog.xaml b/Firehose/UI/Dialogs/AIFeedbackDialog.xaml index a7134b0..a5be4a4 100644 --- a/Firehose/UI/Dialogs/AIFeedbackDialog.xaml +++ b/Firehose/UI/Dialogs/AIFeedbackDialog.xaml @@ -1,5 +1,5 @@  + Maximum="200" Margin="10" MaxWidth="200" + Value="{x:Bind Model.ArticleFetchLimit, Mode=TwoWay}"/> - + + + Article WebView + Reader mode + Default Browser + @@ -33,7 +39,7 @@ - diff --git a/Firehose/UI/Preferences.xaml.cs b/Firehose/UI/Preferences.xaml.cs index a74e6cc..caf5cda 100644 --- a/Firehose/UI/Preferences.xaml.cs +++ b/Firehose/UI/Preferences.xaml.cs @@ -1,14 +1,13 @@ -using Firehose.Preferences; +using FirehoseApp.Preferences; -namespace Firehose.UI; +namespace FirehoseApp.UI; /// /// An empty page that can be used on its own or navigated to within a Frame. /// public sealed partial class Preferences : Page { private PreferencesModel Model; - - + public string AppVer { get => $"{Package.Current.DisplayName} Version {Package.Current.Id.Version.Major}." + diff --git a/Firehose/UI/ReaderView.xaml b/Firehose/UI/ReaderView.xaml index f24f27b..09f3b15 100644 --- a/Firehose/UI/ReaderView.xaml +++ b/Firehose/UI/ReaderView.xaml @@ -1,10 +1,10 @@  @@ -26,7 +26,7 @@ - diff --git a/Firehose/UI/ReaderView.xaml.cs b/Firehose/UI/ReaderView.xaml.cs index 95b1bd3..6e2c352 100644 --- a/Firehose/UI/ReaderView.xaml.cs +++ b/Firehose/UI/ReaderView.xaml.cs @@ -1,6 +1,9 @@ +using CommunityToolkit.Mvvm.DependencyInjection; +using FirehoseApp.Viewmodels; +using HYDRANT; using HYDRANT.Definitions; -namespace Firehose.UI; +namespace FirehoseApp.UI; public sealed partial class ReaderMode : Page { @@ -11,6 +14,4 @@ public ReaderMode(Article Data) Article = Data; InitializeComponent(); } - - private void GoBack(object sender, RoutedEventArgs e) => Glob.GoBack(); } diff --git a/Firehose/UI/WebView.xaml b/Firehose/UI/WebView.xaml index 22f4b08..c1d533f 100644 --- a/Firehose/UI/WebView.xaml +++ b/Firehose/UI/WebView.xaml @@ -1,10 +1,11 @@  @@ -13,9 +14,9 @@ - + + VerticalAlignment="Stretch" Grid.Row="1" Name="WV2" Loaded="WV2_OnLoaded"/> diff --git a/Firehose/UI/WebView.xaml.cs b/Firehose/UI/WebView.xaml.cs index b5fc959..19eba92 100644 --- a/Firehose/UI/WebView.xaml.cs +++ b/Firehose/UI/WebView.xaml.cs @@ -1,7 +1,7 @@ using HYDRANT.Definitions; using Microsoft.UI; -namespace Firehose.UI; +namespace FirehoseApp.UI; public sealed partial class ArticleView : Page { @@ -19,4 +19,15 @@ public ArticleView(Article Data) } else { Background = new SolidColorBrush(Colors.LightGray); } } + + private async void WV2_OnLoaded(object sender, RoutedEventArgs e) + { + //WORKAROUND: Fix sign-ins for the verge and co on mobile + //Sign-ins can be blocked based on useragent, so we just set them to + //basic desktop ones + await WV2.EnsureCoreWebView2Async(); + WV2.CoreWebView2.Settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" + + " AppleWebKit/537.36 (KHTML, like Gecko) " + + "Chrome/126.0.0.0 Safari/537.36 Edg/126.0.2592.113"; + } } diff --git a/Firehose/Viewmodels/AppDataVM.cs b/Firehose/Viewmodels/AppDataVM.cs index 038cece..5dfbcb4 100644 --- a/Firehose/Viewmodels/AppDataVM.cs +++ b/Firehose/Viewmodels/AppDataVM.cs @@ -1,4 +1,4 @@ -namespace Firehose.Viewmodels; +namespace FirehoseApp.Viewmodels; internal class AppDataVM { /// diff --git a/Firehose/Viewmodels/ShellVM.cs b/Firehose/Viewmodels/ShellVM.cs index b0f0bd7..e0d494e 100644 --- a/Firehose/Viewmodels/ShellVM.cs +++ b/Firehose/Viewmodels/ShellVM.cs @@ -1,12 +1,12 @@ using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; -using Firehose.UI; -using Firehose.UI.Controls; +using FirehoseApp.UI; +using FirehoseApp.UI.Controls; using HYDRANT; using HYDRANT.Definitions; using Uno.Extensions; -namespace Firehose.Viewmodels; +namespace FirehoseApp.Viewmodels; class ShellVM : ObservableObject { @@ -14,7 +14,7 @@ class ShellVM : ObservableObject public delegate void UpdateButtons(Button Button); - public UpdateButtons UpdateButtonsDelegate; + public UpdateButtons? UpdateButtonsDelegate; public ObservableCollection
Articles { get; set; } public AsyncCommand LoadPublicationDataCommand { get; set; } public AsyncCommand LoadArticleDataCommand { get; set; } @@ -27,10 +27,11 @@ class ShellVM : ObservableObject public ObservableCollection Filters = [ new("Latest", ""), - new("Headlines", "IMPACT > 70"), - new("Today", "DATE(Publish_Date) = CURDATE()"), - new("Business", "SECTORS NOT LIKE ''"), - new("Elections", "title LIKE '%election%'\r\nOR ARTICLE_TEXT LIKE '%election%'") + new("Headlines", "IMPACT > 70 AND DATE(Publish_Date) >= DATE_SUB(CURDATE(), INTERVAL 4 DAY)","ORDER BY IMPACT DESC"), + new("Today", "DATE(Publish_Date) = CURDATE()","ORDER BY IMPACT DESC"), + new("Business", "SECTORS NOT LIKE '' AND DATE(Publish_Date) = CURDATE()","ORDER BY IMPACT DESC"), + new("Elections", "title LIKE '%election%'\r\nOR ARTICLE_TEXT LIKE '%election%' " + + " AND DATE(Publish_Date) >= DATE_SUB(CURDATE(), INTERVAL 4 DAY)","ORDER BY IMPACT DESC") ]; //Access to the hallon API server @@ -97,19 +98,23 @@ public async Task LoadArticleData() public async Task LoadPublicationData() => await Hallon.GetPublications(); - public void OpenArticle(Article article) + public async void OpenArticle(Article article) { - //Open article in reader mode if always open reader is enabled - if (Glob.Model.AlwaysOpenReader) + switch (Glob.Model.OpenInMode) { - Glob.NaviStack.Push(new ReaderMode(article)); + case 0: //Open in Article WebView + Glob.DoNavi(new ArticleView(article)); + break; + case 1: //Open in reader mode + if (string.IsNullOrEmpty(article.Text)) + { + article.Text = await new API().GetArticleText(article.Url); + } + Glob.DoNavi(new ReaderMode(article)); + break; + case 2: //Open in Web Browser + Windows.System.Launcher.LaunchUriAsync(new Uri(article.Url)); + break; } - else - { - Glob.NaviStack.Push(new ArticleView(article)); - } - - //Navigate to view - Glob.DoNavi(); } } diff --git a/Firehose/Viewmodels/ThemeVM.cs b/Firehose/Viewmodels/ThemeVM.cs index ab133b2..9692573 100644 --- a/Firehose/Viewmodels/ThemeVM.cs +++ b/Firehose/Viewmodels/ThemeVM.cs @@ -2,7 +2,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.UI; -namespace Firehose.Viewmodels; +namespace FirehoseApp.Viewmodels; /// /// Controls application color and theming diff --git a/Hydrant/API.cs b/Hydrant/API.cs index 1fe96d0..88583d8 100644 --- a/Hydrant/API.cs +++ b/Hydrant/API.cs @@ -44,7 +44,7 @@ public API(string endpoint = "https://www.hallon.rarisma.net:5000") //Make request and check it was successful var response = await client.GetAsync(Endpoint + endpoint); - response.EnsureSuccessStatusCode(); + response.EnsureSuccessStatusCode(); //Deserialize JSON content var content = await response.Content.ReadAsStringAsync(); @@ -94,4 +94,16 @@ public async Task ReportArticle(Article Article) string url = $"{Endpoint}/Articles/ReportArticleSummary?ArticleURL={Uri.EscapeDataString(Article.Url)}"; await client.GetAsync(url); } + + /// + /// Gets article text + /// + /// Article to report + public async Task GetArticleText(string URL) + { + using HttpClient client = new(); + string url = $"{Endpoint}/Articles/GetArticleText?URL={Uri.EscapeDataString(URL)}"; + HttpResponseMessage Response = await client.GetAsync(url); + return await Response.Content.ReadAsStringAsync(); + } } diff --git a/Hydrant/SQL.cs b/Hydrant/SQL.cs index 397ece9..4458249 100644 --- a/Hydrant/SQL.cs +++ b/Hydrant/SQL.cs @@ -12,7 +12,7 @@ public class SQL /// /// MySQL Connection String /// - /// + /// SQL Connection String public SQL(string connectionString) { //Connect to the DB and open the connection @@ -84,7 +84,12 @@ public List
GetArticles(int Limit = 0, int Offset = 0, COMPANIES_MENTIONED, AUTHOR, SECTORS"; } - if (string.IsNullOrWhiteSpace(Filter) || Filter.Split(" ")[0] == "ORDER") { Filter = "WHERE UserGeneratedArticle = 0 " + Filter; } + if (string.IsNullOrWhiteSpace(Filter) || Filter.Split(" ")[0] == "ORDER") + { Filter = "WHERE UserGeneratedArticle = 0 " + Filter; } + else if (Filter.Contains("ORDER")) + { + Filter = Filter.Replace("ORDER", "AND UserGeneratedArticle = 0 ORDER"); + } else { Filter += " AND UserGeneratedArticle = 0"; } //Add common filtering stuff @@ -339,36 +344,36 @@ public void IncrementSummaryReportCounter(string URL) } } - public String GetArticleText(string URL) + /// + /// Gets article text for provided URL + /// + /// URL for article text + /// Article Text + public string GetArticleText(string URL) { try { - using (MySqlConnection connection = new(Connection)) + using MySqlConnection connection = new(Connection); + connection.Open(); + + using MySqlCommand cmd = new("SELECT ARTICLE_TEXT, PAYWALL FROM ARTICLES WHERE URL = @url", + connection); + cmd.Parameters.AddWithValue("@url", URL); + var r = cmd.ExecuteReader(); + string ArticleText = "Article Text Unavailable"; + while (r.Read()) { - connection.Open(); - - using (MySqlCommand cmd = new("SELECT ARTICLE_TEXT, PAYWALL FROM ARTICLES WHERE URL = @url", - connection)) + if (!bool.Parse(r["PAYWALL"].ToString() ?? "False")) { - cmd.Parameters.AddWithValue("@url", URL); - var r = cmd.ExecuteReader(); - string ArticleText = "Article Text Unavailable"; - while (r.Read()) - { - if (!bool.Parse(r["PAYWALL"].ToString() ?? "False")) - { - ArticleText = r["ARTICLE_TEXT"].ToString() ?? "Article Text Unavailable"; - } - else - { - ArticleText = "Article Text isn't available for this article"; - } - } - - return ArticleText; - + ArticleText = r["ARTICLE_TEXT"].ToString() ?? "Article Text Unavailable"; + } + else + { + ArticleText = "Article Text isn't available for this article"; } } + + return ArticleText; } catch (Exception e) {