fix 人脸url重新获取

This commit is contained in:
2024-01-15 13:47:29 +08:00
parent 8285e9e7da
commit 10f0918753
8 changed files with 51 additions and 50 deletions

View File

@@ -52,13 +52,13 @@ public class AssignmentsController : ControllerBase
await _assignmentService.UpdateDeviceTaskStatusAsync(request);
}
/// <summary>
/// 获取新token
/// 获取新人脸照片
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
[HttpGet("token")]
public async Task<string> Token(long taskId)
[HttpGet("renewfaceurl")]
public async Task<string> RenewFaceUrlAsync(long taskId)
{
return await _assignmentService.Token(taskId);
return await _assignmentService.RenewFaceUrlAsync(taskId);
}
}

View File

@@ -21,9 +21,9 @@ public interface IAssignmentService : IScopeDependency
Task UpdateDeviceTaskStatusAsync(UpdateDeviceTaskStatusRequest request);
/// <summary>
/// 获取新token
/// 获取新人脸照片
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
Task<string> Token(long taskId);
Task<string> RenewFaceUrlAsync(long taskId);
}

View File

@@ -153,37 +153,36 @@ public class AssignmentService : IAssignmentService
}).ToList();
});
}
/// <summary>
/// 获取新token
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<string> Token(long taskId)
public async Task<string> RenewFaceUrlAsync(long taskId)
{
var task = await _dbContext.Queryable<DeviceTaskEntity>().Where(x => x.Id == taskId).FirstAsync();
var task = await _dbContext.Queryable<DeviceTaskEntity>().Where(x => x.Id == taskId).FirstAsync();
task.ThrowIfNull("该任务不存在");
var isSuccess = task.Status != DeviceTaskStatusEnumType.Success ? true : false;
isSuccess.ThrowIfTrue("设备任务下发状态需为完成");
(task.Status != DeviceTaskStatusEnumType.Process).ThrowIfTrue($"设备任务下发状态需为{DeviceTaskStatusEnumType.Process.GetDescription()}");
string newtoken="";
Scoped.Request.Value.Create((sp) =>
return Scoped.Request.Value.Create((sp) =>
{
FaceUrlOptions faceUrlOptions = sp.GetService<IOptions<FaceUrlOptions>>().Value;
var dataProtectionProvider = sp.GetService<IDataProtectionProvider>();
var timeLimitedDataProtector = dataProtectionProvider
.CreateProtector("down:face")
.ToTimeLimitedDataProtector();
.CreateProtector("down:face")
.ToTimeLimitedDataProtector();
var userCode = task.UserCode;
var key = $"face:{userCode}";
var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit));
newtoken = faceUrlOptions.Url + token;
});
return newtoken;
return faceUrlOptions.Url + token;
});
}