Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ type Query {
): Directory!
validateStashBoxCredentials(input: StashBoxInput!): StashBoxValidationResult!

# Validate remote CDP path
ValidateCDPPath: CDPValidationResult!
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be good to accept an input parameter here so that users can test before saving? Currently you cant test and it just saves regardless of it it is correct or not.

Should also do camel case here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debated doing that as well


# System status
systemStatus: SystemStatus!

Expand Down
5 changes: 5 additions & 0 deletions graphql/schema/types/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,8 @@ type StashBoxValidationResult {
valid: Boolean!
status: String!
}

type CDPValidationResult {
valid: Boolean!
status: String!
}
15 changes: 15 additions & 0 deletions internal/api/resolver_query_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scraper"
"golang.org/x/text/collate"
)

Expand Down Expand Up @@ -285,3 +286,17 @@ func (r *queryResolver) ValidateStashBoxCredentials(ctx context.Context, input c

return &result, nil
}

func (r *queryResolver) ValidateCDPPath(ctx context.Context) (*CDPValidationResult, error) {
err := scraper.TestRemoteCDP(config.GetInstance())
if err == nil {
return &CDPValidationResult{
Valid: true,
Status: "Successfully validated CDP path",
}, nil
}
return &CDPValidationResult{
Valid: false,
Status: err.Error(),
}, nil
}
16 changes: 16 additions & 0 deletions pkg/scraper/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,19 @@ func splitProxyAuth(proxyUrl string) (string, string, string) {

return proxyUrl, "", ""
}

func TestRemoteCDP(globalConfig GlobalConfig) error {
cdpPath := globalConfig.GetScraperCDPPath()
if cdpPath == "" {
return fmt.Errorf("CDP path is empty")
}
if !isCDPPathHTTP(globalConfig) {
// unable to test non-http CDP
return fmt.Errorf("Unable to test non-http CDP paths")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, should this be an error? I'm not sure on this one but it seems to me that the path could be valid but just not tested. It would return valid:false then spit the error out to the user. It could be misleading because it's not technically an error just not tested.

Perhaps it should be info level or something unless it's actually invalid.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the current way to fetch it, it cant handle it. We would need to do an actual xpath scrape to validate PATHs.

}
_, err := getRemoteCDPWSAddress(context.Background(), cdpPath)
if err != nil {
return fmt.Errorf("Failed to get remote CDP websocket address: %v", err)
}
return nil
}
7 changes: 7 additions & 0 deletions ui/v2.5/graphql/queries/settings/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ query ValidateStashBox($input: StashBoxInput!) {
status
}
}

query ValidateCDP {
ValidateCDPPath {
valid
status
}
}
Loading