|
|
|
@ -5,6 +5,9 @@ using Infrastructure.CloudSdk;
|
|
|
|
|
using Infrastructure.CloudSdk.minio;
|
|
|
|
|
using Infrastructure.CloudSdk.wayline;
|
|
|
|
|
using Infrastructure.Extensions;
|
|
|
|
|
using Irony.Parsing.Construction;
|
|
|
|
|
using MetadataExtractor;
|
|
|
|
|
using MetadataExtractor.Formats.Exif;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using MQTTnet.Client;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
@ -250,7 +253,9 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
FlightId = flightId,
|
|
|
|
|
TaskId = taskId,
|
|
|
|
|
ParentKey = "0",
|
|
|
|
|
Name = string.IsNullOrEmpty(executeTask.TaskName) ? timeStr : $"{executeTask.TaskName} {timeStr}",
|
|
|
|
|
Name = string.IsNullOrEmpty(executeTask.TaskName)
|
|
|
|
|
? timeStr
|
|
|
|
|
: $"{executeTask.TaskName} {timeStr}",
|
|
|
|
|
WorkspaceId = executeTask.WorkspaceId,
|
|
|
|
|
CreateTime = date,
|
|
|
|
|
};
|
|
|
|
@ -264,8 +269,111 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
.Where(a => a.ObjectKey.Equals(objectKey)).SingleAsync();
|
|
|
|
|
if (mediaFile == null)
|
|
|
|
|
{
|
|
|
|
|
string objectKey1 = data.file.object_key.ToString();
|
|
|
|
|
string suoluokey = "minipic/" + data.file.name.ToString();
|
|
|
|
|
long? picSize = 0;
|
|
|
|
|
int width = 0, height = 0, focalLength = 0;
|
|
|
|
|
int offset = 0, length = 0;
|
|
|
|
|
var fileUrl ="http://" + _minioService.endPoint + "/" + _minioService._bucketName + "/" + objectKey;
|
|
|
|
|
using (var httpClient = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
// 目前读取64KB
|
|
|
|
|
// 添加Range请求头
|
|
|
|
|
httpClient.DefaultRequestHeaders.Range =
|
|
|
|
|
new System.Net.Http.Headers.RangeHeaderValue(0, 65535);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var response = httpClient
|
|
|
|
|
.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead).Result;
|
|
|
|
|
if (response.StatusCode == System.Net.HttpStatusCode.PartialContent)
|
|
|
|
|
{
|
|
|
|
|
//Focal Length 35: 24 mm
|
|
|
|
|
//Exif Image Width: 4032 pixels : Exif SubIFD
|
|
|
|
|
//Exif Image Height: 3024 pixels : Exif SubIFD
|
|
|
|
|
// 3.1 解析Content-Range头(格式:bytes start-end/total)
|
|
|
|
|
var contentRange = response.Content.Headers.ContentRange;
|
|
|
|
|
if (contentRange != null)
|
|
|
|
|
{
|
|
|
|
|
picSize = contentRange.Length.Value;
|
|
|
|
|
Console.WriteLine(
|
|
|
|
|
$"获取范围:{contentRange.From}-{contentRange.To}/{contentRange.Length}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 成功获取部分内容
|
|
|
|
|
var y = response.Content.ReadAsByteArrayAsync().Result;
|
|
|
|
|
MemoryStream ms = new MemoryStream(y);
|
|
|
|
|
var directories = ImageMetadataReader.ReadMetadata(ms);
|
|
|
|
|
foreach (var directory in directories)
|
|
|
|
|
{
|
|
|
|
|
if (directory is ExifDirectoryBase)
|
|
|
|
|
{
|
|
|
|
|
if (directory.Name.Equals("Exif SubIFD"))
|
|
|
|
|
{
|
|
|
|
|
foreach (var tag in directory.Tags)
|
|
|
|
|
{
|
|
|
|
|
if (tag.Name.Equals("Exif Image Width"))
|
|
|
|
|
{
|
|
|
|
|
width = int.Parse(tag.Description.Replace("pixels", "")
|
|
|
|
|
.Trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tag.Name.Equals("Exif Image Height"))
|
|
|
|
|
{
|
|
|
|
|
height = int.Parse(tag.Description.Replace("pixels", "")
|
|
|
|
|
.Trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tag.Name.Equals("Focal Length 35"))
|
|
|
|
|
{
|
|
|
|
|
focalLength = int.Parse(tag.Description.Replace("mm", "")
|
|
|
|
|
.Trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Console.WriteLine(directory.Name);
|
|
|
|
|
if (directory.Name.Equals("Exif Thumbnail"))
|
|
|
|
|
{
|
|
|
|
|
foreach (var tag in directory.Tags)
|
|
|
|
|
{
|
|
|
|
|
if (tag.Name.Equals("Thumbnail Offset"))
|
|
|
|
|
{
|
|
|
|
|
offset = int.Parse(tag.Description.Replace("bytes", "")
|
|
|
|
|
.Trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tag.Name.Equals("Thumbnail Length"))
|
|
|
|
|
{
|
|
|
|
|
length = int.Parse(tag.Description.Replace("bytes", "")
|
|
|
|
|
.Trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ms.Seek(offset + 6, SeekOrigin.Begin);
|
|
|
|
|
byte[] buffer = new byte[length];
|
|
|
|
|
int bytesRead = ms.Read(buffer, 0, length);
|
|
|
|
|
// 上传缩略图到MinIO
|
|
|
|
|
await _minioService.PutObjectAsync("", data.file.name.ToString(), suoluokey,
|
|
|
|
|
new MemoryStream(buffer));
|
|
|
|
|
}
|
|
|
|
|
else if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
|
|
{
|
|
|
|
|
// 服务器不支持Range请求,返回完整内容
|
|
|
|
|
throw new InvalidOperationException("服务器不支持Range请求");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new HttpRequestException($"请求失败: {response.StatusCode}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"下载Range数据失败: {ex.Message}", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*string objectKey1 = data.file.object_key.ToString();
|
|
|
|
|
//缩略图处理
|
|
|
|
|
var imageStream = _minioService.GetObjectAsStream("", objectKey1);
|
|
|
|
|
var width = 0;
|
|
|
|
@ -293,7 +401,7 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
await _minioService.PutObjectAsync("", data.file.name.ToString(), suoluokey,
|
|
|
|
|
memoryStream); // 根据实际格式修改Content-Type
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
var fileUpload = new LasaMediaFile()
|
|
|
|
|
{
|
|
|
|
@ -321,9 +429,10 @@ public class ConfigSubscribe : IJob
|
|
|
|
|
Width = width,
|
|
|
|
|
Height = height,
|
|
|
|
|
minipic = suoluokey,
|
|
|
|
|
//Size = size,
|
|
|
|
|
Size = picSize,
|
|
|
|
|
ShowOnMap = 1,
|
|
|
|
|
display = 1
|
|
|
|
|
display = 1,
|
|
|
|
|
FocalLength = focalLength
|
|
|
|
|
};
|
|
|
|
|
// todo 添加事务
|
|
|
|
|
await _sqlSugarClient.Insertable(fileUpload).ExecuteCommandAsync();
|
|
|
|
|