refactor: use errors.New for static error strings
This commit is contained in:
@@ -2,7 +2,7 @@ package allanime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"errors"
|
||||||
"mal/internal/domain"
|
"mal/internal/domain"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -48,17 +48,17 @@ func (c *AllAnimeProvider) GetAvailableEpisodes(ctx context.Context, showID stri
|
|||||||
|
|
||||||
data, ok := result["data"].(map[string]any)
|
data, ok := result["data"].(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return AvailableEpisodes{}, fmt.Errorf("invalid response")
|
return AvailableEpisodes{}, errors.New("invalid response")
|
||||||
}
|
}
|
||||||
|
|
||||||
show, ok := data["show"].(map[string]any)
|
show, ok := data["show"].(map[string]any)
|
||||||
if !ok || show == nil {
|
if !ok || show == nil {
|
||||||
return AvailableEpisodes{}, fmt.Errorf("show not found")
|
return AvailableEpisodes{}, errors.New("show not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
detail, ok := show["availableEpisodesDetail"].(map[string]any)
|
detail, ok := show["availableEpisodesDetail"].(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return AvailableEpisodes{}, fmt.Errorf("invalid detail")
|
return AvailableEpisodes{}, errors.New("invalid detail")
|
||||||
}
|
}
|
||||||
|
|
||||||
return AvailableEpisodes{
|
return AvailableEpisodes{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -21,7 +22,7 @@ func decryptTobeparsed(encoded string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(raw) < 29 {
|
if len(raw) < 29 {
|
||||||
return nil, fmt.Errorf("encrypted payload too short")
|
return nil, errors.New("encrypted payload too short")
|
||||||
}
|
}
|
||||||
|
|
||||||
version := raw[0]
|
version := raw[0]
|
||||||
@@ -54,7 +55,7 @@ func decryptTobeparsed(encoded string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("decryption failed")
|
return nil, errors.New("decryption failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryDecryptCTR(block cipher.Block, iv []byte, cipherText []byte) []byte {
|
func tryDecryptCTR(block cipher.Block, iv []byte, cipherText []byte) []byte {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package allanime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -41,28 +42,28 @@ func (c *AllAnimeProvider) GetEpisodeSources(ctx context.Context, showID string,
|
|||||||
|
|
||||||
data, ok := result["data"].(map[string]any)
|
data, ok := result["data"].(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("invalid source response")
|
return nil, errors.New("invalid source response")
|
||||||
}
|
}
|
||||||
|
|
||||||
rawSourceURLs, ok := data["episode"].(map[string]any)
|
rawSourceURLs, ok := data["episode"].(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("invalid episode response")
|
return nil, errors.New("invalid episode response")
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceURLs, ok := rawSourceURLs["sourceUrls"].([]any)
|
sourceURLs, ok := rawSourceURLs["sourceUrls"].([]any)
|
||||||
if !ok || len(sourceURLs) == 0 {
|
if !ok || len(sourceURLs) == 0 {
|
||||||
return nil, fmt.Errorf("no source urls")
|
return nil, errors.New("no source urls")
|
||||||
}
|
}
|
||||||
|
|
||||||
references := buildSourceReferences(sourceURLs)
|
references := buildSourceReferences(sourceURLs)
|
||||||
if len(references) == 0 {
|
if len(references) == 0 {
|
||||||
return nil, fmt.Errorf("no source references")
|
return nil, errors.New("no source references")
|
||||||
}
|
}
|
||||||
|
|
||||||
out := c.resolveSourceReferences(ctx, references)
|
out := c.resolveSourceReferences(ctx, references)
|
||||||
|
|
||||||
if len(out) == 0 {
|
if len(out) == 0 {
|
||||||
return nil, fmt.Errorf("no playable sources extracted")
|
return nil, errors.New("no playable sources extracted")
|
||||||
}
|
}
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
@@ -261,7 +262,7 @@ func (c *AllAnimeProvider) graphqlRequestWithHash(ctx context.Context, showID, e
|
|||||||
|
|
||||||
data, ok := parsed["data"].(map[string]any)
|
data, ok := parsed["data"].(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("no data in response")
|
return nil, errors.New("no data in response")
|
||||||
}
|
}
|
||||||
|
|
||||||
decrypted, err := responseFromTobeparsed(data)
|
decrypted, err := responseFromTobeparsed(data)
|
||||||
@@ -276,7 +277,7 @@ func (c *AllAnimeProvider) graphqlRequestWithHash(ctx context.Context, showID, e
|
|||||||
return parsed, nil
|
return parsed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("no usable data in response")
|
return nil, errors.New("no usable data in response")
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEpisodeHashRequest(ctx context.Context, showID, episode, mode string) (*http.Request, error) {
|
func newEpisodeHashRequest(ctx context.Context, showID, episode, mode string) (*http.Request, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user