Skip to content

Commit

Permalink
website: work on the song submission page
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Jan 28, 2024
1 parent 8f7d306 commit 6274d2c
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 35 deletions.
28 changes: 28 additions & 0 deletions radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,13 @@ type SubmissionStorageService interface {
SubmissionsTx(context.Context, StorageTx) (SubmissionStorage, StorageTx, error)
}

func CalculateSubmissionCooldown(t time.Time) time.Duration {
if time.Since(t) > time.Hour {
return 0
}
return (time.Hour) - time.Since(t)
}

// SubmissionStorage stores stuff related to the reviewing of submissions
// and associated information
type SubmissionStorage interface {
Expand All @@ -800,6 +807,27 @@ type SubmissionStorage interface {
// UpdateSubmissionTime updates the last submission time to the current time
// for the identifier given
UpdateSubmissionTime(identifier string) error
// SubmissionStats returns the submission stats for the identifier given.
SubmissionStats(identifier string) (SubmissionStats, error)
}

type SubmissionStats struct {
// Amount of submissions in the pending queue
CurrentPending int `db:"current_pending"`
// Information about accepted songs
AcceptedTotal int `db:"accepted_total"`
AcceptedLastTwoWeeks int `db:"accepted_last_two_weeks"`
AcceptedYou int `db:"accepted_you"`
RecentAccepts []Song

// Information about declined songs
DeclinedTotal int `db:"declined_total"`
DeclinedLastTwoWeeks int `db:"declined_last_two_weeks"`
DeclinedYou int `db:"declined_you"`
RecentDeclines []PendingSong

// Information about (You)
LastSubmissionTime time.Time `db:"last_submission_time"`
}

// SubmissionID is the ID of a pending song
Expand Down
42 changes: 42 additions & 0 deletions storage/mariadb/submissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"time"

radio "github.com/R-a-dio/valkyrie"
"github.com/R-a-dio/valkyrie/errors"
"github.com/jmoiron/sqlx"
)
Expand Down Expand Up @@ -52,3 +53,44 @@ func (ss SubmissionStorage) UpdateSubmissionTime(identifier string) error {
}
return nil
}

