This commit is contained in:
sxyazi 2024-04-10 08:42:06 +08:00
parent d6e5f728ae
commit bbb8c3c036
No known key found for this signature in database
3 changed files with 10 additions and 10 deletions

View file

@ -8,19 +8,19 @@ use super::Body;
#[derive(Debug, Serialize, Deserialize)]
pub struct BodyDelete<'a> {
pub targets: Cow<'a, Vec<Url>>,
pub urls: Cow<'a, Vec<Url>>,
}
impl<'a> BodyDelete<'a> {
#[inline]
pub fn borrowed(targets: &'a Vec<Url>) -> Body<'a> {
Self { targets: Cow::Borrowed(targets) }.into()
Self { urls: Cow::Borrowed(targets) }.into()
}
}
impl BodyDelete<'static> {
#[inline]
pub fn owned(targets: Vec<Url>) -> Body<'static> { Self { targets: Cow::Owned(targets) }.into() }
pub fn owned(targets: Vec<Url>) -> Body<'static> { Self { urls: Cow::Owned(targets) }.into() }
}
impl<'a> From<BodyDelete<'a>> for Body<'a> {
@ -29,8 +29,8 @@ impl<'a> From<BodyDelete<'a>> for Body<'a> {
impl IntoLua<'_> for BodyDelete<'static> {
fn into_lua(self, lua: &Lua) -> mlua::Result<Value<'_>> {
let t = lua.create_table_with_capacity(self.targets.len(), 0)?;
for (i, url) in self.targets.into_owned().into_iter().enumerate() {
let t = lua.create_table_with_capacity(self.urls.len(), 0)?;
for (i, url) in self.urls.into_owned().into_iter().enumerate() {
t.raw_set(i + 1, lua.create_any_userdata(url)?)?;
}
t.into_lua(lua)

View file

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

View file

@ -49,7 +49,7 @@ impl Pump {
loop {
select! {
Some(items) = move_rx.next() => Pubsub::pub_from_move(items),
Some(targets) = delete_rx.next() => Pubsub::pub_from_delete(targets),
Some(urls) = delete_rx.next() => Pubsub::pub_from_delete(urls),
else => {
CT.cancel();
break;