mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-11 19:50:24 +08:00
fix: FileDB -> f
This commit is contained in:
@@ -4,9 +4,11 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/corona10/goimagehash"
|
||||
"github.com/fumiama/paper-manager/backend/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// QuestionJSON is the struct representation of File.Questions
|
||||
@@ -17,6 +19,29 @@ type QuestionJSON struct {
|
||||
Sub []QuestionJSON `json:"sub,omitempty"`
|
||||
}
|
||||
|
||||
// Delete me and all subs
|
||||
func (q *QuestionJSON) Delete(f *FileDatabase, istemp bool) {
|
||||
if b, err := hex.DecodeString(q.Name); err == nil {
|
||||
err = f.DelQuestion(int64(binary.LittleEndian.Uint64(b)), istemp)
|
||||
if err != nil {
|
||||
logrus.Warnln("[global.QuestionJSON] Delete", q.Name, "err:", err)
|
||||
}
|
||||
}
|
||||
for _, sq := range q.Sub {
|
||||
sq.Delete(f, istemp)
|
||||
}
|
||||
}
|
||||
|
||||
// DelQuestion 删除问题, 其它问题的 dup 可能会残留有 id, 使用时需要排除
|
||||
func (f *FileDatabase) DelQuestion(id int64, istemp bool) error {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
if istemp {
|
||||
return f.db.Del(FileTableTempQuestion, "WHERE ID="+strconv.FormatInt(id, 10))
|
||||
}
|
||||
return f.db.Del(FileTableQuestion, "WHERE ID="+strconv.FormatInt(id, 10))
|
||||
}
|
||||
|
||||
type Question struct {
|
||||
ID int64 // ID is the first 8 bytes of the Plain's md5
|
||||
Path string // Path is the question's docx position
|
||||
|
||||
Reference in New Issue
Block a user