Compare commits
4
Commits
v0.1.2
..
19385c4bca
No files matched your search
Generated
+1
-1
@@ -1179,7 +1179,7 @@ checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wakey"
|
name = "wakey"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wakey"
|
name = "wakey"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
publish = ["gitea"]
|
publish = ["gitea"]
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -7,9 +7,11 @@ use crate::route::api::Status; */
|
|||||||
use crate::utils::parse::mac::{des_opm, ser_opm};
|
use crate::utils::parse::mac::{des_opm, ser_opm};
|
||||||
use crate::utils::wake::wake_one;
|
use crate::utils::wake::wake_one;
|
||||||
use axum::{extract::Json, http::StatusCode, response::IntoResponse};
|
use axum::{extract::Json, http::StatusCode, response::IntoResponse};
|
||||||
|
use futures::TryFutureExt;
|
||||||
use macaddr::MacAddr;
|
use macaddr::MacAddr;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
|
use tokio::net::UdpSocket;
|
||||||
|
|
||||||
#[skip_serializing_none]
|
#[skip_serializing_none]
|
||||||
#[derive(Debug, Default, Serialize, Clone)]
|
#[derive(Debug, Default, Serialize, Clone)]
|
||||||
@@ -75,7 +77,9 @@ pub async fn wake_multi(Json(req): Json<Vec<WakeTarget>>) -> impl IntoResponse {
|
|||||||
pub async fn wake_multi_split(
|
pub async fn wake_multi_split(
|
||||||
targets: impl IntoIterator<Item = WakeTarget>,
|
targets: impl IntoIterator<Item = WakeTarget>,
|
||||||
) -> io::Result<Vec<WakeTargetResult>> {
|
) -> io::Result<Vec<WakeTargetResult>> {
|
||||||
let sock = tokio::net::UdpSocket::bind("0.0.0.0:0").await?;
|
let sock = UdpSocket::bind("[::]:0")
|
||||||
|
.or_else(|_| UdpSocket::bind(":0"))
|
||||||
|
.await?;
|
||||||
sock.set_broadcast(true)?;
|
sock.set_broadcast(true)?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,7 @@
|
|||||||
pub mod impls;
|
pub mod impls;
|
||||||
use std::{io, net::IpAddr};
|
use std::{io, net::IpAddr};
|
||||||
|
|
||||||
|
use futures::TryFutureExt;
|
||||||
use macaddr::MacAddr;
|
use macaddr::MacAddr;
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
|
|
||||||
@@ -74,7 +75,9 @@ impl WakeTargetResult {
|
|||||||
pub async fn _wake_multi(
|
pub async fn _wake_multi(
|
||||||
targets: impl IntoIterator<Item = WakeTarget>,
|
targets: impl IntoIterator<Item = WakeTarget>,
|
||||||
) -> io::Result<Vec<WakeTargetResult>> {
|
) -> io::Result<Vec<WakeTargetResult>> {
|
||||||
let sock = UdpSocket::bind(":0").await?;
|
let sock = UdpSocket::bind("[::]:0")
|
||||||
|
.or_else(|_| UdpSocket::bind(":0"))
|
||||||
|
.await?;
|
||||||
sock.set_broadcast(true)?;
|
sock.set_broadcast(true)?;
|
||||||
let fs = targets.into_iter().map(|t| wake_one(&sock, t));
|
let fs = targets.into_iter().map(|t| wake_one(&sock, t));
|
||||||
Ok(futures::future::join_all(fs).await)
|
Ok(futures::future::join_all(fs).await)
|
||||||
|
|||||||
+14
-4
@@ -1,6 +1,8 @@
|
|||||||
|
import { filter_array } from "./status.js";
|
||||||
|
|
||||||
export const qs = new URLSearchParams(location.search);
|
export const qs = new URLSearchParams(location.search);
|
||||||
|
|
||||||
// not real cuh
|
// $ is normally queryselector are we fr
|
||||||
export const $ = (id) => document.getElementById(id);
|
export const $ = (id) => document.getElementById(id);
|
||||||
export const elName = $("name");
|
export const elName = $("name");
|
||||||
export const elCheck = $("check");
|
export const elCheck = $("check");
|
||||||
@@ -17,10 +19,18 @@ export function setPill(kind, text) {
|
|||||||
pill.textContent = text;
|
pill.textContent = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setLink(name) {
|
export function setLink(name, clear) {
|
||||||
const url = new URL(location.href);
|
const url = new URL(location.href);
|
||||||
if (name) url.searchParams.set("name", name);
|
if (clear) url.searchParams.forEach((_, k) => url.searchParams.delete(k)); // FUCK
|
||||||
else url.searchParams.delete("name");
|
/* const hasExtraFilters = filter_array.some(
|
||||||
|
(k) => url.searchParams.getAll(k).length
|
||||||
|
);
|
||||||
|
if (hasExtraFilters) {
|
||||||
|
// jus returns whatever; they are specifying further
|
||||||
|
} else */ {
|
||||||
|
if (name) url.searchParams.set("name", name);
|
||||||
|
else url.searchParams.delete("name");
|
||||||
|
}
|
||||||
history.replaceState(null, "", url);
|
history.replaceState(null, "", url);
|
||||||
link.href = url.toString();
|
link.href = url.toString();
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ function pickTarget(value) {
|
|||||||
elName.value = v;
|
elName.value = v;
|
||||||
updatePreview();
|
updatePreview();
|
||||||
saveName(v);
|
saveName(v);
|
||||||
setLink(v);
|
setLink(v, true);
|
||||||
fetchStatus(v);
|
fetchStatus(v);
|
||||||
fetchLeases();
|
fetchLeases();
|
||||||
}
|
}
|
||||||
@@ -74,10 +74,16 @@ const initial = loadName(qs);
|
|||||||
if (initial) {
|
if (initial) {
|
||||||
elName.value = initial;
|
elName.value = initial;
|
||||||
updatePreview();
|
updatePreview();
|
||||||
setLink(initial);
|
if (qs.has("name")) {
|
||||||
fetchStatus(initial);
|
setLink(initial);
|
||||||
|
fetchStatus(initial);
|
||||||
|
} else {
|
||||||
|
fetchStatus();
|
||||||
|
}
|
||||||
fetchLeases();
|
fetchLeases();
|
||||||
} else {
|
} else {
|
||||||
setPill("warn", "unknown");
|
setPill("warn", "unknown");
|
||||||
|
updatePreview();
|
||||||
|
fetchStatus();
|
||||||
fetchLeases();
|
fetchLeases();
|
||||||
}
|
}
|
||||||
@@ -8,8 +8,8 @@ const status_map = {
|
|||||||
state: "state",
|
state: "state",
|
||||||
dev: "interface",
|
dev: "interface",
|
||||||
};
|
};
|
||||||
|
export const status_array = Object.keys(status_map);
|
||||||
const filter_array = ["ip", "dev", "nud", "mac"];
|
export const filter_array = ["ip", "dev", "nud", "mac"];
|
||||||
|
|
||||||
function buildStatusUrl(name) {
|
function buildStatusUrl(name) {
|
||||||
const hasExtraFilters = filter_array.some((k) => qs.getAll(k).length);
|
const hasExtraFilters = filter_array.some((k) => qs.getAll(k).length);
|
||||||
@@ -18,7 +18,7 @@ function buildStatusUrl(name) {
|
|||||||
}
|
}
|
||||||
const u = new URL("/api/status", location.origin);
|
const u = new URL("/api/status", location.origin);
|
||||||
if (name) u.searchParams.set("name", name);
|
if (name) u.searchParams.set("name", name);
|
||||||
for (const k of Object.keys(status_map)) {
|
for (const k of filter_array) {
|
||||||
const vals = qs.getAll(k);
|
const vals = qs.getAll(k);
|
||||||
for (const v of vals) u.searchParams.append(k, v);
|
for (const v of vals) u.searchParams.append(k, v);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user