nuno 已修改 1 month ago. 還原成這個修訂版本
1 file changed, 56 insertions
gistfile1.txt(檔案已創建)
| @@ -0,0 +1,56 @@ | |||
| 1 | + | function peers::format_status() { | |
| 2 | + | local name="${1:-}" public_key="${2:-}" is_blocked="${3:-false}" | |
| 3 | + | local is_restricted="${4:-false}" handshake_ts="${5:-0}" last_ts="${6:-}" | |
| 4 | + | ||
| 5 | + | local connected=false modifier="" color | |
| 6 | + | ||
| 7 | + | if [[ "$is_blocked" == "true" ]]; then | |
| 8 | + | local now attempt_ts diff | |
| 9 | + | now=$(date +%s) | |
| 10 | + | attempt_ts=$(json::iso_to_ts "$last_ts") | |
| 11 | + | diff=$(( now - attempt_ts )) | |
| 12 | + | (( diff < "$(config::handshake_time_sec)" )) && connected=true | |
| 13 | + | modifier=" (blocked)" | |
| 14 | + | color="\033[1;31m" | |
| 15 | + | elif [[ "$is_restricted" == "true" ]]; then | |
| 16 | + | local now diff | |
| 17 | + | now=$(date +%s) | |
| 18 | + | diff=$(( now - handshake_ts )) | |
| 19 | + | (( diff < "$(config::handshake_time_sec)" )) && connected=true | |
| 20 | + | modifier=" (restricted)" | |
| 21 | + | color="\033[1;33m" | |
| 22 | + | else | |
| 23 | + | local now diff | |
| 24 | + | now=$(date +%s) | |
| 25 | + | diff=$(( now - handshake_ts )) | |
| 26 | + | (( diff < "$(config::handshake_time_sec)" )) && connected=true | |
| 27 | + | if $connected; then color="\033[1;32m"; else color="\033[0;37m"; fi | |
| 28 | + | fi | |
| 29 | + | ||
| 30 | + | local conn_str | |
| 31 | + | $connected && conn_str="online" || conn_str="offline" | |
| 32 | + | echo -e "${color}${conn_str}${modifier}\033[0m" | |
| 33 | + | } | |
| 34 | + | ||
| 35 | + | function peers::format_last_seen() { | |
| 36 | + | local name="${1:-}" pubkey="${2:-}" is_blocked="${3:-false}" | |
| 37 | + | local last_ts="${4:-}" last_evt="${5:-}" handshake_ts="${6:-0}" | |
| 38 | + | ||
| 39 | + | if [[ "$is_blocked" == "true" ]]; then | |
| 40 | + | if [[ -n "$last_ts" && "$last_ts" != "0" && "$last_ts" != "null" ]]; then | |
| 41 | + | local formatted | |
| 42 | + | formatted=$(fmt::datetime_iso "$last_ts") | |
| 43 | + | echo "${formatted} (dropped)" | |
| 44 | + | else | |
| 45 | + | echo "—" | |
| 46 | + | fi | |
| 47 | + | else | |
| 48 | + | if [[ -z "$handshake_ts" || "$handshake_ts" == "0" ]]; then | |
| 49 | + | echo "—" | |
| 50 | + | else | |
| 51 | + | local formatted | |
| 52 | + | formatted=$(fmt::datetime "$handshake_ts") | |
| 53 | + | echo "${formatted} (handshake)" | |
| 54 | + | fi | |
| 55 | + | fi | |
| 56 | + | } | |
上一頁
下一頁