mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 03:26:37 +08:00
b0fe40142a
* Rebrand MMTL to MeBox across codebase and assets Rename the project display name, Go module path, environment variable prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl to MeBox/mebox. Replace logo assets with the new MeBox icon and keep legacy SQLite migration support for existing mmtl.db deployments. Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Fix logo icons: use cube-only crop without truncated text Previous icon generation cropped too much of the source image, including partial MeBox wordmark text that was cut off in square icon containers. Regenerate logo-64/192/512, favicon, and SVG from cube-only region. Co-authored-by: truewhile <truewhile@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: truewhile <truewhile@users.noreply.github.com>
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package service
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/truewhile/MeBox/internal/model"
|
|
)
|
|
|
|
// PlayProfileInput is the create/update payload accepted by the API.
|
|
// PIN is hashed only when non-empty so omitting it preserves the existing PIN on update.
|
|
type PlayProfileInput struct {
|
|
UserID string `json:"user_id"`
|
|
Name string `json:"name"`
|
|
IsDefault bool `json:"is_default"`
|
|
ContentRatingLimit string `json:"content_rating_limit"`
|
|
AllowAdult bool `json:"allow_adult"`
|
|
RequirePIN bool `json:"require_pin"`
|
|
PIN string `json:"pin,omitempty"`
|
|
PreferredSubtitleLang string `json:"preferred_subtitle_lang"`
|
|
PreferredAudioLang string `json:"preferred_audio_lang"`
|
|
AutoplayNext bool `json:"autoplay_next"`
|
|
SkipIntro bool `json:"skip_intro"`
|
|
AllowedLibraryIDs []string `json:"allowed_library_ids"`
|
|
}
|
|
|
|
// ProfileView is the public shape for React forms.
|
|
type ProfileView struct {
|
|
model.PlayProfile
|
|
AllowedLibraryIDs []string `json:"allowed_library_ids"`
|
|
}
|
|
|
|
func toProfileView(p model.PlayProfile) ProfileView {
|
|
v := ProfileView{PlayProfile: p}
|
|
if p.AllowedLibraryIDs != "" {
|
|
_ = json.Unmarshal([]byte(p.AllowedLibraryIDs), &v.AllowedLibraryIDs)
|
|
}
|
|
if v.AllowedLibraryIDs == nil {
|
|
v.AllowedLibraryIDs = []string{}
|
|
}
|
|
return v
|
|
}
|
|
|
|
func validateProfileInput(in PlayProfileInput, requireUser bool) error {
|
|
if strings.TrimSpace(in.Name) == "" {
|
|
return fmt.Errorf("%w: name required", ErrPlayProfileValidation)
|
|
}
|
|
if requireUser && strings.TrimSpace(in.UserID) == "" {
|
|
return fmt.Errorf("%w: user_id required", ErrPlayProfileValidation)
|
|
}
|
|
if requireUser && in.RequirePIN && strings.TrimSpace(in.PIN) == "" {
|
|
return fmt.Errorf("%w: pin required", ErrPlayProfileValidation)
|
|
}
|
|
if in.RequirePIN && in.PIN != "" {
|
|
if len(in.PIN) < 4 || len(in.PIN) > 8 {
|
|
return fmt.Errorf("%w: pin must be 4-8 characters", ErrPlayProfileValidation)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func hashPIN(pin string) string {
|
|
sum := sha256.Sum256([]byte(pin))
|
|
return hex.EncodeToString(sum[:])
|
|
}
|