Minor changes

This commit is contained in:
sxyazi 2024-04-11 01:04:35 +08:00
parent 0a93a4e9a4
commit e0077f6a10
No known key found for this signature in database
5 changed files with 33 additions and 33 deletions

View file

@ -25,7 +25,7 @@ body:
- type: dropdown - type: dropdown
id: tried_main id: tried_main
attributes: attributes:
label: Did you try the latest main branch to see if the problem got fixed? label: Did you try the latest code to see if this problem got fixed?
options: options:
- Tried, but the problem still - Tried, but the problem still
- Not tried, and I'll explain why below - Not tried, and I'll explain why below

View file

@ -16,8 +16,8 @@ pub enum Body<'a> {
Bulk(BodyBulk<'a>), Bulk(BodyBulk<'a>),
Yank(BodyYank<'a>), Yank(BodyYank<'a>),
Move(BodyMove<'a>), Move(BodyMove<'a>),
Delete(BodyDelete<'a>),
Trash(BodyTrash<'a>), Trash(BodyTrash<'a>),
Delete(BodyDelete<'a>),
Custom(BodyCustom), Custom(BodyCustom),
} }
@ -32,8 +32,8 @@ impl<'a> Body<'a> {
"bulk" => Body::Bulk(serde_json::from_str(body)?), "bulk" => Body::Bulk(serde_json::from_str(body)?),
"yank" => Body::Yank(serde_json::from_str(body)?), "yank" => Body::Yank(serde_json::from_str(body)?),
"move" => Body::Move(serde_json::from_str(body)?), "move" => Body::Move(serde_json::from_str(body)?),
"delete" => Body::Delete(serde_json::from_str(body)?),
"trash" => Body::Trash(serde_json::from_str(body)?), "trash" => Body::Trash(serde_json::from_str(body)?),
"delete" => Body::Delete(serde_json::from_str(body)?),
_ => BodyCustom::from_str(kind, body)?, _ => BodyCustom::from_str(kind, body)?,
}) })
} }
@ -61,8 +61,8 @@ impl<'a> Body<'a> {
Self::Bulk(_) => "bulk", Self::Bulk(_) => "bulk",
Self::Yank(_) => "yank", Self::Yank(_) => "yank",
Body::Move(_) => "move", Body::Move(_) => "move",
Body::Delete(_) => "delete",
Body::Trash(_) => "trash", Body::Trash(_) => "trash",
Body::Delete(_) => "delete",
Self::Custom(b) => b.kind.as_str(), Self::Custom(b) => b.kind.as_str(),
} }
} }
@ -104,8 +104,8 @@ impl IntoLua<'_> for Body<'static> {
Body::Bulk(b) => b.into_lua(lua), Body::Bulk(b) => b.into_lua(lua),
Body::Yank(b) => b.into_lua(lua), Body::Yank(b) => b.into_lua(lua),
Body::Move(b) => b.into_lua(lua), Body::Move(b) => b.into_lua(lua),
Body::Delete(b) => b.into_lua(lua),
Body::Trash(b) => b.into_lua(lua), Body::Trash(b) => b.into_lua(lua),
Body::Delete(b) => b.into_lua(lua),
Body::Custom(b) => b.into_lua(lua), Body::Custom(b) => b.into_lua(lua),
} }
} }

View file

@ -85,8 +85,8 @@ impl Display for Payload<'_> {
Body::Bulk(b) => serde_json::to_string(b), Body::Bulk(b) => serde_json::to_string(b),
Body::Yank(b) => serde_json::to_string(b), Body::Yank(b) => serde_json::to_string(b),
Body::Move(b) => serde_json::to_string(b), Body::Move(b) => serde_json::to_string(b),
Body::Delete(b) => serde_json::to_string(b),
Body::Trash(b) => serde_json::to_string(b), Body::Trash(b) => serde_json::to_string(b),
Body::Delete(b) => serde_json::to_string(b),
Body::Custom(b) => serde_json::to_string(b), Body::Custom(b) => serde_json::to_string(b),
}; };

View file

@ -155,18 +155,6 @@ impl Pubsub {
} }
} }
pub(super) fn pub_from_delete(urls: Vec<Url>) {
if PEERS.read().values().any(|p| p.able("delete")) {
Client::push(BodyDelete::borrowed(&urls));
}
if BOOT.local_events.contains("delete") {
BodyDelete::borrowed(&urls).with_receiver(*ID).flush();
}
if LOCAL.read().contains_key("delete") {
Self::pub_(BodyDelete::owned(urls));
}
}
pub(super) fn pub_from_trash(urls: Vec<Url>) { pub(super) fn pub_from_trash(urls: Vec<Url>) {
if PEERS.read().values().any(|p| p.able("trash")) { if PEERS.read().values().any(|p| p.able("trash")) {
Client::push(BodyTrash::borrowed(&urls)); Client::push(BodyTrash::borrowed(&urls));
@ -178,4 +166,16 @@ impl Pubsub {
Self::pub_(BodyTrash::owned(urls)); Self::pub_(BodyTrash::owned(urls));
} }
} }
pub(super) fn pub_from_delete(urls: Vec<Url>) {
if PEERS.read().values().any(|p| p.able("delete")) {
Client::push(BodyDelete::borrowed(&urls));
}
if BOOT.local_events.contains("delete") {
BodyDelete::borrowed(&urls).with_receiver(*ID).flush();
}
if LOCAL.read().contains_key("delete") {
Self::pub_(BodyDelete::owned(urls));
}
}
} }

