first commit
This commit is contained in:
35
src/web.rs
35
src/web.rs
@@ -346,6 +346,8 @@ struct FeedRow {
|
||||
entries: i64,
|
||||
downloaded: i64,
|
||||
unread: i64,
|
||||
/// Including you. More than one means every file here is shared.
|
||||
subscribers: i64,
|
||||
}
|
||||
|
||||
async fn feeds(
|
||||
@@ -363,6 +365,7 @@ async fn feeds(
|
||||
.into_iter()
|
||||
.map(|s| (s.feed_id.clone(), s))
|
||||
.collect();
|
||||
let counts = state.ctx.db.subscriber_counts()?;
|
||||
let mut out = Vec::with_capacity(mine.len());
|
||||
for sub in &subs {
|
||||
let (id, feed) = (&sub.id, &sub.cfg);
|
||||
@@ -400,6 +403,7 @@ async fn feeds(
|
||||
entries: s.entries,
|
||||
downloaded: s.downloaded,
|
||||
unread: state.ctx.db.unread_count(user.id, id)?,
|
||||
subscribers: counts.get(id).copied().unwrap_or(0),
|
||||
});
|
||||
}
|
||||
Ok(Json(out))
|
||||
@@ -822,15 +826,46 @@ async fn download_now(
|
||||
Ok(StatusCode::ACCEPTED)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Force {
|
||||
#[serde(default)]
|
||||
force: bool,
|
||||
}
|
||||
|
||||
async fn delete_file(
|
||||
State(state): State<WebState>,
|
||||
Path(id): Path<i64>,
|
||||
user: crate::db::User,
|
||||
Query(q): Query<Force>,
|
||||
) -> Result<StatusCode, ApiError> {
|
||||
let enc = state
|
||||
.ctx
|
||||
.db
|
||||
.enclosure(id)?
|
||||
.ok_or_else(|| anyhow::anyhow!("no enclosure {id}"))?;
|
||||
|
||||
// There is one copy of the file: deleting it deletes everyone's. Say so before doing
|
||||
// it, once, and let them decide.
|
||||
if !q.force {
|
||||
let (starred, unread) = state.ctx.db.others_wanting(id, user.id)?;
|
||||
let people = |n: i64| if n == 1 { "person".to_string() } else { format!("{n} people") };
|
||||
let complaint = match (starred, unread) {
|
||||
(0, 0) => None,
|
||||
(0, u) => Some(format!("{} subscribed to this feed {} not played it yet", people(u), if u == 1 { "has" } else { "have" })),
|
||||
(st, 0) => Some(format!("another {} starred it to keep", people(st))),
|
||||
(st, u) => Some(format!(
|
||||
"another {} starred it to keep, and {} not played it yet",
|
||||
people(st),
|
||||
if u == 1 { "one person has".to_string() } else { format!("{u} have") }
|
||||
)),
|
||||
};
|
||||
if let Some(why) = complaint {
|
||||
return Err(ApiError {
|
||||
error: anyhow::Error::msg(format!("There is one copy of this file and {why}.")),
|
||||
status: StatusCode::CONFLICT,
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Some(path) = &enc.path
|
||||
&& let Err(e) = std::fs::remove_file(path)
|
||||
&& e.kind() != std::io::ErrorKind::NotFound
|
||||
|
||||
Reference in New Issue
Block a user