stash/internal/api/resolver_query_job.go
dev-null-life f920bd8b8e
Fix WebSocket UTF-8 error for non-UTF-8 file paths in subscriptions (#6810)
* Fix WebSocket UTF-8 error for non-UTF-8 file paths in subscriptions

Sanitize log messages and job fields (description, subtasks, error)
before sending over WebSocket. File paths with non-UTF-8 characters
caused the browser to close the connection with "Could not decode a
text frame as UTF-8." Invalid bytes are replaced with U+FFFD.

Only the API response layer is affected — underlying stored data is
unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Replace direct ToValidUTF8 calls to new sanitiseWebsocketString function
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2026-04-10 13:42:42 +10:00

63 lines
1.2 KiB
Go

package api
import (
"context"
"strconv"
"github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/job"
)
func (r *queryResolver) JobQueue(ctx context.Context) ([]*Job, error) {
queue := manager.GetInstance().JobManager.GetQueue()
var ret []*Job
for _, j := range queue {
ret = append(ret, jobToJobModel(j))
}
return ret, nil
}
func (r *queryResolver) FindJob(ctx context.Context, input FindJobInput) (*Job, error) {
jobID, err := strconv.Atoi(input.ID)
if err != nil {
return nil, err
}
j := manager.GetInstance().JobManager.GetJob(jobID)
if j == nil {
return nil, nil
}
return jobToJobModel(*j), nil
}
func jobToJobModel(j job.Job) *Job {
subTasks := make([]string, len(j.Details))
for i, t := range j.Details {
subTasks[i] = sanitiseWebsocketString(t)
}
var jobError *string
if j.Error != nil {
s := sanitiseWebsocketString(*j.Error)
jobError = &s
}
ret := &Job{
ID: strconv.Itoa(j.ID),
Status: JobStatus(j.Status),
Description: sanitiseWebsocketString(j.Description),
SubTasks: subTasks,
StartTime: j.StartTime,
EndTime: j.EndTime,
AddTime: j.AddTime,
Error: jobError,
}
if j.Progress != -1 {
ret.Progress = &j.Progress
}
return ret
}