feat: localize license states and restore revoked licenses
Some checks failed
Check / delivery-static (push) Has been cancelled
Check / api (push) Has been cancelled
Check / web (push) Has been cancelled

Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
2026-10-12 16:11:09 +08:00
parent f4b99e50cd
commit 09910db251
8 changed files with 141 additions and 6 deletions

View File

@@ -345,6 +345,15 @@ func (a *BusinessAPI) operateLicense(c *gin.Context, operation string) {
apiError(c, 500, "internal_error", "撤销失败")
return
}
} else if operation == "restore" {
if rec.Status != "revoked" {
apiError(c, 409, "invalid_state", "仅已撤销的授权可以恢复")
return
}
if _, err = tx.ExecContext(c, "UPDATE licenses SET status='active',revoked_at=NULL WHERE id=?", id); err != nil {
apiError(c, 500, "internal_error", "恢复失败")
return
}
} else {
if rec.Status == "revoked" || !expires.After(rec.ExpiresAt) {
apiError(c, 400, "invalid_request", "续期时间必须晚于当前结束时间且授权未撤销")
@@ -371,7 +380,9 @@ func (a *BusinessAPI) operateLicense(c *gin.Context, operation string) {
if operation == "revoke" {
rec.Status = "revoked"
} else {
rec.ExpiresAt = expires
if operation == "renew" {
rec.ExpiresAt = expires
}
rec.Status = currentLicenseStatus("active", rec.StartsAt, rec.ExpiresAt, time.Now().UTC())
}
c.JSON(200, gin.H{"data": rec, "idempotent_replay": false})