Add edit custom song endpoint

This commit is contained in:
Ethan O'Brien
2026-07-03 16:12:14 -05:00
parent 6b465eca8e
commit f04ffc2f5d
3 changed files with 357 additions and 3 deletions

View File

@@ -85,7 +85,7 @@ pub fn get_revision() -> i64 {
DATABASE.lock_and_select("SELECT revision FROM revision WHERE id=1", params!()).unwrap_or_default().parse::<i64>().unwrap_or(0)
}
// Bumped on every upload/delete/visibility change so the client can invalidate its cache
// Bumped on every upload/update/delete/visibility change so the client can invalidate its cache
pub fn bump_revision() {
DATABASE.lock_and_exec("INSERT INTO revision (id, revision, last_music_id) VALUES (1, 1, 0) ON CONFLICT(id) DO UPDATE SET revision=revision+1", params!());
}
@@ -110,6 +110,12 @@ pub fn insert_song(music_id: i64, owner_id: i64, song: &JsonValue, visibility: &
set_shared_users(music_id, shared_with);
}
// Replace an existing song's catalog blob in place. The owner, visibility,
// shared list and download toggle live in their own columns and are untouched
pub fn update_song(music_id: i64, song: &JsonValue) {
DATABASE.lock_and_exec("UPDATE songs SET song=?1 WHERE music_id=?2", params!(jzon::stringify(song.clone()), music_id));
}
pub fn delete_song(music_id: i64) {
DATABASE.lock_and_exec("DELETE FROM songs WHERE music_id=?1", params!(music_id));
DATABASE.lock_and_exec("DELETE FROM shared_users WHERE music_id=?1", params!(music_id));