Skip to content

Commit

Permalink
Remove reader role (#29)
Browse files Browse the repository at this point in the history
* Remove reader role
* Move email.config to appsettings
* Update README
  • Loading branch information
vov4uk authored Jun 29, 2024
1 parent fdf6ff0 commit d63972d
Show file tree
Hide file tree
Showing 44 changed files with 327 additions and 297 deletions.
Binary file modified HikConsole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 51 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
| What | Badge|
| ---- | ---- |
| Build | [![Build Status](https://dev.azure.com/khmelovskyi/HikConsole/_apis/build/status/vov4uk.HikConsole?branchName=master)](https://dev.azure.com/khmelovskyi/HikConsole/_build/latest?definitionId=1&branchName=master)|
| Latest | [![GitHub (pre-)release](https://img.shields.io/github/v/release/vov4uk/HikConsole?include_prereleases)](https://github.com/vov4uk/HikConsole/releases)|
| Total| [![Github Releases](https://img.shields.io/github/downloads/vov4uk/HikConsole/total)](https://github.com/vov4uk/HikConsole/releases)|
| Sonar | [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=vov4uk_HikConsole&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=vov4uk_HikConsole)|

# Hik.Client
* HikPhotoClient - Download photo files from Hikvision IP cameras.
* HikVideoClient - Download video files from Hikvision IP cameras.
* YiClient - Download files from Xiaomi YI cameras. Connect to camera over FTP, and download files.
* RSyncClient - Download and delete files from FTP server

# HikWeb
* Download photo/video files from Hikvision IP cameras.
<h1 align="center">Hik Web</h1>
<p align="center">
<a href="https://github.com/vov4uk/HikConsole/releases">
<img alt="GitHub (pre-)release" src="https://img.shields.io/github/v/release/vov4uk/HikConsole?include_prereleases"/>
</a>
<a href="https://github.com/vov4uk/HikConsole/releases">
<img alt="GitHub release" src="https://img.shields.io/github/downloads/vov4uk/HikConsole/total"/>
</a>
</p>


## Key features
* Download photo/video files from Hikvision & Dahua IP cameras.
* Download files from FTP/Yi camera
* Migrate files from one folder to another. Move and rename.
* Remove old files if low of space.
Expand All @@ -22,4 +20,42 @@
* Simple search and video playback (h264 supported)
* Job execution based on cron string.

## Implemented Job Types
* PhotoDownloaderJob
* Only HikVision IP cameras supported
* VideoDownloaderJob
* HikVision IP Camera
* Dahua IP Camera
* FTP Server (YI Home camera with [custom firmware](https://github.com/TheCrypt0/yi-hack-v4))
* FilesCollectorJob
* Move files from one folder to another
* GarbageCollectorJob
* Remove files older than n days
* Remove oldest files if less than n% of free space
________________________________________________________________________

* Download Hik.Web_xxx.zip [latets releases](https://github.com/vov4uk/HikConsole/releases/latest)
* Unzip Hik.Web_xxx.zip to Hik.Web folder
* Start from command line
```
cd Hik.Web
Hik.Web.exe --console
```
* Go to [http://localhost:50001](http://localhost:50001)

* Start as windows server -> [click here](https://github.com/vov4uk/HikConsole/blob/master/src/Hik.Web/Build/install.bat)

![Alt text](HikConsole.png?raw=true "Output example")


________________________________________________________________________
### Basic authentication implemented
* You need rebuild Hik.Web with folowing command:
* ``` dotnet build --configuration Release /p:Platform=x64 /p:DefineConstants=USE_AUTHORIZATION C:\HikWeb\Hik.sln```
* After start go to [https://localhost:50001](https://localhost:50001)
* Enter credentials: admin \ admin

### Logging options
* [SEQ](https://datalust.co/seq)
* Text file
* Console
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ public void Handle_Should_Start_Activity()
// Mocking the GetSection method to return a test configuration
var mockSection = new Mock<IConfigurationSection>();
mockSection.SetupGet(x => x.Value).Returns("{\r\n \"ConnectionString\": \"Filename=C:\\\\Code\\\\HikDatabase1.db;Pooling=True;\",\r\n \"CommandTimeout\": 30\r\n }");
var emailSection = new Mock<IConfigurationSection>();
emailSection.SetupGet(x => x.Value).Returns(@"{
""UserName"": ""email@yahoo.com"",
""Password"": ""pass"",
""Server"": ""smtp.mail.yahoo.com"",
""Port"": 587,
""Receiver"": ""email@outlook.com""
},");
mockConfiguration.Setup(x => x.GetSection("DBConfiguration")).Returns(mockSection.Object);
mockConfiguration.Setup(x => x.GetSection("EmailConfig")).Returns(emailSection.Object);

// Act
var task = handler.Handle(command, CancellationToken.None);
Expand Down
4 changes: 2 additions & 2 deletions Tests/Hik.Web.Tests/Pages/IndexModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void OnPostKill_ActivityNotFound(string activityId)
[AutoData]
public void OnPostKill_ActivityFound(string group, string name)
{
RunningActivities.Add(new Activity(new Parameters(group, name, ""), null, null));
RunningActivities.Add(new Activity(new Parameters(group, name, ""), null, null, null));

var sut = new IndexModel(this._mediator.Object);
var result = sut.OnPostKill($"{group}.{name}");
Expand All @@ -71,7 +71,7 @@ public void OnPostKill_ActivityFound(string group, string name)
[AutoData]
public async Task OnGet_ReturnJobs(string msg)
{
RunningActivities.Add(new Activity(new Parameters(group, name, ""), null, null));
RunningActivities.Add(new Activity(new Parameters(group, name, ""), null, null, null));
this._mediator.Setup(x => x.Send(It.IsAny<QuartzTriggersQuery>(), default(CancellationToken)))
.ReturnsAsync(new QuartzTriggersDto
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Hik.Web.Tests/Pages/SchedulerModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task OnPostRestartAsync_Redirect()
[AutoData]
public void OnPostKill_Redirect(string group, string name)
{
RunningActivities.Add(new Activity(new Parameters(group, name, ""), null, null));
RunningActivities.Add(new Activity(new Parameters(group, name, ""), null, null, null));

Assert.NotEmpty(RunningActivities.GetEnumerator());

Expand Down
2 changes: 1 addition & 1 deletion Tests/Hik.Web.Tests/Pages/TriggerModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public async Task OnPostAsync_CreateNewTrigger_RedirectToConfigPage(string class

[Theory]
[InlineData("GarbageCollectorJob", "{\r\n \"RetentionPeriodDays\": -1,\r\n \"FreeSpacePercentage\": 0.0,\r\n \"Triggers\": [],\r\n \"FileExtention\": null,\r\n \"JobTimeoutMinutes\": 29,\r\n \"DestinationFolder\": null\r\n}")]
[InlineData("FilesCollectorJob", "{\r\n \"SourceFolder\": null,\r\n \"AbnormalFilesCount\": 0,\r\n \"FileNamePattern\": null,\r\n \"FileNameDateTimeFormat\": null,\r\n \"SkipLast\": 0,\r\n \"AllowedFileExtentions\": \"*.*;\",\r\n \"JobTimeoutMinutes\": 29,\r\n \"DestinationFolder\": null\r\n}")]
[InlineData("FilesCollectorJob", "{\r\n \"SourceFolder\": null,\r\n \"AbnormalFilesCount\": 0,\r\n \"FileNamePattern\": null,\r\n \"FileNameDateTimeFormat\": null,\r\n \"SkipLast\": 0,\r\n \"AllowedFileExtentions\": \".jpg;\",\r\n \"JobTimeoutMinutes\": 29,\r\n \"DestinationFolder\": null\r\n}")]
[InlineData("VideoDownloaderJob", "{\r\n \"ProcessingPeriodHours\": 0,\r\n \"Camera\": null,\r\n \"ClientType\": 0,\r\n \"SyncTime\": true,\r\n \"SyncTimeDeltaSeconds\": 5,\r\n \"RemotePath\": null,\r\n \"SaveFilesToRootFolder\": false,\r\n \"JobTimeoutMinutes\": 29,\r\n \"DestinationFolder\": null\r\n}")]
[InlineData("PhotoDownloaderJob", "{\r\n \"ProcessingPeriodHours\": 0,\r\n \"Camera\": null,\r\n \"ClientType\": 0,\r\n \"SyncTime\": true,\r\n \"SyncTimeDeltaSeconds\": 5,\r\n \"RemotePath\": null,\r\n \"SaveFilesToRootFolder\": false,\r\n \"JobTimeoutMinutes\": 29,\r\n \"DestinationFolder\": null\r\n}")]
public void OnGetConfigJson_ClassNameExist_ReturnConfig(string className, string expexted)
Expand Down
3 changes: 1 addition & 2 deletions Tests/Job.Tests/Impl/FilesCollectorJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Hik.DTO.Contracts;
using Job.Impl;
using Moq;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -27,7 +26,7 @@ public void Constructor_ConfigNotExist_Exception()
[Fact]
public void Constructor_InvalidConfig_Exception()
{
Assert.Throws<JsonReaderException>(() => CreateJob("ArchiveJobTestsInvalid.json"));
Assert.Throws<NullReferenceException>(() => CreateJob("ArchiveJobTestsInvalid.json"));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Tests/Job.Tests/Impl/JobBaseTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Hik.DataAccess.Abstractions;
using Hik.DataAccess.Data;
using Hik.DTO.Contracts;
using Job.Email;
using Serilog;
using Moq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Xunit.Abstractions;
using Hik.Helpers.Email;

namespace Job.Tests.Impl
{
Expand Down
2 changes: 1 addition & 1 deletion src/Hik.Client/Service/VideoDownloaderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private async Task<bool> DownloadRemoteVideoFileAsync(MediaFileDto file, Cancell
file.DownloadDuration = duration;

int? videoDuration = file.Duration;
logger.Information($"{file.ToVideoUserFriendlyString()} - downloaded in {duration.FormatSeconds()}, avg speed {((long)Utils.SafeDivision(file.Size, duration.Value)).FormatBytes()}/s, avg rate {((long)Utils.SafeDivision(file.Size, videoDuration.Value)).FormatBytes()}/s");
logger.Information($"{file.ToVideoUserFriendlyString()} - downloaded in {duration.FormatMilliseconds()}, avg speed {((long)Utils.SafeDivision(file.Size, duration.Value / 1000m)).FormatBytes()}/s, avg rate {((long)Utils.SafeDivision(file.Size, videoDuration.Value)).FormatBytes()}/s");
}

return downloaded;
Expand Down
2 changes: 1 addition & 1 deletion src/Hik.DTO/Config/FilesCollectorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FilesCollectorConfig : BaseConfig
public int SkipLast { get; set; } = 0;

[Display(Name = "Allowed file extentions")]
public string AllowedFileExtentions { get; set; } = "*.*;";
public string AllowedFileExtentions { get; set; } = ".jpg;";
}

public class FilesConfigValidator : AbstractValidator<FilesCollectorConfig>
Expand Down
Loading

0 comments on commit d63972d

Please sign in to comment.