View file

@ -10,8 +10,8 @@ use crate::{body::BodyMoveItem, Pubsub};
static CT: RoCell<CancellationToken> = RoCell::new(); static CT: RoCell<CancellationToken> = RoCell::new();
static MOVE_TX: Mutex<Option<mpsc::UnboundedSender<BodyMoveItem>>> = Mutex::new(None); static MOVE_TX: Mutex<Option<mpsc::UnboundedSender<BodyMoveItem>>> = Mutex::new(None);
static DELETE_TX: Mutex<Option<mpsc::UnboundedSender<Url>>> = Mutex::new(None);
static TRASH_TX: Mutex<Option<mpsc::UnboundedSender<Url>>> = Mutex::new(None); static TRASH_TX: Mutex<Option<mpsc::UnboundedSender<Url>>> = Mutex::new(None);
static DELETE_TX: Mutex<Option<mpsc::UnboundedSender<Url>>> = Mutex::new(None);
pub struct Pump; pub struct Pump;
@ -23,13 +23,6 @@ impl Pump {
} }
} }
#[inline]
pub fn push_delete(target: Url) {
if let Some(tx) = &*DELETE_TX.lock() {
tx.send(target).ok();
}
}
#[inline] #[inline]
pub fn push_trash(target: Url) { pub fn push_trash(target: Url) {
if let Some(tx) = &*TRASH_TX.lock() { if let Some(tx) = &*TRASH_TX.lock() {
@ -37,33 +30,40 @@ impl Pump {
} }
} }
#[inline]
pub fn push_delete(target: Url) {
if let Some(tx) = &*DELETE_TX.lock() {
tx.send(target).ok();
}
}
pub(super) fn serve() { pub(super) fn serve() {
let (move_tx, move_rx) = mpsc::unbounded_channel(); let (move_tx, move_rx) = mpsc::unbounded_channel();
let (delete_tx, delete_rx) = mpsc::unbounded_channel();
let (trash_tx, trash_rx) = mpsc::unbounded_channel(); let (trash_tx, trash_rx) = mpsc::unbounded_channel();
let (delete_tx, delete_rx) = mpsc::unbounded_channel();
CT.with(Default::default); CT.with(Default::default);
MOVE_TX.lock().replace(move_tx); MOVE_TX.lock().replace(move_tx);
DELETE_TX.lock().replace(delete_tx);
TRASH_TX.lock().replace(trash_tx); TRASH_TX.lock().replace(trash_tx);
DELETE_TX.lock().replace(delete_tx);
tokio::spawn(async move { tokio::spawn(async move {
let move_rx = let move_rx =
UnboundedReceiverStream::new(move_rx).chunks_timeout(1000, Duration::from_millis(500)); UnboundedReceiverStream::new(move_rx).chunks_timeout(1000, Duration::from_millis(500));
let delete_rx =
UnboundedReceiverStream::new(delete_rx).chunks_timeout(1000, Duration::from_millis(500));
let trash_rx = let trash_rx =
UnboundedReceiverStream::new(trash_rx).chunks_timeout(1000, Duration::from_millis(500)); UnboundedReceiverStream::new(trash_rx).chunks_timeout(1000, Duration::from_millis(500));
let delete_rx =
UnboundedReceiverStream::new(delete_rx).chunks_timeout(1000, Duration::from_millis(500));
pin!(move_rx); pin!(move_rx);
pin!(delete_rx);
pin!(trash_rx); pin!(trash_rx);
pin!(delete_rx);
loop { loop {
select! { select! {
Some(items) = move_rx.next() => Pubsub::pub_from_move(items), Some(items) = move_rx.next() => Pubsub::pub_from_move(items),
Some(urls) = trash_rx.next() => Pubsub::pub_from_trash(urls),
Some(urls) = delete_rx.next() => Pubsub::pub_from_delete(urls), Some(urls) = delete_rx.next() => Pubsub::pub_from_delete(urls),
Some(urls) = trash_rx.next() => Pubsub::pub_from_trash(urls),
else => { else => {
CT.cancel(); CT.cancel();
break; break;
@ -75,8 +75,8 @@ impl Pump {
pub(super) async fn shutdown() { pub(super) async fn shutdown() {
drop(MOVE_TX.lock().take()); drop(MOVE_TX.lock().take());
drop(DELETE_TX.lock().take());
drop(TRASH_TX.lock().take()); drop(TRASH_TX.lock().take());
drop(DELETE_TX.lock().take());
CT.cancelled().await; CT.cancelled().await;
} }
} }