forked from Furumi/furumi-web
Add the Import library page and wizard to the web player
Import library sits between Followed and Settings in the account menu and opens #imports: the sources, the history with statistics and links to the created playlists, and #imports/N with progress, per-playlist results, a deleted-playlist notice with Create again, and the entries with status and playlist filters, search, paging and the candidates of doubtful entries to choose from. Retry unmatched (with the federated search consent), Cancel, Delete history and a new Spotify sign-in for waiting imports call the existing /api/imports endpoints. The page polls every 3 s while an import runs. It follows the player's views, skeletons, dialogs, switches and phrase table in English and Russian. The New import wizard picks a source, then the data export or the Spotify sign-in, then the playlists: imported ones cannot be selected, similar ones need an explicit confirmation, and federated search is off until the user turns it on. A ZIP export is opened in the browser with fflate 0.8.2, vendored with its MIT licence and served at /vendor/fflate-0.8.2.js only when an archive is picked. Only Playlist*.json and YourLibrary.json are extracted; archives over 256 MiB, with more than 2,000 entries, more than 256 playlist files or more than 32 MiB declared for them are refused before anything is decompressed, and a request over 32 MiB is not sent. Federated tracks can now be removed from a playlist in edit mode: DELETE /api/player/tracks/content/playlist checks the owner and records the existing PlaylistTrackRemoved operation. The body-level dialogs get an Alpine root, which also makes Get app open again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4d6a1513d9
commit
d275e7326b
21 files changed
+2421
-14
No files matched your search
@@ -7292,6 +7292,85 @@ async fn content_playlist_add_handler(
|
||||
Json(serde_json::json!({ "ok": true })).into_response()
|
||||
}
|
||||
|
||||
/// Result of removing a federated track from a playlist.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum ContentRemoval {
|
||||
Removed,
|
||||
NotOwned,
|
||||
InvalidContentId,
|
||||
}
|
||||
|
||||
/// Removes a track identified by its content id from the user's own playlist
|
||||
/// with the existing `PlaylistTrackRemoved` operation: the register becomes
|
||||
/// `present = false` and a materialized row, if any, is deleted. Federated
|
||||
/// tracks have no `playlist_track` row, so this is how the web removes them.
|
||||
pub(crate) async fn remove_content_from_playlist(
|
||||
pool: &sqlx::PgPool,
|
||||
user_id: i64,
|
||||
playlist_id: i64,
|
||||
content_id: &str,
|
||||
) -> anyhow::Result<ContentRemoval> {
|
||||
let Some(content_id) = music_dht::normalize_content_id(content_id) else {
|
||||
return Ok(ContentRemoval::InvalidContentId);
|
||||
};
|
||||
let owns: bool = sqlx::query_scalar(
|
||||
"SELECT EXISTS (
|
||||
SELECT 1 FROM furumusic__playlist WHERE id = $1 AND owner_id = $2
|
||||
)",
|
||||
)
|
||||
.bind(playlist_id)
|
||||
.bind(user_id)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
if !owns {
|
||||
return Ok(ContentRemoval::NotOwned);
|
||||
}
|
||||
crate::federation::devices::record_playlist_tracks_removed(
|
||||
pool,
|
||||
user_id,
|
||||
playlist_id,
|
||||
&[content_id],
|
||||
)
|
||||
.await?;
|
||||
Ok(ContentRemoval::Removed)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DELETE /api/player/tracks/content/playlist — remove a federated track
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async fn content_playlist_remove_handler(
|
||||
auth_ctx: auth::AuthContext,
|
||||
session: Session,
|
||||
db: Database,
|
||||
pool: &sqlx::PgPool,
|
||||
Json(body): Json<ContentTrackMutation>,
|
||||
) -> cot::Result<cot::response::Response> {
|
||||
let Some(user) = auth::get_request_user(&auth_ctx, &session, &db).await else {
|
||||
return Ok(json_error(StatusCode::UNAUTHORIZED, "not authenticated"));
|
||||
};
|
||||
let Some(playlist_id) = body.playlist_id else {
|
||||
return Ok(json_error(StatusCode::BAD_REQUEST, "missing playlist id"));
|
||||
};
|
||||
match remove_content_from_playlist(pool, user.id, playlist_id, &body.content_id).await {
|
||||
Ok(ContentRemoval::Removed) => Json(serde_json::json!({ "ok": true })).into_response(),
|
||||
Ok(ContentRemoval::NotOwned) => Ok(json_error(StatusCode::FORBIDDEN, "not your playlist")),
|
||||
Ok(ContentRemoval::InvalidContentId) => {
|
||||
Ok(json_error(StatusCode::BAD_REQUEST, "invalid content id"))
|
||||
}
|
||||
Err(err) => {
|
||||
tracing::warn!(
|
||||
playlist_id,
|
||||
"fed device playlist remove op was not recorded: {err:#}"
|
||||
);
|
||||
Ok(json_error(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
"could not remove the track",
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn federation_playlist_tracks_handler(
|
||||
auth_ctx: auth::AuthContext,
|
||||
session: Session,
|
||||
@@ -10696,6 +10775,30 @@ impl App for PlayerApp {
|
||||
content_playlist_add_handler(auth_ctx, session, db, pg_pool, json).await
|
||||
}
|
||||
}
|
||||
})
|
||||
.delete({
|
||||
let pool = Arc::clone(&pool);
|
||||
let pool_config = Arc::clone(&pool_config);
|
||||
move |auth_ctx: auth::AuthContext,
|
||||
session: Session,
|
||||
db: Database,
|
||||
json: Json<ContentTrackMutation>| {
|
||||
let pool = Arc::clone(&pool);
|
||||
let pool_config = Arc::clone(&pool_config);
|
||||
async move {
|
||||
let pg_pool = pool
|
||||
.get_or_init(|| async {
|
||||
sqlx::postgres::PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(&pool_config.database_url)
|
||||
.await
|
||||
.expect("player pool")
|
||||
})
|
||||
.await;
|
||||
content_playlist_remove_handler(auth_ctx, session, db, pg_pool, json)
|
||||
.await
|
||||
}
|
||||
}
|
||||
}),
|
||||
"player_content_playlist",
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user