]> littlesong.place Git - littlesongplace.git/commitdiff
Cancel import for other song update methods
authorChris Fulljames <christianfulljames@gmail.com>
Mon, 19 Jan 2026 21:07:38 +0000 (16:07 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Mon, 19 Jan 2026 21:07:38 +0000 (16:07 -0500)
src/littlesongplace/songs.py
test/test_dreams_importer.py

index a0ec845ba069da422f5d130344c57c86773f36e3..4adb2cb19ff599aab35f0e9380b4f8182c272a24 100644 (file)
@@ -335,6 +335,11 @@ def update_song():
 
     error = False
     if file or url:
+
+        # Clear pending dreams import
+        if song_data["queueid"] is not None:
+            dreams_importer.delete_from_queue(song_data["queueid"])
+
         with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
             passed = convert_song(tmp_file, file, url, upload_type)
 
@@ -377,8 +382,6 @@ def update_song():
                 [collab, songid])
 
         if upload_type == "dreams" and url:
-            if song_data["queueid"] is not None:
-                dreams_importer.delete_from_queue(song_data["queueid"])
             duration = duration_in_seconds(song_duration)
             dreams_importer.add_to_queue(songid, url, duration)
 
index 5f46c54eb1f3d9a6303358c4110b127711d93db4..c272c16a04f1a39147b2e0d5d20f14c66b4c7046 100644 (file)
@@ -132,3 +132,23 @@ def test_update_queued_song(client, user):
     assert response.json["next"]["indreamsurl"] == TEST_URL + "_new"
     assert response.json["next"]["songid"] == 1
 
+def test_import_canceled_by_file(client, user):
+    upload_song(
+        client, b"Queued for import from Dreams",
+        upload_type="dreams",
+        song_url=TEST_URL)
+
+    # Initial queue position
+    response = client.get(f"/users/user")
+    assert b"[Hidden]" in response.data
+    assert b"[Queue Pos: 1]" in response.data
+
+    upload_song(client, b"Success", songid=1)
+
+    # Queue gone now that file was used
+    response = client.get(f"/users/user")
+    assert b"[Hidden]" not in response.data
+    assert b"[Queue Pos: 1]" not in response.data
+    response = client.get("/dreams-importer/next-in-queue")
+    assert response.json["next"] is None
+