func (ss SubmissionStorage) SubmissionStats(identifier string) (radio.SubmissionStats, error) {
const op errors.Op = "mariadb/SubmissionStorage.SubmissionStats"

var stats radio.SubmissionStats

var input = struct {
Identifier string
}{
Identifier: identifier,
}

query := `
SELECT
(SELECT count(*) FROM pending) AS current_pending,
IFNULL(SUM(accepted >= 0), 0) AS accepted_total,
IFNULL(SUM(accepted >= 0 && time > DATE_SUB(NOW(), INTERVAL 2 WEEK)), 0) AS accepted_last_two_weeks,
IFNULL(SUM(accepted >= 0 && ip=:identifier), 0) AS accepted_you,
IFNULL(SUM(accepted = 0), 0) AS declined_total,
IFNULL(SUM(accepted = 0 && time > DATE_SUB(NOW(), INTERVAL 2 WEEK)), 0) AS declined_last_two_weeks,
IFNULL(SUM(accepted = 0 && ip=:identifier), 0) AS declined_you,
COALESCE((SELECT time FROM uploadtime WHERE ip=:identifier ORDER BY time DESC LIMIT 1), TIMESTAMP('0000-00-00 00::00::00')) AS last_submission_time
FROM postpending;
`

rows, err := sqlx.NamedQuery(ss.handle, query, input)
if err != nil {
return stats, errors.E(op, err)
}
defer rows.Close()

if !rows.Next() {
return stats, errors.E(op, sql.ErrNoRows)
}

if err = rows.StructScan(&stats); err != nil {
return stats, errors.E(op, err)
}

return stats, nil
}
9 changes: 6 additions & 3 deletions templates/default/partials/form_submit.tmpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{{define "form_submit"}}
<form id="submit" method="post" enctype="multipart/form-data" hx-encoding="multipart/form-data" hx-post="/submit">
<div class="field">
<div class="control">
<input class="input" type="file" name="track">
<p>Upload a song to the R/a/dio database. We accept both MP3 (30MB max) and FLAC (90MB max).</p>
</div>
<progress id="submit-progress" class="htmx-indicator progress" value="0" max="100"></progress>
</div>
<div class="field">
<div class="control">
<input class="input" type="text" name="comment" placeholder="Comment">
<input class="input" type="text" name="comment" placeholder="Comment" value="{{with .}}{{.Comment}}{{end}}">
<p>Add the source, artist and title if tags are missing, etc. </p>
</div>
</div>
Expand All @@ -22,14 +24,15 @@
</div>
<div class="field">
<div class="control">
<input class="input" type="text" name="daypass" placeholder="Daypass">
<input class="input" type="text" name="daypass" placeholder="Daypass" value="{{with .}}{{.Daypass}}{{end}}">
</div>
<p>Enter the daypass and you can have unlimited uploads until midnight, UTC. <a href="https://static.r-a-d.io/exci/daypass-guide.webm">Ask exci in IRC for it</a>. USE WITH DISCRETION.
Uploading full soundtracks or albums without asking for a daypass will probably end in everything being declined.</p>
</div>
<div class="field">
<div class="control">
<button class="button">Upload Song</button>
<button class="button" type="submit">Upload Song</button>
</div>
</div>
</form>
{{end}}
89 changes: 88 additions & 1 deletion templates/default/submit.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,90 @@
{{define "content"}}
Submit {{.}}
<section class="section">
<div class="content">
{{$cooldown := CalculateSubmissionCooldown .Stats.LastSubmissionTime}}
{{if eq $cooldown 0}}
<div class="notification is-primary has-text-centered">
You can upload a song
</div>
{{else}}
<div class="notification is-danger has-text-centered">
You cannot upload another song just yet. You can upload <time datetime="{{(Now.Add $cooldown).Unix}}">{{PrettyDuration $cooldown}}</time>.
</div>
{{end}}
<div class="columns">
<div class="column is-6">
<p>
<strong>Uploading</strong>
</p>
<ul>
<li>VERY IMPORTANT: Search first to make sure that the song isn't already in the database!</li>
<li>Low quality uploads are likely to be declined if it's obvious better quality versions are available</li>
<li>Anything below 192kbps is rejected. Do not upload YouTube rips.</li>
<li>Please include as much information as possible in the comment field, especially source (name of the anime, VN, game). If there is no source work, please mention this.</li>
<li><a style="cursor: pointer;" data-toggle="modal" data-target="#submission-guidelines">Why did my submission get declined?</a></li>
</ul>
<p></p>
<p>
<strong>Tagging</strong>
</p>
<ul>
<li>Artist and title are required; at least put them in the comment, if not in the artist and title tags.</li>
<li>Avoid Japanese characters unless it's absolutely necessary. Uploads with too much kana/kanji may be declined.</li>
<li>Do not include character names or "CV" notation; vocalists only.</li>
<li>If you can remember, please include where you downloaded the file from</li>
<li><a href="https://static.r-a-d.io/exci/good-comment.png">An example of a good comment</a></li>
</ul>
</div>
<div class="column is-6">
{{template "form_submit" .Form}}
</div>
</div>
<p class="has-text-centered">There are currently {{.Stats.CurrentPending}} pending tracks awaiting approval.</p>
<hr>
<div class="columns">
<div class="column is-6">
<div class="content has-text-success has-text-centered">
<h2>Accepts</h2>
<br>
{{.Stats.AcceptedTotal}} accepted submissions.
<br>
{{.Stats.AcceptedLastTwoWeeks}} accepted in the last 2 weeks.
<br>
{{.Stats.AcceptedYou}} accepted submissions from (You).
<br><br>
</div>
<div class="content">
{{range $song := .Stats.RecentAccepts}}
<p>{{$song.Metadata}}</p>
<hr>
{{end}}
</div>
</div>
<div class="column is-6">
<div class="content has-text-danger has-text-centered">
<h2>Declines</h2>
<br>
{{.Stats.DeclinedTotal}} declined submissions.
<br>
{{.Stats.DeclinedLastTwoWeeks}} declined in the last 2 weeks.
<br>
{{.Stats.DeclinedYou}} declined submissions from (You).
<br><br>
</div>
{{range $song := .Stats.RecentDeclines}}
<div class="columns content">
<div class="column is-8">
<p>{{$song.Metadata}}</p>
</div>
<div class="column is-4">
<p class="has-text-danger">{{$song.DeclineReason}}</p>
</div>
</div>
<hr>
{{end}}
</div>
</div>
</div>
</section>
{{printjson .}}
{{end}}
14 changes: 8 additions & 6 deletions templates/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ func TemplateFuncs() template.FuncMap {
}

var fnMap = map[string]any{
"printjson": PrintJSON,
"safeHTML": SafeHTML,
"safeHTMLAttr": SafeHTMLAttr,
"Until": time.Until,
"Since": time.Since,
"PrettyDuration": PrettyDuration,
"printjson": PrintJSON,
"safeHTML": SafeHTML,
"safeHTMLAttr": SafeHTMLAttr,
"Until": time.Until,
"Since": time.Since,
"Now": time.Now,
"PrettyDuration": PrettyDuration,
"CalculateSubmissionCooldown": radio.CalculateSubmissionCooldown,
}

func PrintJSON(v any) (template.HTML, error) {
Expand Down
Loading

0 comments on commit 6274d2c

Please sign in to comment.