summaryrefslogtreecommitdiffstats
path: root/internal/client/usrsx.go
diff options
context:
space:
mode:
authors <[email protected]>2025-11-03 21:17:12 -0500
committers <[email protected]>2025-11-03 21:17:12 -0500
commitf7fcfa623e670dc533bb378912829c73a3593e63 (patch)
tree910119ff7293b407affa9ff34706d627d77a3a04 /internal/client/usrsx.go
downloaddborg-f7fcfa623e670dc533bb378912829c73a3593e63.tar.gz
dborg-f7fcfa623e670dc533bb378912829c73a3593e63.zip
hi
Diffstat (limited to 'internal/client/usrsx.go')
-rw-r--r--internal/client/usrsx.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/internal/client/usrsx.go b/internal/client/usrsx.go
new file mode 100644
index 0000000..456acbf
--- /dev/null
+++ b/internal/client/usrsx.go
@@ -0,0 +1,72 @@
+package client
+
+import (
+ "bufio"
+ "dborg/internal/models"
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+ "net/url"
+ "strings"
+)
+
+func (c *Client) CheckUsernameStream(params *models.USRSXParams, callback func(result json.RawMessage) error) error {
+ queryParams := url.Values{}
+
+ if len(params.Sites) > 0 {
+ queryParams.Add("sites", strings.Join(params.Sites, ","))
+ }
+ if params.Fuzzy {
+ queryParams.Add("fuzzy", "true")
+ }
+ if params.MaxTasks > 0 && params.MaxTasks != 50 {
+ queryParams.Add("max_tasks", fmt.Sprintf("%d", params.MaxTasks))
+ }
+
+ path := fmt.Sprintf("/osint/username/%s", url.PathEscape(params.Username))
+ fullURL := c.config.BaseURL + path
+ if len(queryParams) > 0 {
+ fullURL += "?" + queryParams.Encode()
+ }
+
+ req, err := http.NewRequest(http.MethodGet, fullURL, nil)
+ if err != nil {
+ return fmt.Errorf("failed to create request: %w", err)
+ }
+
+ req.Header.Set("X-API-Key", c.config.APIKey)
+ req.Header.Set("User-Agent", c.config.UserAgent)
+ req.Header.Set("Accept", "application/x-ndjson, application/json")
+
+ resp, err := c.httpClient.Do(req)
+ if err != nil {
+ return fmt.Errorf("failed to execute request: %w", err)
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode != http.StatusOK {
+ body, _ := io.ReadAll(resp.Body)
+ return fmt.Errorf("API request failed with status %d: %s", resp.StatusCode, string(body))
+ }
+
+ scanner := bufio.NewScanner(resp.Body)
+ for scanner.Scan() {
+ line := scanner.Bytes()
+ if len(line) == 0 {
+ continue
+ }
+
+ if err := callback(json.RawMessage(line)); err != nil {
+ return err
+ }
+ }
+
+ if err := scanner.Err(); err != nil {
+ if !strings.Contains(err.Error(), "context deadline exceeded") && !strings.Contains(err.Error(), "timeout") {
+ return fmt.Errorf("stream reading error: %w", err)
+ }
+ }
+
+ return nil
+}