fix(device): 修复自动恢复编译错误 (#201)

This commit is contained in:
QiuSW
2026-09-03 11:16:26 +08:00
parent 2c263e687e
commit 74f55f43cc
+4 -4
View File
@@ -259,9 +259,9 @@ func (service *Service) Register(ctx context.Context, request RegisterRequest, p
return response, nil
}
// ResetIdentity invalidates the current token and grants a short-lived, one-use
// recovery code. The code is returned only to the administrator once; only its
// digest is persisted. It deliberately retains the device row and task bindings.
// ResetIdentity invalidates the current token and opens a short-lived automatic
// re-registration window for the same installId. It retains the device row and
// task bindings, so no recovery code needs to leave the Admin workflow.
func (service *Service) ResetIdentity(ctx context.Context, deviceID uint64) (ResetIdentityResponse, error) {
if service.DB == nil {
return ResetIdentityResponse{}, internalError(errors.New("database is nil"))
@@ -269,7 +269,7 @@ func (service *Service) ResetIdentity(ctx context.Context, deviceID uint64) (Res
now := service.Now()
expiresAt := now.Add(deviceRecoveryLifetime)
response := ResetIdentityResponse{DeviceID: deviceID, ExpiresAt: expiresAt}
err = service.DB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
err := service.DB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
var device models.AgentDevice
if err := tx.First(&device, deviceID).Error; errors.Is(err, gorm.ErrRecordNotFound) {
return &ServiceError{Code: CodeDeviceNotFound, Message: "设备不存在", Retryable: false}