Skip to content

Commit

Permalink
chore(rename): Renamed md5 to id for document field
Browse files Browse the repository at this point in the history
  • Loading branch information
breadrock1 committed Jun 16, 2024
1 parent 38da771 commit 2d3040a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/ocr/raw/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (re *Service) RecognizeFile(document *reader.Document) error {

stringData := string(bytesData)
if len(stringData) == 0 {
return fmt.Errorf("returned empty content data for: %s", document.DocumentMD5)
return fmt.Errorf("returned empty content data for: %s", document.DocumentID)
}

document.SetContentData(stringData)
Expand Down
4 changes: 2 additions & 2 deletions internal/reader/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Document struct {
FolderID string `json:"folder_id"`
FolderPath string `json:"folder_path"`
Content string `json:"content"`
DocumentMD5 string `json:"document_md5"`
DocumentID string `json:"document_id"`
DocumentSSDEEP string `json:"document_ssdeep"`
DocumentName string `json:"document_name"`
DocumentPath string `json:"document_path"`
Expand Down Expand Up @@ -142,7 +142,7 @@ func (d *Document) ComputeMd5Hash() {
}

func (d *Document) ComputeMd5HashData(data []byte) {
d.DocumentMD5 = fmt.Sprintf("%x", md5.Sum(data))
d.DocumentID = fmt.Sprintf("%x", md5.Sum(data))
}

func (d *Document) ComputeSsdeepHash() {
Expand Down
2 changes: 1 addition & 1 deletion internal/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func New() *Service {

func (s *Service) AddAwaitDocument(document *Document) {
s.mu.Lock()
s.AwaitingDocs[document.DocumentMD5] = document
s.AwaitingDocs[document.DocumentID] = document
s.mu.Unlock()
}

Expand Down
6 changes: 3 additions & 3 deletions internal/searcher/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *Service) StoreDocument(document *reader.Document) error {
}

reqBody := bytes.NewBuffer(jsonData)
targetURL := fmt.Sprintf("%s/storage/folders/%s/documents/%s", s.Address, document.FolderID, document.DocumentMD5)
targetURL := fmt.Sprintf("%s/storage/folders/%s/documents/%s", s.Address, document.FolderID, document.DocumentID)
log.Printf("Storing document %s to elastic", document.FolderID)

method := "PUT"
Expand All @@ -48,14 +48,14 @@ func (s *Service) StoreDocument(document *reader.Document) error {
}

reqBody = bytes.NewBuffer(jsonData)
targetURL = fmt.Sprintf("%s/storage/folders/%s/documents/%s", s.Address, "history", document.DocumentMD5)
targetURL = fmt.Sprintf("%s/storage/folders/%s/documents/%s", s.Address, "history", document.DocumentID)
_, err = sender.SendRequest(reqBody, &targetURL, &method, &mimeType, s.Timeout)
if err != nil {
log.Println("Failed while sending request: ", err)
}

reqBody = bytes.NewBuffer(jsonData)
targetURL = fmt.Sprintf("%s/storage/folders/%s/documents/%s?document_type=vectors", s.Address, document.FolderID, document.DocumentMD5)
targetURL = fmt.Sprintf("%s/storage/folders/%s/documents/%s?document_type=vectors", s.Address, document.FolderID, document.DocumentID)

Check failure on line 58 in internal/searcher/searcher.go

View workflow job for this annotation

GitHub Actions / golangci

line is 135 characters (lll)
_, err = sender.SendRequest(reqBody, &targetURL, &method, &mimeType, s.Timeout)
if err != nil {
log.Println("Failed while sending request: ", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *Service) Create(ctx context.Context, document *reader.Document) (int, e
document.FolderID,
document.FolderPath,
document.Content,
document.DocumentMD5,
document.DocumentID,
document.DocumentSSDEEP,
document.DocumentName,
document.DocumentPath,
Expand Down
2 changes: 1 addition & 1 deletion internal/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (nw *NotifyWatcher) PopRecognizedDocument(documentID string) *reader.Docume

func (nw *NotifyWatcher) AppendRecognizedDocument(document *reader.Document) {
nw.mu.Lock()
nw.RecognizedDocuments[document.DocumentMD5] = document
nw.RecognizedDocuments[document.DocumentID] = document
nw.mu.Unlock()
}

Expand Down

0 comments on commit 2d3040a

Please sign in to comment.