feat: publish v1.0.0-rc.36-custom.1
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s

This commit is contained in:
Codex committed 2026-09-11 05:07:48 +08:00
commit bb7968b612
2381 files changed
+551494

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
package model
import (
"errors"
"fmt"
"github.com/QuantumNous/new-api/common"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
const activeLoginEncryptionKeySlot = "active"
// LoginEncryptionKey stores internal key material used by the browser login
// protocol. It is deliberately separate from administrator-facing options.
type LoginEncryptionKey struct {
ID uint `json:"-" gorm:"primaryKey"`
Slot string `json:"-" gorm:"type:varchar(32);not null;uniqueIndex"`
PrivateKeyPEM string `json:"-" gorm:"type:text;not null"`
}
// InitPasswordEncryption loads the shared login-encryption key from its
// dedicated store. Concurrent replicas converge through the unique slot.
func InitPasswordEncryption() error {
var stored LoginEncryptionKey
queryErr := DB.Where("slot = ?", activeLoginEncryptionKeySlot).First(&stored).Error
if queryErr == nil {
if err := common.LoadPasswordEncryptionPrivateKey(stored.PrivateKeyPEM); err != nil {
return fmt.Errorf("load persisted password encryption key: %w", err)
}
return nil
}
if !errors.Is(queryErr, gorm.ErrRecordNotFound) {
return fmt.Errorf("read password encryption key: %w", queryErr)
}
privateKeyPEM, err := common.GeneratePasswordEncryptionPrivateKey()
if err != nil {
return err
}
candidate := LoginEncryptionKey{
Slot: activeLoginEncryptionKeySlot,
PrivateKeyPEM: privateKeyPEM,
}
if err := DB.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "slot"}},
DoNothing: true,
}).Create(&candidate).Error; err != nil {
return fmt.Errorf("persist password encryption key: %w", err)
}
if err := DB.Where("slot = ?", activeLoginEncryptionKeySlot).First(&stored).Error; err != nil {
return fmt.Errorf("reload password encryption key: %w", err)
}
if err := common.LoadPasswordEncryptionPrivateKey(stored.PrivateKeyPEM); err != nil {
return fmt.Errorf("load persisted password encryption key: %w", err)
}
return nil
}