From ab1784ba3bd25d84b87020ec65da738d830eaeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 9 May 2023 23:35:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96analyze?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/global/analyze.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/global/analyze.go b/backend/global/analyze.go index fe59e66..0e13ae0 100644 --- a/backend/global/analyze.go +++ b/backend/global/analyze.go @@ -6,6 +6,7 @@ import ( "encoding/binary" "encoding/hex" "encoding/json" + "errors" "fmt" "image" "io" @@ -23,6 +24,10 @@ import ( "github.com/sirupsen/logrus" ) +var ( + ErrPaperFileExist = errors.New("paper file exist") +) + // AddFile from lst and copy it to analyzed path. // The para reg must belong to a valid user func (f *FileDatabase) AddFile(lstid int, reg *Regex, istemp bool, progress func(uint)) error { @@ -379,11 +384,14 @@ func (f *FileDatabase) AddFile(lstid int, reg *Regex, istemp bool, progress func if err != nil { return err } - lst.Path = filebasepath + file.Class + ".docx" lst.HasntAnalyzed = false lst.Desc = fmt.Sprintf("%s%v%v%v%c卷", file.Class, file.Year, file.Type.FirstSecond(), file.Type.MiddleFinal(), file.Type.AB(), ) + lst.Path = filebasepath + lst.Desc + ".docx" + if utils.IsExist(lst.Path) { + return ErrPaperFileExist + } dstf, err := os.Create(lst.Path) if err != nil { return err