mirror of
https://github.com/icereed/paperless-gpt.git
synced 2025-03-13 13:18:02 -05:00
Fix tags API pagination
This commit is contained in:
parent
31f0e81465
commit
0dd1d0b5ad
2 changed files with 36 additions and 28 deletions
61
main.go
61
main.go
|
@ -165,40 +165,47 @@ func createLLM() (llms.Model, error) {
|
|||
}
|
||||
|
||||
func getAllTags(ctx context.Context, baseURL, apiToken string) (map[string]int, error) {
|
||||
tagIDMapping := make(map[string]int)
|
||||
url := fmt.Sprintf("%s/api/tags/", baseURL)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Token %s", apiToken))
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("Error fetching tags: %d, %s", resp.StatusCode, string(bodyBytes))
|
||||
}
|
||||
for url != "" {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Token %s", apiToken))
|
||||
|
||||
var tagsResponse struct {
|
||||
Results []struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"results"`
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&tagsResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("Error fetching tags: %d, %s", resp.StatusCode, string(bodyBytes))
|
||||
}
|
||||
|
||||
tagIDMapping := make(map[string]int)
|
||||
for _, tag := range tagsResponse.Results {
|
||||
tagIDMapping[tag.Name] = tag.ID
|
||||
var tagsResponse struct {
|
||||
Results []struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
} `json:"results"`
|
||||
Next string `json:"next"`
|
||||
}
|
||||
|
||||
err = json.NewDecoder(resp.Body).Decode(&tagsResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tag := range tagsResponse.Results {
|
||||
tagIDMapping[tag.Name] = tag.ID
|
||||
}
|
||||
|
||||
url = tagsResponse.Next
|
||||
}
|
||||
|
||||
return tagIDMapping, nil
|
||||
|
|
|
@ -17,6 +17,7 @@ const SuggestionCard: React.FC<SuggestionCardProps> = ({
|
|||
onTagAddition,
|
||||
onTagDeletion,
|
||||
}) => {
|
||||
const sortedAvailableTags = availableTags.sort((a, b) => a.name.localeCompare(b.name));
|
||||
const document = suggestion.original_document;
|
||||
return (
|
||||
<div className="bg-white dark:bg-gray-800 shadow-lg shadow-blue-500/50 rounded-md p-4 relative flex flex-col justify-between h-full">
|
||||
|
@ -64,7 +65,7 @@ const SuggestionCard: React.FC<SuggestionCardProps> = ({
|
|||
value: index.toString(),
|
||||
})) || []
|
||||
}
|
||||
suggestions={availableTags.map((tag) => ({
|
||||
suggestions={sortedAvailableTags.map((tag) => ({
|
||||
id: tag.id,
|
||||
name: tag.name,
|
||||
label: tag.name,
|
||||
|
|
Loading…
Reference in a new issue