cleanup
This commit is contained in:
parent
cdc4c60618
commit
8fece91f75
16 changed files with 2275 additions and 2252 deletions
438
node-handle-search.go
Normal file → Executable file
438
node-handle-search.go
Normal file → Executable file
|
@ -1,219 +1,219 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
func handleSearchTextMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-text request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchTextResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "text-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
// Log the address to be used for sending the response
|
||||
log.Printf("Sending text search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending text search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSearchImageMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-image request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchImageResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "image-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
// Log the address to be used for sending the response
|
||||
log.Printf("Sending image search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending image search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSearchVideoMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-video request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchVideoResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "video-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
log.Printf("Sending video search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending video search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSearchFileMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-file request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchFileResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "file-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
log.Printf("Sending file search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending file search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSearchForumMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-forum request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchForumResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "forum-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
// Log the address to be used for sending the response
|
||||
log.Printf("Sending forum search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending forum search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
func handleSearchTextMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
printWarn("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
printDebug("Received search-text request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchTextResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
printWarn("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "text-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
// Log the address to be used for sending the response
|
||||
printDebug("Sending text search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
printErr("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
printWarn("Error sending text search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSearchImageMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-image request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchImageResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "image-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
// Log the address to be used for sending the response
|
||||
log.Printf("Sending image search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending image search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSearchVideoMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-video request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchVideoResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "video-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
log.Printf("Sending video search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending video search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSearchFileMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-file request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchFileResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "file-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
log.Printf("Sending file search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending file search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func handleSearchForumMessage(msg Message) {
|
||||
var searchParams struct {
|
||||
Query string `json:"query"`
|
||||
Safe string `json:"safe"`
|
||||
Lang string `json:"lang"`
|
||||
Page int `json:"page"`
|
||||
ResponseAddr string `json:"responseAddr"`
|
||||
}
|
||||
err := json.Unmarshal([]byte(msg.Content), &searchParams)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing search parameters: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Received search-forum request. ResponseAddr: %s", searchParams.ResponseAddr)
|
||||
|
||||
results := fetchForumResults(searchParams.Query, searchParams.Safe, searchParams.Lang, searchParams.Page)
|
||||
resultsJSON, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling search results: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
responseMsg := Message{
|
||||
ID: hostID,
|
||||
Type: "forum-results",
|
||||
Content: string(resultsJSON),
|
||||
}
|
||||
|
||||
// Log the address to be used for sending the response
|
||||
log.Printf("Sending forum search results to %s", searchParams.ResponseAddr)
|
||||
|
||||
if searchParams.ResponseAddr == "" {
|
||||
log.Printf("Error: Response address is empty")
|
||||
return
|
||||
}
|
||||
|
||||
err = sendMessage(searchParams.ResponseAddr, responseMsg)
|
||||
if err != nil {
|
||||
log.Printf("Error sending forum search results to %s: %v", searchParams.ResponseAddr, err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue