Restore shared media metadata contract
This commit is contained in:
1 parent
356b43b59e
commit
a348409993
3 files changed
+49
-18
No files matched your search
@@ -505,6 +505,11 @@ type ProbeResult struct {
|
|||||||
DurationMs int64 `json:"durationMs"`
|
DurationMs int64 `json:"durationMs"`
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
Height int `json:"height"`
|
Height int `json:"height"`
|
||||||
|
IsVR bool `json:"isVr"`
|
||||||
|
// Pointers keep the distinction between a newer CarrierNode explicitly
|
||||||
|
// reporting false and an older one that does not return these fields yet.
|
||||||
|
HasVideo *bool `json:"hasVideo"`
|
||||||
|
HasAudio *bool `json:"hasAudio"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) probeMediaOne(ctx context.Context, baseURL, relative string) (ProbeResult, error) {
|
func (c *Client) probeMediaOne(ctx context.Context, baseURL, relative string) (ProbeResult, error) {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
|
|
||||||
sharedauth "repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
|
sharedauth "repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
|
||||||
@@ -152,22 +153,25 @@ func (c *Core) putSyncState(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// MediaRecord is one row of the shared `media` table.
|
// MediaRecord is one row of the shared `media` table.
|
||||||
type MediaRecord struct {
|
type MediaRecord struct {
|
||||||
ID int64
|
ID int64
|
||||||
MediaKey string
|
MediaKey string
|
||||||
MediaType string
|
MediaType string
|
||||||
Title *string
|
Title *string
|
||||||
Description *string
|
Description *string
|
||||||
FilePath string
|
FilePath string
|
||||||
OriginalName string
|
OriginalName string
|
||||||
Source string
|
Source string
|
||||||
Width *int
|
Width *int
|
||||||
Height *int
|
Height *int
|
||||||
DurationMs *int64
|
DurationMs *int64
|
||||||
SizeBytes *int64
|
SizeBytes *int64
|
||||||
IsVR bool
|
IsVR bool
|
||||||
HasFunscript bool
|
HasFunscript bool
|
||||||
Speed *float32
|
FunscriptActionCount *int
|
||||||
ModifiedAt time.Time
|
FunscriptAvgSpeed *float32
|
||||||
|
FunscriptMaxSpeed *float32
|
||||||
|
Speed *float32
|
||||||
|
ModifiedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) streamMediaByQuery(w http.ResponseWriter, r *http.Request) {
|
func (c *Core) streamMediaByQuery(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -725,15 +729,30 @@ func (c *Core) findMedia(ctx context.Context, identifier string) (MediaRecord, e
|
|||||||
SELECT id, media_key, COALESCE(media_type, 'unknown'), COALESCE(title, ''), COALESCE(description, ''),
|
SELECT id, media_key, COALESCE(media_type, 'unknown'), COALESCE(title, ''), COALESCE(description, ''),
|
||||||
COALESCE(NULLIF(file_path, ''), media_key), COALESCE(original_filename, ''), COALESCE(source, 'Filesystem'),
|
COALESCE(NULLIF(file_path, ''), media_key), COALESCE(original_filename, ''), COALESCE(source, 'Filesystem'),
|
||||||
COALESCE(width, 0), COALESCE(height, 0), COALESCE(duration_ms, 0), COALESCE(size_bytes, 0),
|
COALESCE(width, 0), COALESCE(height, 0), COALESCE(duration_ms, 0), COALESCE(size_bytes, 0),
|
||||||
COALESCE(is_vr, FALSE), COALESCE(has_funscript, FALSE), COALESCE(speed, 0), COALESCE(modified_at, created_at)
|
COALESCE(is_vr, FALSE), COALESCE(has_funscript, FALSE), funscript_action_count,
|
||||||
|
funscript_avg_speed, funscript_max_speed, COALESCE(speed, 0), COALESCE(modified_at, created_at)
|
||||||
FROM media WHERE media_key=$1 OR CAST(id AS TEXT)=$1 LIMIT 1`, identifier)
|
FROM media WHERE media_key=$1 OR CAST(id AS TEXT)=$1 LIMIT 1`, identifier)
|
||||||
var title, description string
|
var title, description string
|
||||||
var width, height int
|
var width, height int
|
||||||
var duration, size int64
|
var duration, size int64
|
||||||
|
var funscriptActionCount pgtype.Int4
|
||||||
|
var funscriptAvgSpeed, funscriptMaxSpeed pgtype.Float4
|
||||||
var speed float32
|
var speed float32
|
||||||
if err := row.Scan(&record.ID, &record.MediaKey, &record.MediaType, &title, &description, &record.FilePath, &record.OriginalName, &record.Source, &width, &height, &duration, &size, &record.IsVR, &record.HasFunscript, &speed, &record.ModifiedAt); err != nil {
|
if err := row.Scan(&record.ID, &record.MediaKey, &record.MediaType, &title, &description, &record.FilePath, &record.OriginalName, &record.Source, &width, &height, &duration, &size, &record.IsVR, &record.HasFunscript, &funscriptActionCount, &funscriptAvgSpeed, &funscriptMaxSpeed, &speed, &record.ModifiedAt); err != nil {
|
||||||
return MediaRecord{}, err
|
return MediaRecord{}, err
|
||||||
}
|
}
|
||||||
|
if funscriptActionCount.Valid {
|
||||||
|
value := int(funscriptActionCount.Int32)
|
||||||
|
record.FunscriptActionCount = &value
|
||||||
|
}
|
||||||
|
if funscriptAvgSpeed.Valid {
|
||||||
|
value := funscriptAvgSpeed.Float32
|
||||||
|
record.FunscriptAvgSpeed = &value
|
||||||
|
}
|
||||||
|
if funscriptMaxSpeed.Valid {
|
||||||
|
value := funscriptMaxSpeed.Float32
|
||||||
|
record.FunscriptMaxSpeed = &value
|
||||||
|
}
|
||||||
if title != "" {
|
if title != "" {
|
||||||
record.Title = &title
|
record.Title = &title
|
||||||
}
|
}
|
||||||
@@ -778,6 +797,7 @@ func (record MediaRecord) ToJSON() map[string]any {
|
|||||||
"url": mediaStreamURL(record.MediaKey), "thumbnail": mediaThumbnailURL(record.MediaKey),
|
"url": mediaStreamURL(record.MediaKey), "thumbnail": mediaThumbnailURL(record.MediaKey),
|
||||||
"width": intValue(record.Width), "height": intValue(record.Height), "durationMs": int64Value(record.DurationMs),
|
"width": intValue(record.Width), "height": intValue(record.Height), "durationMs": int64Value(record.DurationMs),
|
||||||
"sizeBytes": int64Value(record.SizeBytes), "isVr": record.IsVR, "hasFunscript": record.HasFunscript, "speed": floatValue(record.Speed),
|
"sizeBytes": int64Value(record.SizeBytes), "isVr": record.IsVR, "hasFunscript": record.HasFunscript, "speed": floatValue(record.Speed),
|
||||||
|
"funscriptActionCount": intValue(record.FunscriptActionCount), "funscriptAvgSpeed": floatValue(record.FunscriptAvgSpeed), "funscriptMaxSpeed": floatValue(record.FunscriptMaxSpeed),
|
||||||
"modifiedAt": record.ModifiedAt,
|
"modifiedAt": record.ModifiedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,10 +73,16 @@ var migrationStatements = []string{
|
|||||||
size_bytes BIGINT,
|
size_bytes BIGINT,
|
||||||
is_vr BOOLEAN NOT NULL DEFAULT FALSE,
|
is_vr BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
has_funscript BOOLEAN NOT NULL DEFAULT FALSE,
|
has_funscript BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
funscript_action_count INT,
|
||||||
|
funscript_avg_speed REAL,
|
||||||
|
funscript_max_speed REAL,
|
||||||
speed REAL,
|
speed REAL,
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
modified_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||||
)`,
|
)`,
|
||||||
|
`ALTER TABLE media ADD COLUMN IF NOT EXISTS funscript_action_count INT`,
|
||||||
|
`ALTER TABLE media ADD COLUMN IF NOT EXISTS funscript_avg_speed REAL`,
|
||||||
|
`ALTER TABLE media ADD COLUMN IF NOT EXISTS funscript_max_speed REAL`,
|
||||||
`CREATE INDEX IF NOT EXISTS media_active_idx ON media (active)`,
|
`CREATE INDEX IF NOT EXISTS media_active_idx ON media (active)`,
|
||||||
`CREATE INDEX IF NOT EXISTS media_file_path_idx ON media (file_path)`,
|
`CREATE INDEX IF NOT EXISTS media_file_path_idx ON media (file_path)`,
|
||||||
`CREATE INDEX IF NOT EXISTS media_search_idx ON media USING GIN (to_tsvector('simple', COALESCE(title, '') || ' ' || COALESCE(original_filename, '') || ' ' || COALESCE(file_path, '')))`,
|
`CREATE INDEX IF NOT EXISTS media_search_idx ON media USING GIN (to_tsvector('simple', COALESCE(title, '') || ' ' || COALESCE(original_filename, '') || ' ' || COALESCE(file_path, '')))`,
|
||||||
|
|||||||
Reference in new issue
Block a user