Documentation ¶
Index ¶
- Constants
- Variables
- type File
- type FileDatabase
- func (f *FileDatabase) AddFile(lstid int, reg *Regex, istemp bool, progress func(uint)) error
- func (f *FileDatabase) DelFile(lstid, uid int, istemp bool) error
- func (f *FileDatabase) DelQuestion(id int64, istemp bool) error
- func (f *FileDatabase) GenerateFile(config *GenerateConfig) (docf *docx.Docx, err error)
- func (f *FileDatabase) GetFile(lstid, uid int) (file *File, lst List, err error)
- func (f *FileDatabase) GetFilesByYearRange(yearstart, yearend StudyYear) ([]*File, error)
- func (f *FileDatabase) GetMajors() (majors []string)
- func (f *FileDatabase) GetQuestion(id int64, istemp bool) (Question, error)
- func (f *FileDatabase) GetQuestionByHex(hexid string, istemp bool) (q Question, err error)
- func (f *FileDatabase) ListFileByID(id int) (lst List, err error)
- func (f *FileDatabase) ListUploadedFile(istemp *bool, uid int) (lst []*List, err error)
- func (f *FileDatabase) SaveFileToTemp(uploader int, file io.Reader, name string) (id int, err error)
- type GenerateConfig
- type List
- type Message
- type MessageType
- type MonthlyAPIVisit
- type PaperType
- func (pt PaperType) AB() byte
- func (pt PaperType) FirstSecond() string
- func (pt PaperType) MiddleFinal() string
- func (pt PaperType) OpenClose() string
- func (pt PaperType) SetAB(x byte) PaperType
- func (pt PaperType) SetFirstSecond(x byte) PaperType
- func (pt PaperType) SetMiddleFinal(x string) PaperType
- func (pt PaperType) SetOpenClose(x string) PaperType
- type Question
- type QuestionJSON
- type Regex
- type StudyYear
- type User
- type UserDatabase
- func (u *UserDatabase) AddUser(user *User, opname string) error
- func (u *UserDatabase) DelMessageByID(id int) (err error)
- func (u *UserDatabase) DelUserByID(id int) (err error)
- func (u *UserDatabase) DisableUser(id int, opname string) error
- func (u *UserDatabase) GetAnnualAPIVisitCount() (cnts [12]uint32)
- func (u *UserDatabase) GetMessageByID(id int) (m Message, err error)
- func (u *UserDatabase) GetMessagesOfUser(to int) (ms []Message, err error)
- func (u *UserDatabase) GetSuperIDs() (ids []int, err error)
- func (u *UserDatabase) GetUserByID(id int) (user User, err error)
- func (u *UserDatabase) GetUserByName(username string) (user User, err error)
- func (u *UserDatabase) GetUserRegex(oper *User, id int) (*Regex, error)
- func (u *UserDatabase) GetUsers() (users []User, err error)
- func (u *UserDatabase) GetUsersCount() (int, error)
- func (u *UserDatabase) IsIDExists(id int) bool
- func (u *UserDatabase) IsNameExists(username string) bool
- func (u *UserDatabase) NotifyRegister(ip, name, cont, pswd string) error
- func (u *UserDatabase) NotifyResetPassword(ip, name, cont string) error
- func (u *UserDatabase) SendMessage(text, opname string, to int) error
- func (u *UserDatabase) SetUserRegex(id int, reg *Regex) error
- func (u *UserDatabase) UpdateUserContact(id int, opname, ncont string) error
- func (u *UserDatabase) UpdateUserInfo(id int, opname, nick, avtr, desc string) error
- func (u *UserDatabase) UpdateUserPassword(id int, opname, npwd string) error
- func (u *UserDatabase) UpdateUserRole(id int, nr UserRole, opname string) error
- func (u *UserDatabase) VisitAPI()
- type UserRole
Constants ¶
const ( // DataFolder stores all backend data in DataFolder = "./data/" // FileFolder stores all uploaded blob files FileFolder = DataFolder + "file/" // PaperFolder stores all protected files PaperFolder = DataFolder + "paper/" )
const ( FileTableList = "lst" FileTableFile = "file" FileTableTempFile = "tmpfile" FileTableQuestion = "question" FileTableTempQuestion = "tmpqstn" )
const ( UserTableUser = "user" UserTableMessage = "msg" UserTableMonthlyAPIVisit = "visit" UserTableRegex = "re" )
Variables ¶
var ( UserDB = UserDatabase{/* contains filtered or unexported fields */} FileDB = FileDatabase{/* contains filtered or unexported fields */} )
var ( ErrMajorSplitsTooShort = errors.New("major splits too short") ErrEmptyClass = errors.New("empty class") ErrHasntAnalyzed = errors.New("hasn't analyzed") ErrNoGetFileStatusPermission = errors.New("no get file status permission") )
var ( ErrInvalidGenerateConfig = errors.New("invalid generate config") ErrMajorTooLarge = errors.New("major too large") ErrNoSuchMajor = errors.New("no such major") ErrNoEnoughQuestionToMatchRequire = errors.New("no enough question to match require") ErrRateLimitExceeded = errors.New("rate limit exceeded") )
var ( ErrInvalidRole = errors.New("invalid role") ErrEmptyPassword = errors.New("empty password") ErrEmptyName = errors.New("empty name") ErrInvalidUsersCount = errors.New("invalid users count") ErrInvalidUserID = errors.New("invalid user ID") ErrInvalidAvatar = errors.New("invalid avatar") ErrEmptyUserID = errors.New("empty user ID") ErrEmptyContact = errors.New("empty contact") ErrUsernameExists = errors.New("username exists") ErrInvalidName = errors.New("invalid name") ErrInvalidContact = errors.New("invalid contact") ErrNoSuchFieldName = errors.New("no such field name") ErrEmptyRegex = errors.New("empty regex") )
var (
ErrInvalidSaveName = errors.New("invalid save name")
)
var (
ErrPaperFileExist = errors.New("paper file exist")
)
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct { ID int64 // ID is the first 8 bytes of the original file's md5 ListID int // ListID is the foreign key to List(ID) Year StudyYear Type PaperType Date uint32 // Date is the yyyymmdd of 考试日期 Time time.Duration // Time is 考试时长 Class string // Class is 考试科目 Rate string // Rate is 成绩构成比例 Questions []byte // Questions is for []QuestionJSON }
File stores to paper/Class/2022-2023学年/第一学期/期末/A/xxx.docx
type FileDatabase ¶
type FileDatabase struct {
// contains filtered or unexported fields
}
func (*FileDatabase) AddFile ¶
AddFile from lst and copy it to analyzed path. The para reg must belong to a valid user
func (*FileDatabase) DelFile ¶
func (f *FileDatabase) DelFile(lstid, uid int, istemp bool) error
DelFile by listid
func (*FileDatabase) DelQuestion ¶
func (f *FileDatabase) DelQuestion(id int64, istemp bool) error
DelQuestion 删除问题, 与其它问题的 dup
func (*FileDatabase) GenerateFile ¶
func (f *FileDatabase) GenerateFile(config *GenerateConfig) (docf *docx.Docx, err error)
GenerateFile 用一些限定条件生成新试卷, 云端不保存
func (*FileDatabase) GetFile ¶
func (f *FileDatabase) GetFile(lstid, uid int) (file *File, lst List, err error)
GetFile get analyzed file's structure from List(ID)
func (*FileDatabase) GetFilesByYearRange ¶ added in v0.1.0
func (f *FileDatabase) GetFilesByYearRange(yearstart, yearend StudyYear) ([]*File, error)
GetFilesByYearRange ...
func (*FileDatabase) GetQuestion ¶
func (f *FileDatabase) GetQuestion(id int64, istemp bool) (Question, error)
GetQuestion by id
func (*FileDatabase) GetQuestionByHex ¶ added in v0.1.0
func (f *FileDatabase) GetQuestionByHex(hexid string, istemp bool) (q Question, err error)
GetQuestionHex by hexid
func (*FileDatabase) ListFileByID ¶
func (f *FileDatabase) ListFileByID(id int) (lst List, err error)
func (*FileDatabase) ListUploadedFile ¶
func (f *FileDatabase) ListUploadedFile(istemp *bool, uid int) (lst []*List, err error)
ListUploadedFile will select all file that HasntAnalyzed && IsTemp or !HasntAnalyzed && !IsTemp
func (*FileDatabase) SaveFileToTemp ¶
func (f *FileDatabase) SaveFileToTemp(uploader int, file io.Reader, name string) (id int, err error)
SaveFileToTemp copy file to PaperFolder/tmp/uploader/name and add record into list.
type GenerateConfig ¶
type GenerateConfig struct { Distribution map[string]uint // Distribution is map[majorname]subcount RateLimit float64 // RateLimit 重复率上限 YearStart StudyYear // YearStart 起始年份(空则直到最旧) YearEnd StudyYear // YearEnd 截止年份(空则直到最新) TypeMask PaperType // TypeMask & File.Type != 0 则匹配 }
GenerateConfig 试卷生成配置
type List ¶
type List struct { ID *int // ID is self-inc Uploader int // Uploader is uid UpName string // UpName is uploader's name UpTime int64 // UpTime is upload time (unix timestamp) Size int64 // Size of the original file QuesC int // QuesC 总小题数 HasntAnalyzed bool // HasntAnalyzed whether file has been analyzed IsTemp bool // IsTemp whether file is temp Path string // Path of file, normally unique Desc string // Desc is file's description }
List of file path
type Message ¶
type Message struct { ID *int ToID int // ToID user's ID Date int64 Text string // Text is the message content Name string // Name is the user's name to add in register message Cont string // Cont is the user's phone number to add in register message or an operator's name in add user message Pswd string // Pswd is the user's password to add in register message }
Message is shown in the workbench
func (*Message) Type ¶
func (m *Message) Type() MessageType
Type decide message type by fields Name, Cont and Pswd.
type MessageType ¶
type MessageType uint8
const ( MessageNormal MessageType = iota MessageRegister MessageUserAdded MessageContactChange MessagePasswordChange MessageResetPassword MessageOperator )
type MonthlyAPIVisit ¶
MonthlyAPIVisit counts the api visit history
type PaperType ¶
type PaperType uint16
PaperType [4 开 一页纸 闭] [4 上下] [4 中末] [4 AB]
func (PaperType) SetFirstSecond ¶
func (PaperType) SetMiddleFinal ¶
func (PaperType) SetOpenClose ¶
type Question ¶
type Question struct { ID int64 // ID is the first 8 bytes of the Plain's md5 ListID int // ListID is fk to List(ID) Major string // Major is sub's major name Path string // Path is the question's docx position Plain string // Plain is the plain text of the question (like markdown format) Images []byte // Images is json of the image dhash in XML, ex. ['rId1': '1234567890abcdef', ...] Vector []byte // Vector is json of {word: freq, ...} Dup []byte // Dup is json of {queid: rate, ...} }
func (*Question) GetDuplicateRate ¶
GetDuplicateRate calc q & que's dup rate
func (*Question) MaxDuplicateRate ¶
MaxDuplicateRate parse q.Dup and get the max rate
type QuestionJSON ¶
type QuestionJSON struct { Name string `json:"name"` // Name is name or Question ID Points int `json:"points,omitempty"` // Points is sum of subs' points or self Sub []QuestionJSON `json:"sub,omitempty"` }
QuestionJSON is the struct representation of File.Questions
func (*QuestionJSON) Delete ¶
func (q *QuestionJSON) Delete(f *FileDatabase, istemp bool)
Delete me and all subs, ignore errors
type Regex ¶
type Regex struct { ID int // ID is User(ID) Title string // Title default `.*(\d{4})\s*-.*学年.*(\d).*([中末]).*([AB])\s*卷` Class string // Class default `(考试科目|课程名称):\s*(\S+)\s*` OpenCl string // OpenCl default `考试形式:\s*(\S+)\s*` Date string // Date default `考试日期:\s*(\d+)\s*年\s*(\d+)\s*月\s*(\d+)\s*日` Time string // Time default `考试时长:\s*(\d+)\s*分钟` Rate string // Rate default `(成绩构成比例|课程成绩构成):\s*(.*%)\s*` Major string // Major default `([一二三四五六七八九十]+)、\s*(.*)\s*(.*([空题]?)\s*(\d*).*共\s*(\d+)\s*分.*)` Sub string // Sub default `(\d+)、` }
Regex stores user's config of splitting docx file
func GetDefaultRegex ¶
func GetDefaultRegex() (reg Regex)
type User ¶
type User struct { ID *int Role UserRole Date int64 // Date is the creating date's unix timestamp Pswd string Last int64 // Last is the last password reseting unix timestamp Name string `db:"Name,UNIQUE"` Nick string Avtr string // Avtr is the user's avatar, typically a image url Cont string // Cont is the user's contact, ex. phone number Desc string }
User stores a user in table named UserTableUser
func (*User) IsFileManager ¶
IsFileManager checks if token is valid for a filemgr
type UserDatabase ¶
type UserDatabase struct {
// contains filtered or unexported fields
}
func (*UserDatabase) AddUser ¶
func (u *UserDatabase) AddUser(user *User, opname string) error
AddUser but cannot customize the ID field for it is self-increasing
func (*UserDatabase) DelMessageByID ¶
func (u *UserDatabase) DelMessageByID(id int) (err error)
DelMessageByID ...
func (*UserDatabase) DelUserByID ¶
func (u *UserDatabase) DelUserByID(id int) (err error)
DelUserByID ...
func (*UserDatabase) DisableUser ¶
func (u *UserDatabase) DisableUser(id int, opname string) error
DisableUser ...
func (*UserDatabase) GetAnnualAPIVisitCount ¶
func (u *UserDatabase) GetAnnualAPIVisitCount() (cnts [12]uint32)
GetAnnualAPIVisitCount get the latest 12 mounths' count
func (*UserDatabase) GetMessageByID ¶
func (u *UserDatabase) GetMessageByID(id int) (m Message, err error)
GetMessageByID ...
func (*UserDatabase) GetMessagesOfUser ¶
func (u *UserDatabase) GetMessagesOfUser(to int) (ms []Message, err error)
GetMessagesOfUser will change non-empty Pswd field to "-"
func (*UserDatabase) GetSuperIDs ¶
func (u *UserDatabase) GetSuperIDs() (ids []int, err error)
func (*UserDatabase) GetUserByID ¶
func (u *UserDatabase) GetUserByID(id int) (user User, err error)
GetUserByID ...
func (*UserDatabase) GetUserByName ¶
func (u *UserDatabase) GetUserByName(username string) (user User, err error)
GetUserByName avoids sql injection by limiting username to 0-9A-Za-z
func (*UserDatabase) GetUserRegex ¶
func (u *UserDatabase) GetUserRegex(oper *User, id int) (*Regex, error)
GetUserRegex default newRegex()
func (*UserDatabase) GetUsers ¶
func (u *UserDatabase) GetUsers() (users []User, err error)
GetUsers will set Pswd field to empty
func (*UserDatabase) GetUsersCount ¶
func (u *UserDatabase) GetUsersCount() (int, error)
GetUsersCount ...
func (*UserDatabase) IsNameExists ¶
func (u *UserDatabase) IsNameExists(username string) bool
IsNameExists avoids sql injection by limiting username to 0-9A-Za-z
func (*UserDatabase) NotifyRegister ¶
func (u *UserDatabase) NotifyRegister(ip, name, cont, pswd string) error
NotifyRegister will send register notification to all supers
func (*UserDatabase) NotifyResetPassword ¶
func (u *UserDatabase) NotifyResetPassword(ip, name, cont string) error
NotifyResetPassword will send notification to all supers
func (*UserDatabase) SendMessage ¶
func (u *UserDatabase) SendMessage(text, opname string, to int) error
SendMessage will send a normal message to id
func (*UserDatabase) SetUserRegex ¶
func (u *UserDatabase) SetUserRegex(id int, reg *Regex) error
SetUserRegex set Regex.name = re
func (*UserDatabase) UpdateUserContact ¶
func (u *UserDatabase) UpdateUserContact(id int, opname, ncont string) error
UpdateUserContact ...
func (*UserDatabase) UpdateUserInfo ¶
func (u *UserDatabase) UpdateUserInfo(id int, opname, nick, avtr, desc string) error
UpdateUserInfo ...
func (*UserDatabase) UpdateUserPassword ¶
func (u *UserDatabase) UpdateUserPassword(id int, opname, npwd string) error
UpdateUserPassword ...
func (*UserDatabase) UpdateUserRole ¶
func (u *UserDatabase) UpdateUserRole(id int, nr UserRole, opname string) error
UpdateUserRole ...
func (*UserDatabase) VisitAPI ¶
func (u *UserDatabase) VisitAPI()
VisitAPI increases count of this mounth by 1