Skip to content

Commit

Permalink
server|ui: add private field to karas
Browse files Browse the repository at this point in the history
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
  • Loading branch information
odrling committed Dec 4, 2024
1 parent 7c360e4 commit 8ebd790
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/kara.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions server/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions server/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 19 additions & 3 deletions ui/src/components/KaraEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -430,6 +432,19 @@ export default function KaraEditor(props: {
/>
</label>
);
const privateInput = () => (
<label>
<div class="label">
<span class="label-text">Private kara (won’t be exported)</span>
</div>
<input
type="checkbox"
checked={getPrivate()}
onchange={(e) => setPrivate(e.currentTarget.checked)}
class="checkbox"
/>
</label>
);
const languageInput = () => (
<label>
<div class="label">
Expand All @@ -451,9 +466,10 @@ export default function KaraEditor(props: {
<div class="grid md:grid-cols-2 gap-4">
<div class="card bg-base-100 shadow-xl">
<div class="card-body">
<h2 class="card-title">Titles</h2>
<h2 class="card-title">General information</h2>
{titleInput()}
{extraTitlesInput()}
{versionInput()}
</div>
</div>
<div class="card bg-base-100 shadow-xl">
Expand Down Expand Up @@ -481,10 +497,10 @@ export default function KaraEditor(props: {
</div>
<div class="card bg-base-100 shadow-xl md:row-start-1 md:col-start-2">
<div class="card-body">
<h2 class="card-title">Additional informations</h2>
<h2 class="card-title">Author informations</h2>
{authorsInput()}
{commentInput()}
{versionInput()}
{privateInput()}
</div>
</div>
</div>
Expand Down

0 comments on commit 8ebd790

Please sign in to comment.