From 11adfa6c7d0dfb7d08efe2a203e5f04d7abeea25 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Fri, 9 Apr 2021 21:07:03 -0400 Subject: [PATCH 1/5] added draft manager --- Dockerfile | 2 + src/BSLManager/BSLManager.csproj | 12 ++++ src/BSLManager/Program.cs | 119 +++++++++++++++++++++++++++++++ src/BirdsiteLive.sln | 8 ++- 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/BSLManager/BSLManager.csproj create mode 100644 src/BSLManager/Program.cs diff --git a/Dockerfile b/Dockerfile index 0dcccda..7239ca2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,12 @@ EXPOSE 443 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build COPY ./src/ ./src/ RUN dotnet restore "/src/BirdsiteLive/BirdsiteLive.csproj" +RUN dotnet restore "/src/BSLManager/BSLManager.csproj" RUN dotnet build "/src/BirdsiteLive/BirdsiteLive.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "/src/BirdsiteLive/BirdsiteLive.csproj" -c Release -o /app/publish +RUN dotnet publish "/src/BSLManager/BSLManager.csproj" -r linux-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true -c Release -o /app/publish FROM base AS final WORKDIR /app diff --git a/src/BSLManager/BSLManager.csproj b/src/BSLManager/BSLManager.csproj new file mode 100644 index 0000000..fafc29d --- /dev/null +++ b/src/BSLManager/BSLManager.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + + diff --git a/src/BSLManager/Program.cs b/src/BSLManager/Program.cs new file mode 100644 index 0000000..ff1a8bd --- /dev/null +++ b/src/BSLManager/Program.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; +using NStack; +using Terminal.Gui; + +namespace BSLManager +{ + class Program + { + static void Main(string[] args) + { + Console.OutputEncoding = Encoding.Default; + + Application.Init(); + var top = Application.Top; + + // Creates the top-level window to show + var win = new Window("BSL Manager") + { + X = 0, + Y = 1, // Leave one row for the toplevel menu + + // By using Dim.Fill(), it will automatically resize without manual intervention + Width = Dim.Fill(), + Height = Dim.Fill() + }; + + top.Add(win); + + // Creates a menubar, the item "New" has a help menu. + var menu = new MenuBar(new MenuBarItem[] { + new MenuBarItem ("_File", new MenuItem [] { + new MenuItem ("_Quit", "", () => { if (Quit ()) top.Running = false; }) + }), + //new MenuBarItem ("_Edit", new MenuItem [] { + // new MenuItem ("_Copy", "", null), + // new MenuItem ("C_ut", "", null), + // new MenuItem ("_Paste", "", null) + //}) + }); + top.Add(menu); + + static bool Quit() + { + var n = MessageBox.Query(50, 7, "Quit BSL Manager", "Are you sure you want to quit?", "Yes", "No"); + return n == 0; + } + + var listData = new List(); + for (var i = 0; i < 100; i++) + { + listData.Add($"@User{i}@Instance.tld {i*3}"); + } + + var list = new ListView(listData) + { + X = 1, + Y = 2, + Width = Dim.Fill(), + Height = Dim.Fill() + }; + + list.KeyDown += _ => + { + if (_.KeyEvent.Key == Key.Enter) + { + var el = list.SelectedItem; + + bool okpressed = false; + var ok = new Button(10, 14, "Yes"); + ok.Clicked += () => + { + Application.RequestStop(); + okpressed = true; + }; + + var cancel = new Button(3, 14, "No"); + cancel.Clicked += () => Application.RequestStop(); + + var dialog = new Dialog("Delete", 60, 18, cancel, ok); + + var name = new Label($"User: {listData[el]}") + { + X = 1, + Y = 1, + Width = Dim.Fill(), + Height = 1 + }; + var entry = new Label("Delete user and remove all their followings?") + { + X = 1, + Y = 3, + Width = Dim.Fill(), + Height = 1 + }; + dialog.Add(name); + dialog.Add(entry); + Application.Run(dialog); + + if (okpressed) + { + listData.RemoveAt(el); + typeof(Application).GetMethod("TerminalResized", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null); + } + } + }; + + // Add some controls, + win.Add( + new Label(1, 0, "Listing followers"), + list + ); + + Application.Run(); + } + } +} diff --git a/src/BirdsiteLive.sln b/src/BirdsiteLive.sln index 737b8b1..ba118c6 100644 --- a/src/BirdsiteLive.sln +++ b/src/BirdsiteLive.sln @@ -43,10 +43,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.DAL.Tests", "T EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.Moderation", "BirdsiteLive.Moderation\BirdsiteLive.Moderation.csproj", "{4BE541AC-8A93-4FA3-98AC-956CC2D5B748}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BirdsiteLive.Moderation.Tests", "Tests\BirdsiteLive.Moderation.Tests\BirdsiteLive.Moderation.Tests.csproj", "{0A311BF3-4FD9-4303-940A-A3778890561C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.Moderation.Tests", "Tests\BirdsiteLive.Moderation.Tests\BirdsiteLive.Moderation.Tests.csproj", "{0A311BF3-4FD9-4303-940A-A3778890561C}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirdsiteLive.Common.Tests", "Tests\BirdsiteLive.Common.Tests\BirdsiteLive.Common.Tests.csproj", "{C69F7582-6050-44DC-BAAB-7C8F0BDA525C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BSLManager", "BSLManager\BSLManager.csproj", "{4A84D351-E91B-4E58-8E20-211F0F4991D7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -125,6 +127,10 @@ Global {C69F7582-6050-44DC-BAAB-7C8F0BDA525C}.Debug|Any CPU.Build.0 = Debug|Any CPU {C69F7582-6050-44DC-BAAB-7C8F0BDA525C}.Release|Any CPU.ActiveCfg = Release|Any CPU {C69F7582-6050-44DC-BAAB-7C8F0BDA525C}.Release|Any CPU.Build.0 = Release|Any CPU + {4A84D351-E91B-4E58-8E20-211F0F4991D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A84D351-E91B-4E58-8E20-211F0F4991D7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A84D351-E91B-4E58-8E20-211F0F4991D7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A84D351-E91B-4E58-8E20-211F0F4991D7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From d0f817e1a8c83f571defe287554565bddd63e0e5 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Tue, 13 Apr 2021 01:25:36 -0400 Subject: [PATCH 2/5] fix url missing with some AP softwares --- .gitignore | 1 + src/BirdsiteLive.Domain/ActivityPubService.cs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 086c047..a6584fc 100644 --- a/.gitignore +++ b/.gitignore @@ -351,3 +351,4 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ +/src/BSLManager/Properties/launchSettings.json diff --git a/src/BirdsiteLive.Domain/ActivityPubService.cs b/src/BirdsiteLive.Domain/ActivityPubService.cs index fa3bf70..37fe0b5 100644 --- a/src/BirdsiteLive.Domain/ActivityPubService.cs +++ b/src/BirdsiteLive.Domain/ActivityPubService.cs @@ -46,7 +46,10 @@ namespace BirdsiteLive.Domain httpClient.DefaultRequestHeaders.Add("Accept", "application/activity+json"); var result = await httpClient.GetAsync(objectId); var content = await result.Content.ReadAsStringAsync(); - return JsonConvert.DeserializeObject(content); + + var actor = JsonConvert.DeserializeObject(content); + if (string.IsNullOrWhiteSpace(actor.url)) actor.url = objectId; + return actor; } public async Task PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox) From 32a4a6356b6e1094dbfff810831ba5a55be7c2be Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Tue, 13 Apr 2021 01:28:07 -0400 Subject: [PATCH 3/5] road to 0.16.2 --- src/BirdsiteLive/BirdsiteLive.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BirdsiteLive/BirdsiteLive.csproj b/src/BirdsiteLive/BirdsiteLive.csproj index 9daebca..dd17829 100644 --- a/src/BirdsiteLive/BirdsiteLive.csproj +++ b/src/BirdsiteLive/BirdsiteLive.csproj @@ -4,7 +4,7 @@ netcoreapp3.1 d21486de-a812-47eb-a419-05682bb68856 Linux - 0.16.1 + 0.16.2 From cad6c2018e97378363fd354e4e1565bf31caaf20 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Thu, 15 Apr 2021 19:39:33 -0400 Subject: [PATCH 4/5] fix warm up number --- .../Tools/MaxUsersNumberProvider.cs | 6 +++--- .../Tools/MaxUsersNumberProviderTests.cs | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/BirdsiteLive.Pipeline/Tools/MaxUsersNumberProvider.cs b/src/BirdsiteLive.Pipeline/Tools/MaxUsersNumberProvider.cs index c84b7b1..1c7e7c4 100644 --- a/src/BirdsiteLive.Pipeline/Tools/MaxUsersNumberProvider.cs +++ b/src/BirdsiteLive.Pipeline/Tools/MaxUsersNumberProvider.cs @@ -16,6 +16,7 @@ namespace BirdsiteLive.Pipeline.Tools private int _totalUsersCount = -1; private int _warmUpIterations; + private const int WarmUpMaxCapacity = 200; #region Ctor public MaxUsersNumberProvider(InstanceSettings instanceSettings, ITwitterUserDal twitterUserDal) @@ -31,8 +32,7 @@ namespace BirdsiteLive.Pipeline.Tools if (_totalUsersCount == -1) { _totalUsersCount = await _twitterUserDal.GetTwitterUsersCountAsync(); - var warmUpMaxCapacity = _instanceSettings.MaxUsersCapacity / 4; - _warmUpIterations = warmUpMaxCapacity == 0 ? 0 : (int)(_totalUsersCount / (float)warmUpMaxCapacity); + _warmUpIterations = (int)(_totalUsersCount / (float)WarmUpMaxCapacity); } // Return if warm up ended @@ -40,7 +40,7 @@ namespace BirdsiteLive.Pipeline.Tools // Calculate warm up value var maxUsers = _warmUpIterations > 0 - ? _instanceSettings.MaxUsersCapacity / 4 + ? WarmUpMaxCapacity : _instanceSettings.MaxUsersCapacity; _warmUpIterations--; return maxUsers; diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Tools/MaxUsersNumberProviderTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Tools/MaxUsersNumberProviderTests.cs index d48beb8..c2f52d0 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Tools/MaxUsersNumberProviderTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Tools/MaxUsersNumberProviderTests.cs @@ -30,17 +30,20 @@ namespace BirdsiteLive.Pipeline.Tests.Tools var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object); var result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(250, result); + Assert.AreEqual(200, result); result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(250, result); + Assert.AreEqual(200, result); result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(250, result); + Assert.AreEqual(200, result); result = await provider.GetMaxUsersNumberAsync(); - Assert.AreEqual(250, result); - + Assert.AreEqual(200, result); + + result = await provider.GetMaxUsersNumberAsync(); + Assert.AreEqual(200, result); + result = await provider.GetMaxUsersNumberAsync(); Assert.AreEqual(1000, result); @@ -63,7 +66,7 @@ namespace BirdsiteLive.Pipeline.Tests.Tools var twitterUserDalMock = new Mock(MockBehavior.Strict); twitterUserDalMock .Setup(x => x.GetTwitterUsersCountAsync()) - .ReturnsAsync(249); + .ReturnsAsync(199); #endregion var provider = new MaxUsersNumberProvider(settings, twitterUserDalMock.Object); From 77f4b49d9ac69831cc3f98c9a0d5a4d689e608ee Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Thu, 15 Apr 2021 20:40:27 -0400 Subject: [PATCH 5/5] increasing user limit --- src/BirdsiteLive/appsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BirdsiteLive/appsettings.json b/src/BirdsiteLive/appsettings.json index e25c7ca..8b12018 100644 --- a/src/BirdsiteLive/appsettings.json +++ b/src/BirdsiteLive/appsettings.json @@ -20,7 +20,7 @@ "AdminEmail": "me@domain.name", "ResolveMentionsInProfiles": true, "PublishReplies": false, - "MaxUsersCapacity": 800, + "MaxUsersCapacity": 1500, "UnlistedTwitterAccounts": null }, "Db": {