Documentation
¶
Index ¶
- Constants
- Variables
- func CheckPass(user *User, pass string) bool
- func GenMultiTrnFilesFromSrcFiles(srcRegs []string, trnReg string, ignores []string, proj *Project) ([]string, map[string][]string)
- func GenSalt() []byte
- func GenTrnFilesFromSrcFiles(src []string, trn string, lang *Language, proj *Project) (res []string)
- func HashSalt(pass string, salt []byte) []byte
- func Init() error
- func NewVote(user_id int64, tran_id int64, vote int)
- func ProcessTXT(data []byte) ([]string, []int)
- func ProcessXML(cfg *ProjCfg, data []byte) ([]string, []int)
- func ProjExisted(uri string) bool
- func SetAllFilesInvalid(proj_id int64)
- func SetAllSentsInvalid(file_id int64)
- func SetUserProjRole(user_id int64, proj_id int64, role Role)
- func TxnVote(user_id int64, tran_id int64, vote int) (likes int)
- func UpdateProjCfgPullStatus(cfg *ProjCfg, stat int)
- func UpdateProjCfgPushStatus(cfg *ProjCfg, stat int)
- func UpdateVote(user_id int64, tran_id int64, vote int)
- type CreateProjRequest
- type ExtraCfg
- type Language
- type LoginRequest
- type PostTranRequest
- type ProjCfg
- func (cfg *ProjCfg) AfterFind(tx *gorm.DB) error
- func (cfg *ProjCfg) Process()
- func (*ProjCfg) TableName() string
- func (cfg *ProjCfg) TxnProcess(proj *Project, files []string)
- func (cfg *ProjCfg) UpdateProjCfg(req *UpdateProjCfgRequest) error
- func (cfg *ProjCfg) UpdateStatus(stat int)
- func (cfg *ProjCfg) Write()
- type ProjFile
- type ProjRole
- type Project
- type RegisterRequest
- type RepoInfo
- type Response
- type Role
- type Sentence
- type Token
- type TranRes
- type Translation
- type UpdateProfileRequest
- type UpdateProjCfgRequest
- type User
- type Voting
- type XMLCfg
Constants ¶
const ( VoteLike = 1 VoteUnlike = -1 VoteNone = 0 )
Variables ¶
var (
ProjMutexMap = util.NewMutexMap()
)
var Resp400 = Response{ Success: false, Code: 400, Msg: "bad request", }
Resp400 is for 'Bad Request'
var Resp403 = Response{ Success: false, Code: 403, Msg: "forbidden", }
Resp403 is for 'Forbidden'
var Resp404 = Response{ Success: false, Code: 404, Msg: "not found", }
Resp404 is for 'Not Found'
var RespInvalidToken = Response{ Success: false, Code: 401, Msg: "invalid token", }
RespInvalidToken when token is invalid
Functions ¶
func GenTrnFilesFromSrcFiles ¶
func ProcessTXT ¶
func ProjExisted ¶
func SetAllFilesInvalid ¶
func SetAllFilesInvalid(proj_id int64)
func SetAllSentsInvalid ¶
func SetAllSentsInvalid(file_id int64)
func SetUserProjRole ¶
func UpdateProjCfgPullStatus ¶
UpdateProjCfgPullStatus update a project cfg pull status
func UpdateProjCfgPushStatus ¶
UpdateProjCfgPushStatus update a project cfg push status
func UpdateVote ¶
Types ¶
type CreateProjRequest ¶
type Language ¶
type Language struct { Code string `json:"code"` Code2 string `json:"code2"` ISO string `json:"iso"` Name string `json:"name"` }
Language 语言
func GetLangByCode ¶
GetLangByCode gets a language by language code
func ParseLangsFromCodes ¶
ParseLangsFromCodes extract []Lang from []string like ["en", "zh-CN"]
func ParseLangsFromStr ¶
ParseLangsFromStr extract []Lang from string like "eng|zho"
type LoginRequest ¶
type PostTranRequest ¶
type ProjCfg ¶
type ProjCfg struct { ID int64 `json:"id" gorm:"primaryKey;autoIncrement"` Status int `json:"status" gorm:"type:tinyint;"` SrcBr string `json:"src_branch" gorm:"type:varchar(32);notNull"` TrnBr string `json:"trn_branch" gorm:"type:varchar(32);notNull"` PullGap uint16 `json:"pull_gap" gorm:"index;notNull"` PushGap uint16 `json:"push_gap" gorm:"index;notNull"` PullStatus int `json:"pull_status" gorm:"notNull"` PushStatus int `json:"push_status" gorm:"notNull"` LastPullAt *time.Time `json:"last_pull_at"` LastPushAt *time.Time `json:"last_push_at"` SrcRegs []string `json:"src_files" gorm:"-"` SrcRegsBytes []byte `json:"-" gorm:"column:src_regs"` TrnReg string `json:"trn_file" gorm:"column:trn_reg"` IgnRegs []string `json:"ign_regs" gorm:"-"` IgnRegsBytes []byte `json:"-" gorm:"column:ign_regs"` Extra ExtraCfg `json:"extra" gorm:"-"` ExtraBytes []byte `json:"-" gorm:"column:extra"` }
ProjCfg means project config
func GetProjCfgByID ¶
GetProjCfgByID get a project config by config id
func ListSyncProjCfg ¶
func ListSyncProjCfg() []ProjCfg
ListSyncProjCfg list all project cfg that should be sync
func NewProjCfg ¶
NewProjCfg creates a new cfg for project
func (*ProjCfg) TxnProcess ¶
func (*ProjCfg) UpdateProjCfg ¶
func (cfg *ProjCfg) UpdateProjCfg(req *UpdateProjCfgRequest) error
type ProjFile ¶
type ProjFile struct { ID int64 `json:"id" gorm:"primaryKey"` ProjID int64 `json:"proj_id" gorm:"index"` Path string `json:"path" gorm:"index"` Valid bool `json:"-" gorm:"index"` SentCnt int `json:"sent_cnt" gorm:""` WordCnt int `json:"word_cnt" gorm:""` Content string `json:"-" gorm:"type:text"` }
func GetProjFileByID ¶
func GetProjFileByPath ¶
func ListProjFiles ¶
func MustGetValidProjFile ¶
func NewProjFile ¶
NewProjFile creates a new file for project
func (*ProjFile) ReadContent ¶
func (*ProjFile) TxnProcess ¶
type ProjRole ¶
type ProjRole struct { ProjID int64 `json:"proj_id" gorm:"primaryKey"` UserID int64 `json:"user_id" gorm:"primaryKey"` Role Role `json:"role" gorm:"type:tinyint"` CreatedAt time.Time `` UpdatedAt time.Time `` }
func GetUserProjRole ¶
type Project ¶
type Project struct { ID int64 `json:"id" gorm:"primaryKey;autoIncrement"` URI string `json:"uri" gorm:"type:varchar(32);uniqueIndex;notNull"` Name string `json:"name" gorm:"type:varchar(32);notNull"` OwnerID int64 `json:"owner_id" gorm:"index;notNull"` Token string `json:"-" gorm:"type:varchar(128)"` Type int `json:"type" gorm:"type:tinyint;index;notNull"` Status int `json:"status" gorm:"type:tinyint;notNull"` Desc string `json:"desc" gorm:"type:varchar(256)"` GitURL string `json:"git_url" gorm:"type:varchar(256)"` Path string `json:"-" gorm:"type:varchar(256)"` SrcLangs string `json:"-" gorm:"type:varchar(128)"` TrnLangs string `json:"-" gorm:"type:varchar(128)"` SourceLanguages []Language `json:"src_langs" gorm:"-"` TranslateLanguages []Language `json:"trn_langs" gorm:"-"` ErrMsg string `json:"error_message"` PublicView bool `json:"public_view"` PublicContribute bool `json:"public_contribute"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
Project means project model
func ListUninitProj ¶
func ListUninitProj() []Project
ListUninitProj list all uninitialized projects
func ListUserProj ¶
ListUserProj list all projects from a user
func (*Project) UpdateStatus ¶
type RegisterRequest ¶
type Response ¶
type Response struct { Success bool `json:"success"` Data map[string]interface{} `json:"data"` Code int `json:"code"` Msg string `json:"message"` }
Response is HTTP JSON result
type Role ¶
type Role int8
const ( //RoleAdmin can view, submit, vote and commit translations. Can also manage project settings, including adding collaborators RoleAdmin Role = iota //RoleCommitter can view, submit, vote and commit translations RoleCommitter //RoleContributor can view, submit and vote translations RoleContributor //RoleViewer can view translations RoleViewer RoleNone Role = Role(127) )
type Sentence ¶
type Sentence struct { ID int64 `json:"id" gorm:"primaryKey;autoIncrement"` ProjID int64 `json:"proj_id" gorm:"index"` FileID int64 `json:"file_id" gorm:"index"` Offset int `json:"offset" gorm:"index"` Valid bool `json:"-" gorm:"index"` Locked bool `json:"locked" gorm:""` MD5 string `json:"-" gorm:"index;type:char(32)"` Content string `json:"content" gorm:"type:text"` }
func GetSentByID ¶
func ListValidSents ¶
func NewSentence ¶
NewSentence creates a new file for project
func (*Sentence) TopTran ¶
func (sent *Sentence) TopTran(lang_code string) *Translation
type Token ¶
type Token struct { ID int64 `json:"id" gorm:"primaryKey;autoIncrement"` Valid bool `json:"-"` Source int `json:"-" gorm:"type:varchar(16);index"` OwnerID int64 `json:"-" gorm:"index"` OwnerName string `json:"owner_name" gorm:"type:varchar(32)"` OwnerAvatarURL string `json:"avatar_url" gorm:"type:varchar(128)"` AccessToken string `json:"-" gorm:"type:varchar(128)"` Scope string `json:"-" gorm:"type:varchar(8);index"` CreatedAt time.Time `json:"created_at"` }
Token 存储Github等来源的Token
func GetValidTokensByOwnerID ¶
GetValidTokensByOwnerID get a token by owner id
type TranRes ¶
type TranRes struct { ID int64 `json:"id"` UserID int64 `json:"user_id"` UserName string `json:"user_name"` Vote int `json:"vote"` ProjID int64 `json:"proj_id"` FileID int64 `json:"file_id"` SentID int64 `json:"sent_id"` LangCode string `json:"lang_code"` Likes int64 `json:"likes"` Content string `json:"content"` }
func ListSentTrans ¶
type Translation ¶
type Translation struct { ID int64 `gorm:"primaryKey;autoIncrement"` UserID int64 `gorm:"index"` ProjID int64 `gorm:""` FileID int64 `gorm:"index"` SentID int64 `gorm:"index"` Likes int64 `gorm:""` Unlikes int64 `json:"-" gorm:""` Score float64 `json:"-" gorm:"index"` LangCode string `gorm:"index;type:varchar(8)"` Pinned bool `json:"pinned" gorm:"index"` Content string `gorm:"type:text"` }
func GetTranByID ¶
func GetTranByID(id int64) *Translation
func (*Translation) Delete ¶
func (tran *Translation) Delete()
func (*Translation) Pin ¶
func (tran *Translation) Pin()
func (*Translation) TableName ¶
func (*Translation) TableName() string
func (*Translation) Unpin ¶
func (tran *Translation) Unpin()
func (*Translation) Write ¶
func (tran *Translation) Write()
type UpdateProfileRequest ¶
func (*UpdateProfileRequest) Map ¶
func (req *UpdateProfileRequest) Map() map[string]interface{}
func (*UpdateProfileRequest) Valid ¶
func (req *UpdateProfileRequest) Valid() bool
type UpdateProjCfgRequest ¶
type UpdateProjCfgRequest struct { SrcBr string `json:"src_br"` TrnBr string `json:"trn_br"` PullGap uint16 `json:"pull_gap"` PushGap uint16 `json:"push_gap"` SrcRegs []string `json:"src_files"` SrcRegsBytes []byte `json:"-"` TrnReg string `json:"trn_file"` IgnRegs []string `json:"ign_files"` IgnRegsBytes []byte `json:"-"` Extra ExtraCfg `json:"extra"` ExtraBytes []byte `json:"-"` }
func (*UpdateProjCfgRequest) Map ¶
func (req *UpdateProjCfgRequest) Map() map[string]interface{}
func (*UpdateProjCfgRequest) Valid ¶
func (req *UpdateProjCfgRequest) Valid() bool
type User ¶
type User struct { ID int64 `json:"id" gorm:"primaryKey;autoIncrement"` Email string `json:"email" gorm:"type:varchar(256);uniqueIndex"` Name string `json:"name" gorm:"type:varchar(32);index;notNull"` Bio string `json:"bio" gorm:"type:varchar(256)"` AvatarURL string `json:"avatar_url" gorm:"type:varchar(256)"` GithubID int64 `json:"github_id" gorm:"index"` GithubRepoToken string `json:"-" gorm:"type:varchar(64)"` IsActive bool `json:"is_active"` NoPassword bool `json:"-"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Password []byte `json:"-" gorm:"type:binary(64)"` Salt []byte `json:"-" gorm:"type:binary(64)"` }
User means user
func GetUserByGithubID ¶
GetUserByGithubID gets a user by github id
func NewUserFromGithub ¶
NewUserFromGithub creates a new user from OAuth