Skip to content

Commit

Permalink
feat(plugins/duplicatiplugin): parsedResult 区分 Success,Warning,Fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyungent committed Jan 19, 2024
1 parent 98b0b67 commit 5cb5d83
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 19 deletions.
29 changes: 23 additions & 6 deletions plugins/DuplicatiPlugin/Controllers/SendController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -64,19 +64,36 @@ await botClient.SendTextMessageAsync(
if (settings.Telegram != null && settings.Telegram.Enable)
{
var botClient = new TelegramBotClient(settings.Telegram.BotToken);
string badge = "🔴";
switch (jsonModel.ParsedResult)
string badge = string.Empty;
string badgeStr = string.Empty;
string extraInfo = string.Empty;
switch (jsonModel.ParsedResult.Trim())
{
case "Success":
badge = "✅";
badgeStr = "Success";
break;
default:
case "Warning":
badge = "⚠️";
badgeStr = "Warning";
extraInfo = duplicatiStr;
break;
case "Fatal":
badge = "🔴";
badgeStr = "Fatal";
extraInfo = duplicatiStr;
break;
default:
badge = "❓";
badgeStr = jsonModel.ParsedResult.Trim();
extraInfo = duplicatiStr;
break;
}
string temp = $"Duplicati: {jsonModel.OperationName} \r\n"
+ $"{jsonModel.BackupName} \r\n"
+ $"{badge}";
+ $"{badge} {badgeStr}";
temp += string.IsNullOrEmpty(extraInfo) ? string.Empty : $"\r\n{extraInfo}";

// 发送
await botClient.SendTextMessageAsync(
chatId: settings.Telegram.ChatId,
Expand All @@ -89,7 +106,7 @@ await botClient.SendTextMessageAsync(
Utils.LogUtil.Exception(ex);

return Ok("fail");
}
}
#endregion

#region 保存数据库, key 做来源区分
Expand Down
38 changes: 29 additions & 9 deletions plugins/DuplicatiPlugin/DuplicatiPlugin.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>PluginCore.Plugins.DuplicatiPlugin</PackageId>
<Version>0.2.2</Version>
<FileVersion>0.2.2.0</FileVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Company>yiyun</Company>
<Authors>yiyun</Authors>
<Description>PluginCore Plugin: DuplicatiPlugin</Description>
<Copyright>Copyright (c) 2023-present yiyun</Copyright>
<RepositoryUrl>https://github.com/yiyungent/KnifeHub</RepositoryUrl>
<PackageLicenseUrl>https://github.com/yiyungent/KnifeHub/blob/main/LICENSE</PackageLicenseUrl>
<PackageTags>PluginCore PluginCore.Plugins</PackageTags>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0">
<!--<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
</PackageReference>-->
<FrameworkReference Include="Microsoft.AspNetCore.App">
<ExcludeAssets>runtime</ExcludeAssets>
</FrameworkReference>
<PackageReference Include="PluginCore.IPlugins.AspNetCore" Version="0.1.1">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<!--<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>-->
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
<PackageReference Include="PluginCore.IPlugins.AspNetCore" Version="0.0.1">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
</ItemGroup>

Expand Down
7 changes: 6 additions & 1 deletion plugins/DuplicatiPlugin/Models/DuplicatiMessageModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -17,6 +17,11 @@ public class DuplicatiMessageModel

public string BackupName { get; set; }

/// <summary>
/// Success
/// Warning
/// Fatal
/// </summary>
public string ParsedResult { get; set; }

public string LocalPath { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions plugins/DuplicatiPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
--send-http-url=替换为你的链接
```

### 2. 方式2: 全局设置 Duplicati
### 2. 方式2: 全局设置 Duplicati (推荐)

- [右键复制本链接, 然后再替换其中内容](/api/Duplicati/replace-your-key/apply)

Expand Down Expand Up @@ -66,5 +66,5 @@
> 本项目基于 [TelegramBots/Telegram.Bot: .NET Client for Telegram Bot API](https://github.com/TelegramBots/Telegram.Bot)
<!-- Matomo Image Tracker-->
<img referrerpolicy="no-referrer-when-downgrade" src="https://matomo.moeci.com/matomo.php?idsite=2&amp;rec=1&amp;action_name=Plugins.DuplicatiPlugin-v0.2.1.README" style="border:0" alt="" />
<img referrerpolicy="no-referrer-when-downgrade" src="https://matomo.moeci.com/matomo.php?idsite=2&amp;rec=1&amp;action_name=PluginCore.Plugins..DuplicatiPlugin-v0.2.2.README" style="border:0" alt="" />
<!-- End Matomo -->
2 changes: 1 addition & 1 deletion plugins/DuplicatiPlugin/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"DisplayName": "Duplicati插件",
"Description": "Duplicati插件",
"Author": "yiyun",
"Version": "0.2.1",
"Version": "0.2.2",
"SupportedVersions": [ "0.0.1" ]
}

0 comments on commit 5cb5d83

Please sign in to comment.