feat: extend media library controls and playback
- Add safe CarrierNode media deletion and rating support - Count tag suggestions across visible, processed media - Support muted autoplay in MediaPlayer
This commit is contained in:
1 parent
5d9e3063c5
commit
0c4dc3aacb
5 files changed
+161
-4
No files matched your search
@@ -117,6 +117,7 @@ type MediaRecord struct {
|
||||
FunscriptMaxSpeed *float32
|
||||
Speed *float32
|
||||
ModifiedAt time.Time
|
||||
Rating string
|
||||
}
|
||||
|
||||
func (c *Service) streamMediaByQuery(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -440,7 +441,16 @@ func (c *Service) tagSuggestions(w http.ResponseWriter, r *http.Request) {
|
||||
if value := r.URL.Query().Get("limit"); value != "" {
|
||||
limit = optionalInt(value, 50, 1, math.MaxInt)
|
||||
}
|
||||
rows, err := c.db.Query(r.Context(), `SELECT tag, COUNT(*) AS frequency FROM media_tags GROUP BY tag ORDER BY frequency DESC, LOWER(tag) LIMIT $1`, limit)
|
||||
// Match the library's visibility rules and count media items rather than tag rows:
|
||||
// a tag can have contributions from multiple users, and old tags may outlive media.
|
||||
rows, err := c.db.Query(r.Context(), `
|
||||
SELECT MIN(mt.tag) AS tag, COUNT(DISTINCT m.media_key) AS frequency
|
||||
FROM media_tags mt
|
||||
JOIN media m ON m.media_key = mt.media_key
|
||||
WHERE m.active = TRUE AND m.content_scanner_processed = TRUE
|
||||
GROUP BY LOWER(mt.tag)
|
||||
ORDER BY frequency DESC, LOWER(MIN(mt.tag))
|
||||
LIMIT $1`, limit)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"tags": []any{}})
|
||||
return
|
||||
@@ -779,7 +789,8 @@ func (c *Service) FindMedia(ctx context.Context, identifier string, options Medi
|
||||
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(is_vr, FALSE), COALESCE(has_funscript, FALSE), funscript_action_count,
|
||||
funscript_avg_speed, funscript_max_speed, COALESCE(speed, 0), COALESCE(modified_at, created_at)
|
||||
funscript_avg_speed, funscript_max_speed, COALESCE(speed, 0), COALESCE(modified_at, created_at),
|
||||
COALESCE(rating, '')
|
||||
FROM media WHERE (media_key=$1 OR id=$2) AND (active OR $3) AND (NOT $4 OR content_scanner_processed) LIMIT 1`,
|
||||
identifier, mediaIDArg(identifier), options.IncludeHidden, options.RequireContentScannerProcessed)
|
||||
var title, description string
|
||||
@@ -788,7 +799,7 @@ func (c *Service) FindMedia(ctx context.Context, identifier string, options Medi
|
||||
var funscriptActionCount pgtype.Int4
|
||||
var funscriptAvgSpeed, funscriptMaxSpeed pgtype.Float4
|
||||
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, &funscriptActionCount, &funscriptAvgSpeed, &funscriptMaxSpeed, &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, &record.Rating); err != nil {
|
||||
return MediaRecord{}, err
|
||||
}
|
||||
if funscriptActionCount.Valid {
|
||||
@@ -846,7 +857,7 @@ func (record MediaRecord) ToJSON() map[string]any {
|
||||
if mediaType == "unknown" || mediaType == "" {
|
||||
mediaType = InferMediaType(filename)
|
||||
}
|
||||
return map[string]any{
|
||||
result := map[string]any{
|
||||
"id": record.MediaKey, "numericId": record.ID, "mediaKey": record.MediaKey,
|
||||
"filename": filename, "name": filename, "title": record.Title, "description": record.Description,
|
||||
"relPath": urlPath(record.FilePath), "mediaType": mediaType, "source": record.Source,
|
||||
@@ -856,6 +867,10 @@ func (record MediaRecord) ToJSON() map[string]any {
|
||||
"funscriptActionCount": intValue(record.FunscriptActionCount), "funscriptAvgSpeed": floatValue(record.FunscriptAvgSpeed), "funscriptMaxSpeed": floatValue(record.FunscriptMaxSpeed),
|
||||
"modifiedAt": record.ModifiedAt,
|
||||
}
|
||||
if record.Rating != "" {
|
||||
result["rating"] = record.Rating
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// --- path-safety helpers (generic, no Core dependency) ---
|
||||
|
||||
Reference in new issue
Block a user