mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Support streaming via API key (#1279)
* Support api key via url query parameter * Add api key to stream URL
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/stashapp/stash/pkg/api/urlbuilders"
|
"github.com/stashapp/stash/pkg/api/urlbuilders"
|
||||||
|
"github.com/stashapp/stash/pkg/manager/config"
|
||||||
"github.com/stashapp/stash/pkg/models"
|
"github.com/stashapp/stash/pkg/models"
|
||||||
"github.com/stashapp/stash/pkg/utils"
|
"github.com/stashapp/stash/pkg/utils"
|
||||||
)
|
)
|
||||||
@@ -78,6 +79,7 @@ func (r *sceneResolver) File(ctx context.Context, obj *models.Scene) (*models.Sc
|
|||||||
func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (*models.ScenePathsType, error) {
|
func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (*models.ScenePathsType, error) {
|
||||||
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
||||||
builder := urlbuilders.NewSceneURLBuilder(baseURL, obj.ID)
|
builder := urlbuilders.NewSceneURLBuilder(baseURL, obj.ID)
|
||||||
|
builder.APIKey = config.GetInstance().GetAPIKey()
|
||||||
screenshotPath := builder.GetScreenshotURL(obj.UpdatedAt.Timestamp)
|
screenshotPath := builder.GetScreenshotURL(obj.UpdatedAt.Timestamp)
|
||||||
previewPath := builder.GetStreamPreviewURL()
|
previewPath := builder.GetStreamPreviewURL()
|
||||||
streamPath := builder.GetStreamURL()
|
streamPath := builder.GetStreamURL()
|
||||||
|
|||||||
@@ -37,7 +37,10 @@ var uiBox *packr.Box
|
|||||||
//var legacyUiBox *packr.Box
|
//var legacyUiBox *packr.Box
|
||||||
var loginUIBox *packr.Box
|
var loginUIBox *packr.Box
|
||||||
|
|
||||||
const ApiKeyHeader = "ApiKey"
|
const (
|
||||||
|
ApiKeyHeader = "ApiKey"
|
||||||
|
ApiKeyParameter = "apikey"
|
||||||
|
)
|
||||||
|
|
||||||
func allowUnauthenticated(r *http.Request) bool {
|
func allowUnauthenticated(r *http.Request) bool {
|
||||||
return strings.HasPrefix(r.URL.Path, "/login") || r.URL.Path == "/css"
|
return strings.HasPrefix(r.URL.Path, "/login") || r.URL.Path == "/css"
|
||||||
@@ -54,6 +57,11 @@ func authenticateHandler() func(http.Handler) http.Handler {
|
|||||||
apiKey := r.Header.Get(ApiKeyHeader)
|
apiKey := r.Header.Get(ApiKeyHeader)
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
// try getting the api key as a query parameter
|
||||||
|
if apiKey == "" {
|
||||||
|
apiKey = r.URL.Query().Get(ApiKeyParameter)
|
||||||
|
}
|
||||||
|
|
||||||
if apiKey != "" {
|
if apiKey != "" {
|
||||||
// match against configured API and set userID to the
|
// match against configured API and set userID to the
|
||||||
// configured username. In future, we'll want to
|
// configured username. In future, we'll want to
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package urlbuilders
|
package urlbuilders
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -8,6 +9,7 @@ import (
|
|||||||
type SceneURLBuilder struct {
|
type SceneURLBuilder struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
SceneID string
|
SceneID string
|
||||||
|
APIKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSceneURLBuilder(baseURL string, sceneID int) SceneURLBuilder {
|
func NewSceneURLBuilder(baseURL string, sceneID int) SceneURLBuilder {
|
||||||
@@ -18,7 +20,11 @@ func NewSceneURLBuilder(baseURL string, sceneID int) SceneURLBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b SceneURLBuilder) GetStreamURL() string {
|
func (b SceneURLBuilder) GetStreamURL() string {
|
||||||
return b.BaseURL + "/scene/" + b.SceneID + "/stream"
|
var apiKeyParam string
|
||||||
|
if b.APIKey != "" {
|
||||||
|
apiKeyParam = fmt.Sprintf("?apikey=%s", b.APIKey)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s/scene/%s/stream%s", b.BaseURL, b.SceneID, apiKeyParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b SceneURLBuilder) GetStreamPreviewURL() string {
|
func (b SceneURLBuilder) GetStreamPreviewURL() string {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
* Added scene queue.
|
* Added scene queue.
|
||||||
|
|
||||||
### 🎨 Improvements
|
### 🎨 Improvements
|
||||||
|
* Support API key via URL query parameter, and added API key to stream link in Scene File Info.
|
||||||
* Revamped setup wizard and migration UI.
|
* Revamped setup wizard and migration UI.
|
||||||
* Add various `count` filter criteria and sort options.
|
* Add various `count` filter criteria and sort options.
|
||||||
* Scroll to top when changing page number.
|
* Scroll to top when changing page number.
|
||||||
|
|||||||
Reference in New Issue
Block a user