From 8ebd790651218fe2e6b2430932d6721f59ab1f24 Mon Sep 17 00:00:00 2001 From: odrling Date: Wed, 4 Dec 2024 17:59:51 +0100 Subject: [PATCH] server|ui: add private field to karas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit so we can tag karas that should not be exported to mugen, and which won’t be downloadable through basic auth. not necessarily the best UX but now it exists #53 --- server/kara.go | 2 ++ server/model.go | 5 +++++ server/upload.go | 5 +++++ ui/src/components/KaraEditor.tsx | 22 +++++++++++++++++++--- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/server/kara.go b/server/kara.go index 776bfd44..5bcbbbee 100644 --- a/server/kara.go +++ b/server/kara.go @@ -43,6 +43,7 @@ type KaraInfo struct { Language string `json:"language" example:"FR"` KaraokeCreationDate *int64 `json:"karaoke_creation_time,omitempty" example:"42"` IsHardsub *bool `json:"is_hardsub,omitempty" example:"false"` + Private bool `json:"private,omitempty" example:"false"` } type AllTags struct { @@ -132,6 +133,7 @@ func (info KaraInfo) to_KaraInfoDB(ctx context.Context, tx *gorm.DB, kara_info * kara_info.Version = info.Version kara_info.SongOrder = info.SongOrder kara_info.Language = info.Language + kara_info.Private = info.Private user := *getCurrentUser(ctx) if user.Admin { diff --git a/server/model.go b/server/model.go index ac3c9dbe..0487d752 100644 --- a/server/model.go +++ b/server/model.go @@ -326,6 +326,7 @@ type KaraInfoDB struct { Medias []MediaDB `gorm:"many2many:kara_media_tags"` Title string ExtraTitles []AdditionalName `gorm:"many2many:kara_info_additional_name"` + Private bool Version string Comment string SongOrder uint @@ -389,6 +390,10 @@ func isAssociationsUpdate(tx *gorm.DB) bool { func UploadHookGitlab(tx *gorm.DB, ki *KaraInfoDB) error { if CONFIG.Mugen.Gitlab.IsSetup() { + if ki.Private { + return nil + } + // check if kara is an import mugen_import := &MugenImport{} err := tx.Where(&MugenImport{KaraID: ki.ID}).First(mugen_import).Error diff --git a/server/upload.go b/server/upload.go index 4e0a79b3..c816fc90 100644 --- a/server/upload.go +++ b/server/upload.go @@ -361,6 +361,11 @@ func DownloadFile(ctx context.Context, input *DownloadInput) (*huma.StreamRespon return nil, err } + if kara.Private && getCurrentUser(ctx) == nil { + // return forbidden response for private karas for external users + return nil, huma.Error403Forbidden("private kara") + } + obj, err := GetKaraObject(ctx, kara, input.FileType) if err != nil { return nil, err diff --git a/ui/src/components/KaraEditor.tsx b/ui/src/components/KaraEditor.tsx index e19e753c..f4d92572 100644 --- a/ui/src/components/KaraEditor.tsx +++ b/ui/src/components/KaraEditor.tsx @@ -84,6 +84,7 @@ export default function KaraEditor(props: { const [getComment, setComment] = createSignal(props.kara?.Comment ?? ""); const [getVersion, setVersion] = createSignal(props.kara?.Version ?? ""); const [getLanguage, setLanguage] = createSignal(props.kara?.Language ?? ""); + const [getPrivate, setPrivate] = createSignal(props.kara?.Private ?? false); //#endregion //#region Handlers @@ -104,6 +105,7 @@ export default function KaraEditor(props: { comment: getComment(), version: getVersion(), language: getLanguage(), + private: getPrivate(), }); if (props.reset) { (e.target as HTMLFormElement).reset(); @@ -430,6 +432,19 @@ export default function KaraEditor(props: { /> ); + const privateInput = () => ( + + ); const languageInput = () => (