|
@@ -7,10 +7,10 @@ using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Reflection;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Net;
|
|
|
+using System.Security.Cryptography;
|
|
|
using HyperCube.Models;
|
|
|
using Console = HyperCube.Utils.AdvConsole;
|
|
|
-using System.Net;
|
|
|
-
|
|
|
|
|
|
namespace HyperCube.Pages
|
|
|
{
|
|
@@ -35,6 +35,8 @@ namespace HyperCube.Pages
|
|
|
string fullName { get { return FOLDER_NAME + "/" + articleModel.FilenameReal; } }
|
|
|
int editsCount;
|
|
|
|
|
|
+ bool IsSubmitDisabled = false;
|
|
|
+
|
|
|
async Task<string> Verify()
|
|
|
{
|
|
|
Console.WriteLine($"Verify starting");
|
|
@@ -82,7 +84,6 @@ namespace HyperCube.Pages
|
|
|
string initiator = await articleModel.GetInitiatorUUID();
|
|
|
initiatorAcc = AccountModel.Find(initiator);
|
|
|
status = $"Article ID={docID} loaded, status: {articleModel.Status}, initiator: {initiatorAcc.Name}";
|
|
|
-
|
|
|
}
|
|
|
else
|
|
|
header = "Загрузка материала";
|
|
@@ -102,16 +103,14 @@ namespace HyperCube.Pages
|
|
|
var response = await wrGETURL.GetResponseAsync();
|
|
|
Stream dataStream = response.GetResponseStream();
|
|
|
|
|
|
- StreamReader reader = new StreamReader(dataStream);
|
|
|
-
|
|
|
- string rt = reader.ReadToEnd();
|
|
|
- return rt;
|
|
|
+ StreamReader reader = new(dataStream);
|
|
|
+ return reader.ReadToEnd();
|
|
|
}
|
|
|
|
|
|
private async Task HandleValidSubmit()
|
|
|
{
|
|
|
MySQLConnector dbCon = MySQLConnector.Instance();
|
|
|
- long id = 0;
|
|
|
+ long id;
|
|
|
string stringSQL;
|
|
|
|
|
|
Console.WriteLine($"HandleValidSubmit, docID: {docID}");
|
|
@@ -121,16 +120,16 @@ namespace HyperCube.Pages
|
|
|
id = docID;
|
|
|
stringSQL = $"UPDATE articles " +
|
|
|
$"SET filename='{articleModel.Filename}', article_name='{articleModel.Name}', authors='{articleModel.Authors}', " +
|
|
|
- $"date_publish='{articleModel.PublishDate.ToString("yyyy-MM-dd")}', annotation='{articleModel.Annotation}', " +
|
|
|
- $"keywords='{articleModel.Keywords}', rating={articleModel.Rating} " +
|
|
|
+ $"date_publish='{articleModel.PublishDate:yyyy-MM-dd}', annotation='{articleModel.Annotation}', " +
|
|
|
+ $"keywords='{articleModel.Keywords}', rating={articleModel.Rating}, file_hash={articleModel.FileHashSum} " +
|
|
|
$"WHERE id={docID}";
|
|
|
await dbCon.SQLInsert(stringSQL);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- stringSQL = $"INSERT INTO articles (filename, article_name, authors, date_publish, annotation, keywords) " +
|
|
|
- $"VALUES ('{articleModel.Filename}', '{articleModel.Name}', '{articleModel.Authors}', '{articleModel.PublishDate.ToString("yyyy-MM-dd")}'," +
|
|
|
- $"'{articleModel.Annotation}', '{articleModel.Keywords}')";
|
|
|
+ stringSQL = $"INSERT INTO articles (filename, article_name, authors, date_publish, annotation, keywords, file_hash) " +
|
|
|
+ $"VALUES ('{articleModel.Filename}', '{articleModel.Name}', '{articleModel.Authors}', '{articleModel.PublishDate:yyyy-MM-dd}'," +
|
|
|
+ $"'{articleModel.Annotation}', '{articleModel.Keywords}', '{articleModel.FileHashSum}')";
|
|
|
id = await dbCon.SQLInsert(stringSQL);
|
|
|
NewProjectSmopp(id);
|
|
|
}
|
|
@@ -198,11 +197,35 @@ namespace HyperCube.Pages
|
|
|
memoryStream = new();
|
|
|
await stream.CopyToAsync(memoryStream);
|
|
|
status = $"Finished loading {memoryStream.Length} bytes from {file.Name}";
|
|
|
+ Console.WriteLine(status);
|
|
|
|
|
|
- DocParse docParse = new DocParse();
|
|
|
- articleModelClone = DocParse.ReadPDF(memoryStream);
|
|
|
- articleModelClone.Filename = file.Name;
|
|
|
- articleModel = (ArticleModel)articleModelClone.Clone();
|
|
|
+ /// calculating hash
|
|
|
+ string hash = await CalculateHashSum(memoryStream);
|
|
|
+ Console.WriteLine($"Hash: {hash}");
|
|
|
+
|
|
|
+ /// checking hash
|
|
|
+ MySQLConnector dbCon = MySQLConnector.Instance();
|
|
|
+ string stringSQL;
|
|
|
+ stringSQL = $"SELECT COUNT(*) FROM articles WHERE file_hash='{hash}'";
|
|
|
+ int count = await dbCon.SQLSelectCount(stringSQL);
|
|
|
+ //Console.WriteLine($"File duplicate check, founded files: {count}");
|
|
|
+
|
|
|
+ if (count < 1)
|
|
|
+ {
|
|
|
+ articleModelClone = DocParse.ReadPDF(memoryStream);
|
|
|
+ articleModelClone.Filename = file.Name;
|
|
|
+ articleModelClone.FileHashSum = hash;
|
|
|
+ articleModel = (ArticleModel)articleModelClone.Clone();
|
|
|
+
|
|
|
+ IsSubmitDisabled = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ status = $"File duplicate founded, hash: {hash}.";
|
|
|
+ Console.WriteLine(status);
|
|
|
+
|
|
|
+ IsSubmitDisabled = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -247,5 +270,13 @@ namespace HyperCube.Pages
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ private async Task<string> CalculateHashSum(MemoryStream ms)
|
|
|
+ {
|
|
|
+ MD5CryptoServiceProvider md5Provider = new();
|
|
|
+ ms.Position = 0;
|
|
|
+ byte[] hash = await md5Provider.ComputeHashAsync(ms);
|
|
|
+ return Convert.ToBase64String(hash);
|
|
|
+ }
|
|
|
}
|
|
|
}
|