Skip to content

Commit

Permalink
feat(plugins/webmonitorplugin/): 初步迁移
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyungent committed Jan 21, 2023
1 parent 40e28a4 commit a957b48
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 17 deletions.
7 changes: 7 additions & 0 deletions KnifeHub.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramPlugin", "plugins\T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DuplicatiPlugin", "plugins\DuplicatiPlugin\DuplicatiPlugin.csproj", "{81F72AD3-CE49-4886-B18F-443D491A6DB0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebMonitorPlugin", "plugins\WebMonitorPlugin\WebMonitorPlugin.csproj", "{F10458CE-D27C-41D7-A400-A81007347A93}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -153,6 +155,10 @@ Global
{81F72AD3-CE49-4886-B18F-443D491A6DB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81F72AD3-CE49-4886-B18F-443D491A6DB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81F72AD3-CE49-4886-B18F-443D491A6DB0}.Release|Any CPU.Build.0 = Release|Any CPU
{F10458CE-D27C-41D7-A400-A81007347A93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F10458CE-D27C-41D7-A400-A81007347A93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F10458CE-D27C-41D7-A400-A81007347A93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F10458CE-D27C-41D7-A400-A81007347A93}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -180,6 +186,7 @@ Global
{7CDB5D18-8946-4DF5-9ACB-24AC5F9A5906} = {4B4BFBBE-8CE4-453C-B05A-EAFE933B79C9}
{8185E32D-32D9-462D-995F-C4522E636B86} = {4B4BFBBE-8CE4-453C-B05A-EAFE933B79C9}
{81F72AD3-CE49-4886-B18F-443D491A6DB0} = {4B4BFBBE-8CE4-453C-B05A-EAFE933B79C9}
{F10458CE-D27C-41D7-A400-A81007347A93} = {4B4BFBBE-8CE4-453C-B05A-EAFE933B79C9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3F1D77E3-11F8-4B5B-BEED-EE2816D57A86}
Expand Down
2 changes: 1 addition & 1 deletion plugins/WebMonitorPlugin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace WebMonitorPlugin.Controllers
{
[ApiController]
[Authorize("PluginCoreAdmin")]
[Authorize("PluginCore.Admin")]
[Route($"plugins/{nameof(WebMonitorPlugin)}")]
public class HomeController : ControllerBase
{
Expand Down
13 changes: 13 additions & 0 deletions plugins/WebMonitorPlugin/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

# 介绍

> **注意**: **启用本插件较慢** , 请耐心等待提示 `启用成功` , 若出错, 禁用再启用即可
> **注意** : 本插件需要浏览器环境, 如: 此 Docker 镜像 `yiyungent/knifehub:latest-amd-chrome` 中就打包好了浏览器环境
# 基础

Expand All @@ -8,6 +13,14 @@
- [设置](/plugincore/admin/index.html#/plugins/settings/WebMonitorPlugin) 里配置提醒通知


# 插件设置

`SecondsPeriod` : 一般保持默认 60 秒的监控频率, 当然若服务器压力大, 可以调高

`Selenium.ChromeDriverDirectory` : "" 一般保持为默认空字符串即可, 即使用 当前主程序所在目录 (/app/), 即使用 `yiyungent/knifehub:v1.0.5-amd-chrome` 等镜像 保持默认空字符串即可

`CommandTimeoutMinute.CommandTimeoutMinute` : 一般保持默认 5 分钟即可


# 通知

Expand Down
9 changes: 8 additions & 1 deletion plugins/WebMonitorPlugin/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public class SettingsModel : PluginSettingsModel

public TelegramModel Telegram { get; set; }

public SeleniumModel Selenium { get; set; }

public class TelegramModel
{
public string Token { get; set; }
public string ChatId { get; set; }

public bool Enable { get; set; }
public bool Enable { get; set; }

}

Expand All @@ -36,6 +38,11 @@ public class MailModel

}

public class SeleniumModel
{
public string ChromeDriverDirectory { get; set; }

public long CommandTimeoutMinute { get; set; }
}
}
}
12 changes: 11 additions & 1 deletion plugins/WebMonitorPlugin/WebMonitorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,17 @@ public void ExecuteTask(SettingsModel settings, TaskModel task)
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--disable-gpu");

var driver = new ChromeDriver(chromeDriverDirectory: Environment.CurrentDirectory, options, commandTimeout: TimeSpan.FromMinutes(5));
string chromeDriverDirectory = Environment.CurrentDirectory;
long commandTimeoutMinute = 5;
if (settings.Selenium != null && settings.Selenium.CommandTimeoutMinute > 0)
{
commandTimeoutMinute = settings.Selenium.CommandTimeoutMinute;
}
if (!string.IsNullOrEmpty(settings.Selenium?.ChromeDriverDirectory))
{
chromeDriverDirectory = settings.Selenium.ChromeDriverDirectory;
}
var driver = new ChromeDriver(chromeDriverDirectory: chromeDriverDirectory, options, commandTimeout: TimeSpan.FromMinutes(commandTimeoutMinute));
#endregion

try
Expand Down
20 changes: 14 additions & 6 deletions plugins/WebMonitorPlugin/WebMonitorPlugin.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dragonfly.Sdk" Version="0.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="PluginCore.IPlugins.AspNetCore" Version="0.0.1">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Telegram.Bot" Version="17.0.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
</ItemGroup>

<!-- 发布插件相关文件 -->
Expand All @@ -25,6 +30,9 @@
<Content Include="settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="WebMonitorPlugin.sqlite">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<!-- 发布 wwwroot -->
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions plugins/WebMonitorPlugin/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"DisplayName": "网页监控",
"Description": "网页监控,看文档",
"Author": "yiyun",
"Version": "0.3.1",
"SupportedVersions": [ "0.1.2" ]
"Version": "0.4.1",
"SupportedVersions": [ "0.0.1" ]
}
16 changes: 10 additions & 6 deletions plugins/WebMonitorPlugin/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"SecondsPeriod": 60,
"Telegram": {
"Token": "",
"ChatId": "",
"Enable": false
}
"SecondsPeriod": 60,
"Telegram": {
"Token": "",
"ChatId": "",
"Enable": false
},
"Selenium": {
"ChromeDriverDirectory": "",
"CommandTimeoutMinute": 5
}
}

0 comments on commit a957b48

Please sign in to comment.