i18n: Translate all Chinese to English across the codebase
Translate Chinese comments, log/error messages, validator labels and Swagger annotations to English throughout the source code, generated Swagger docs, config files and CI workflows. Make the English README primary: README.md now holds the English docs and README_EN.md holds the Chinese version, with cross-language links updated accordingly. Note: the generated docs/ swagger files were translated in place; run `go generate ./...` (swag init) to regenerate them from the now-English annotations when a Go toolchain is available. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+18
-18
@@ -8,7 +8,7 @@ import (
|
||||
type PeerService struct {
|
||||
}
|
||||
|
||||
// FindById 根据id查找
|
||||
// FindById finds a peer by id
|
||||
func (ps *PeerService) FindById(id string) *model.Peer {
|
||||
p := &model.Peer{}
|
||||
DB.Where("id = ?", id).First(p)
|
||||
@@ -25,22 +25,22 @@ func (ps *PeerService) InfoByRowId(id uint) *model.Peer {
|
||||
return p
|
||||
}
|
||||
|
||||
// FindByUserIdAndUuid 根据用户id和uuid查找peer
|
||||
// FindByUserIdAndUuid finds a peer by user id and uuid
|
||||
func (ps *PeerService) FindByUserIdAndUuid(uuid string, userId uint) *model.Peer {
|
||||
p := &model.Peer{}
|
||||
DB.Where("uuid = ? and user_id = ?", uuid, userId).First(p)
|
||||
return p
|
||||
}
|
||||
|
||||
// UuidBindUserId 绑定用户id
|
||||
// UuidBindUserId binds a user id
|
||||
func (ps *PeerService) UuidBindUserId(deviceId string, uuid string, userId uint) {
|
||||
peer := ps.FindByUuid(uuid)
|
||||
// 如果存在则更新
|
||||
// if it exists, update it
|
||||
if peer.RowId > 0 {
|
||||
peer.UserId = userId
|
||||
ps.Update(peer)
|
||||
} else {
|
||||
// 不存在则创建
|
||||
// create if it does not exist
|
||||
/*if deviceId != "" {
|
||||
DB.Create(&model.Peer{
|
||||
Id: deviceId,
|
||||
@@ -51,7 +51,7 @@ func (ps *PeerService) UuidBindUserId(deviceId string, uuid string, userId uint)
|
||||
}
|
||||
}
|
||||
|
||||
// UuidUnbindUserId 解绑用户id, 用于用户注销
|
||||
// UuidUnbindUserId unbinds the user id, used for user logout
|
||||
func (ps *PeerService) UuidUnbindUserId(uuid string, userId uint) {
|
||||
peer := ps.FindByUserIdAndUuid(uuid, userId)
|
||||
if peer.RowId > 0 {
|
||||
@@ -59,12 +59,12 @@ func (ps *PeerService) UuidUnbindUserId(uuid string, userId uint) {
|
||||
}
|
||||
}
|
||||
|
||||
// EraseUserId 清除用户id, 用于用户删除
|
||||
// EraseUserId clears the user id, used for user deletion
|
||||
func (ps *PeerService) EraseUserId(userId uint) error {
|
||||
return DB.Model(&model.Peer{}).Where("user_id = ?", userId).Update("user_id", 0).Error
|
||||
}
|
||||
|
||||
// ListByUserIds 根据用户id取列表
|
||||
// ListByUserIds gets the list by user ids
|
||||
func (ps *PeerService) ListByUserIds(userIds []uint, page, pageSize uint) (res *model.PeerList) {
|
||||
res = &model.PeerList{}
|
||||
res.Page = int64(page)
|
||||
@@ -91,11 +91,11 @@ func (ps *PeerService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *
|
||||
return
|
||||
}
|
||||
|
||||
// ListFilterByUserId 根据用户id过滤Peer列表
|
||||
// ListFilterByUserId filters the peer list by user id
|
||||
func (ps *PeerService) ListFilterByUserId(page, pageSize uint, where func(tx *gorm.DB), userId uint) (res *model.PeerList) {
|
||||
userWhere := func(tx *gorm.DB) {
|
||||
tx.Where("user_id = ?", userId)
|
||||
// 如果还有额外的筛选条件,执行它
|
||||
// if there are additional filter conditions, apply them
|
||||
if where != nil {
|
||||
where(tx)
|
||||
}
|
||||
@@ -103,30 +103,30 @@ func (ps *PeerService) ListFilterByUserId(page, pageSize uint, where func(tx *go
|
||||
return ps.List(page, pageSize, userWhere)
|
||||
}
|
||||
|
||||
// Create 创建
|
||||
// Create create
|
||||
func (ps *PeerService) Create(u *model.Peer) error {
|
||||
res := DB.Create(u).Error
|
||||
return res
|
||||
}
|
||||
|
||||
// Delete 删除, 同时也应该删除token
|
||||
// Delete deletes a peer; the associated token should also be deleted
|
||||
func (ps *PeerService) Delete(u *model.Peer) error {
|
||||
uuid := u.Uuid
|
||||
err := DB.Delete(u).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 删除token
|
||||
// delete the token
|
||||
return AllService.UserService.FlushTokenByUuid(uuid)
|
||||
}
|
||||
|
||||
// GetUuidListByIDs 根据ids获取uuid列表
|
||||
// GetUuidListByIDs gets the uuid list by ids
|
||||
func (ps *PeerService) GetUuidListByIDs(ids []uint) ([]string, error) {
|
||||
var uuids []string
|
||||
err := DB.Model(&model.Peer{}).
|
||||
Where("row_id in (?)", ids).
|
||||
Pluck("uuid", &uuids).Error
|
||||
//过滤uuids中的空字符串
|
||||
// filter out empty strings in uuids
|
||||
var newUuids []string
|
||||
for _, uuid := range uuids {
|
||||
if uuid != "" {
|
||||
@@ -136,18 +136,18 @@ func (ps *PeerService) GetUuidListByIDs(ids []uint) ([]string, error) {
|
||||
return newUuids, err
|
||||
}
|
||||
|
||||
// BatchDelete 批量删除, 同时也应该删除token
|
||||
// BatchDelete batch deletes peers; the associated tokens should also be deleted
|
||||
func (ps *PeerService) BatchDelete(ids []uint) error {
|
||||
uuids, err := ps.GetUuidListByIDs(ids)
|
||||
err = DB.Where("row_id in (?)", ids).Delete(&model.Peer{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 删除token
|
||||
// delete the token
|
||||
return AllService.UserService.FlushTokenByUuids(uuids)
|
||||
}
|
||||
|
||||
// Update 更新
|
||||
// Update update
|
||||
func (ps *PeerService) Update(u *model.Peer) error {
|
||||
return DB.Model(u).Updates(u).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user