Compare commits

...

3 Commits

Author SHA1 Message Date
xianguo
798e09b652 add configurable public server URLs 2026-06-22 15:16:25 +08:00
xianguo
0a93378cc8 Add mac launcher app 2026-06-19 14:12:30 +08:00
xianguo
1bf61238a9 modify css & webicon 2026-06-19 13:31:43 +08:00
15 changed files with 882 additions and 302 deletions

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>InternalDropLauncher</string>
<key>CFBundleIdentifier</key>
<string>local.privatedrop.launcher</string>
<key>CFBundleName</key>
<string>Internal Drop Launcher</string>
<key>CFBundleDisplayName</key>
<string>Internal Drop</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>10.13</string>
</dict>
</plist>

View File

@ -0,0 +1,4 @@
#!/bin/zsh
open -a Terminal "/Users/sin/Work/private/privatedrop/launch-internal-drop.command"
sleep 1
open "http://localhost:10051"

View File

@ -0,0 +1 @@
APPL????

View File

@ -23,6 +23,7 @@ Internal Drop is a small LAN text and file transfer app for 2 to 3 internal user
| `INTERNAL_DROP_MAX_FILE_SIZE` | `1073741824` | Max single upload bytes |
| `INTERNAL_DROP_FILE_TTL` | `2h` | Transfer expiry duration |
| `INTERNAL_DROP_ALLOWED_CIDRS` | empty | Optional comma-separated client CIDR allowlist, for example `192.168.1.0/24,10.0.0.0/8` |
| `INTERNAL_DROP_PUBLIC_URLS` | empty | Optional comma-separated URLs to show first in the UI, for example `http://10.20.8.138:10051,https://drop.company.lan` |
## Local Build

View File

@ -13,6 +13,7 @@ type Config struct {
MaxFileSize int64
FileTTL time.Duration
AllowedCIDRs []string
PublicURLs []string
}
func DefaultConfig() Config {
@ -22,6 +23,7 @@ func DefaultConfig() Config {
MaxFileSize: envInt64("INTERNAL_DROP_MAX_FILE_SIZE", 1<<30),
FileTTL: envDuration("INTERNAL_DROP_FILE_TTL", 2*time.Hour),
AllowedCIDRs: envList("INTERNAL_DROP_ALLOWED_CIDRS"),
PublicURLs: envList("INTERNAL_DROP_PUBLIC_URLS"),
}
}

View File

@ -8,3 +8,19 @@ func TestDefaultConfigUsesPort10051(t *testing.T) {
t.Fatalf("default addr = %q, want :10051", cfg.Addr)
}
}
func TestDefaultConfigReadsPublicURLs(t *testing.T) {
t.Setenv("INTERNAL_DROP_PUBLIC_URLS", "http://10.20.8.138:10051, https://drop.company.lan ")
cfg := DefaultConfig()
want := []string{"http://10.20.8.138:10051", "https://drop.company.lan"}
if len(cfg.PublicURLs) != len(want) {
t.Fatalf("public urls = %#v, want %#v", cfg.PublicURLs, want)
}
for i := range want {
if cfg.PublicURLs[i] != want[i] {
t.Fatalf("public urls = %#v, want %#v", cfg.PublicURLs, want)
}
}
}

View File

@ -105,10 +105,20 @@ func (a *App) Routes() http.Handler {
mux.HandleFunc("/api/health", a.handleHealth)
mux.HandleFunc("/api/server-info", a.handleServerInfo)
mux.HandleFunc("/ws", a.handleWebSocket)
mux.Handle("/", http.FileServer(a.static))
mux.Handle("/", a.staticHandler())
return a.withNetworkPolicy(mux)
}
func (a *App) staticHandler() http.Handler {
fileServer := http.FileServer(a.static)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store, max-age=0")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
fileServer.ServeHTTP(w, r)
})
}
func (a *App) StartCleaner(stop <-chan struct{}) {
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()
@ -273,7 +283,7 @@ func (a *App) handleServerInfo(w http.ResponseWriter, r *http.Request) {
ListenAddr: a.cfg.Addr,
Port: port,
CurrentURL: current,
URLs: uniqueStrings(localServerURLs(port)),
URLs: uniqueStrings(append(publicServerURLs(a.cfg.PublicURLs, port), localServerURLs(port)...)),
})
}
@ -500,6 +510,25 @@ func localServerURLs(port string) []string {
return urls
}
func publicServerURLs(values []string, port string) []string {
urls := make([]string, 0, len(values))
for _, value := range values {
value = strings.TrimSpace(value)
if value == "" {
continue
}
if strings.HasPrefix(value, "http://") || strings.HasPrefix(value, "https://") {
urls = append(urls, value)
continue
}
if !strings.Contains(value, ":") && port != "" {
value = net.JoinHostPort(value, port)
}
urls = append(urls, "http://"+value)
}
return urls
}
func isPrivateLANIPv4(ip net.IP) bool {
ip = ip.To4()
if ip == nil {

View File

@ -9,6 +9,7 @@ import (
"os"
"strings"
"testing"
"testing/fstest"
"time"
)
@ -85,6 +86,64 @@ func TestServerInfoAPIShowsCurrentURLAndPort(t *testing.T) {
}
}
func TestServerInfoAPIPrioritizesConfiguredPublicURLs(t *testing.T) {
app := NewApp(
Config{
Addr: ":10051",
TempDir: t.TempDir(),
MaxFileSize: 1024,
FileTTL: time.Hour,
PublicURLs: []string{"http://10.20.8.138:10051", "https://drop.company.lan"},
},
nil,
)
req := httptest.NewRequest(http.MethodGet, "/api/server-info", nil)
rec := httptest.NewRecorder()
app.Routes().ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)
}
var info serverInfoResponse
if err := json.NewDecoder(rec.Body).Decode(&info); err != nil {
t.Fatalf("decode server info: %v", err)
}
if len(info.URLs) < 2 {
t.Fatalf("urls = %#v, want configured public urls", info.URLs)
}
want := []string{"http://10.20.8.138:10051", "https://drop.company.lan"}
for i := range want {
if info.URLs[i] != want[i] {
t.Fatalf("urls = %#v, want configured public urls first %#v", info.URLs, want)
}
}
}
func TestStaticAssetsAreServedWithoutBrowserCaching(t *testing.T) {
app := NewApp(
Config{Addr: ":10051", TempDir: t.TempDir(), MaxFileSize: 1024, FileTTL: time.Hour},
http.FS(fstest.MapFS{"app.js": {Data: []byte("console.log('ok')")}}),
)
req := httptest.NewRequest(http.MethodGet, "/app.js", nil)
rec := httptest.NewRecorder()
app.Routes().ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)
}
if got := rec.Header().Get("Cache-Control"); got != "no-store, max-age=0" {
t.Fatalf("Cache-Control = %q, want no-store, max-age=0", got)
}
if got := rec.Header().Get("Pragma"); got != "no-cache" {
t.Fatalf("Pragma = %q, want no-cache", got)
}
if got := rec.Header().Get("Expires"); got != "0" {
t.Fatalf("Expires = %q, want 0", got)
}
}
func TestPrivateLANIPv4Filter(t *testing.T) {
cases := map[string]bool{
"10.0.1.5": true,

View File

@ -0,0 +1,8 @@
tell application "Terminal"
activate
do script "cd /Users/sin/Work/private/privatedrop && ./internal-drop"
end tell
delay 1
do shell script "open http://localhost:10051"

3
launch-internal-drop.command Executable file
View File

@ -0,0 +1,3 @@
#!/bin/zsh
cd "/Users/sin/Work/private/privatedrop" || exit 1
./internal-drop

View File

@ -6,6 +6,7 @@ const state = {
users: [],
serverInfo: null,
activities: new Map(),
selectedPeerId: "",
ws: null,
reconnectTimer: null
};
@ -16,14 +17,16 @@ const els = {
saveName: document.querySelector("#saveName"),
regenCode: document.querySelector("#regenCode"),
serverAddress: document.querySelector("#serverAddress"),
copyServerAddress: document.querySelector("#copyServerAddress"),
connectionState: document.querySelector("#connectionState"),
selectedPeer: document.querySelector("#selectedPeer"),
dropZone: document.querySelector("#dropZone"),
peerCount: document.querySelector("#peerCount"),
peerList: document.querySelector("#peerList"),
targetSelect: document.querySelector("#targetSelect"),
textInput: document.querySelector("#textInput"),
sendText: document.querySelector("#sendText"),
fileInput: document.querySelector("#fileInput"),
sendFile: document.querySelector("#sendFile"),
uploadProgress: document.querySelector("#uploadProgress"),
activityList: document.querySelector("#activityList"),
clearLog: document.querySelector("#clearLog")
@ -85,16 +88,58 @@ function connectWebSocket() {
}
function bindEvents() {
document.querySelectorAll(".panel-toggle").forEach((button) => {
button.addEventListener("click", (event) => {
event.stopPropagation();
togglePanel(button.dataset.panel, button);
});
});
document.querySelectorAll(".dock-panel").forEach((panel) => {
panel.addEventListener("click", (event) => event.stopPropagation());
});
document.addEventListener("click", closePanels);
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") closePanels();
});
els.saveName.addEventListener("click", saveName);
els.regenCode.addEventListener("click", regenerateCode);
els.copyServerAddress.addEventListener("click", copyServerAddress);
els.sendText.addEventListener("click", sendText);
els.sendFile.addEventListener("click", sendFile);
els.fileInput.addEventListener("change", () => {
const file = els.fileInput.files[0];
if (file) uploadFile(file);
});
els.dropZone.addEventListener("click", () => els.fileInput.click());
els.dropZone.addEventListener("dragenter", handleDragEnter);
els.dropZone.addEventListener("dragover", handleDragOver);
els.dropZone.addEventListener("dragleave", handleDragLeave);
els.dropZone.addEventListener("drop", handleDrop);
els.targetSelect.addEventListener("change", () => selectPeer(els.targetSelect.value));
els.clearLog.addEventListener("click", () => {
els.activityList.innerHTML = "";
state.activities.clear();
});
}
function togglePanel(panelId, button) {
const shouldOpen = document.querySelector(`#${panelId}`)?.hidden;
setPanel(panelId, shouldOpen, button);
}
function setPanel(panelId, open, button = null) {
const panel = document.querySelector(`#${panelId}`);
if (!panel) return;
closePanels();
panel.hidden = !open;
const toggle = button || document.querySelector(`.panel-toggle[data-panel="${panelId}"]`);
if (toggle) toggle.setAttribute("aria-expanded", String(open));
}
function closePanels() {
document.querySelectorAll(".dock-panel").forEach((item) => { item.hidden = true; });
document.querySelectorAll(".panel-toggle").forEach((item) => item.setAttribute("aria-expanded", "false"));
}
async function saveName() {
const name = els.nickname.value.trim();
if (!name) return;
@ -133,9 +178,8 @@ function sendText() {
els.textInput.value = "";
}
function sendFile() {
const file = els.fileInput.files[0];
const receiverId = els.targetSelect.value;
function uploadFile(file) {
const receiverId = state.selectedPeerId || els.targetSelect.value;
if (!file || !receiverId || !state.user) return;
const url = `/api/uploads?sender_id=${encodeURIComponent(state.user.id)}&receiver_id=${encodeURIComponent(receiverId)}&filename=${encodeURIComponent(file.name)}`;
const xhr = new XMLHttpRequest();
@ -164,6 +208,30 @@ function sendFile() {
xhr.send(file);
}
function handleDragEnter(event) {
event.preventDefault();
els.dropZone.classList.add("drag-over");
}
function handleDragOver(event) {
event.preventDefault();
event.dataTransfer.dropEffect = state.selectedPeerId ? "copy" : "none";
}
function handleDragLeave(event) {
if (!els.dropZone.contains(event.relatedTarget)) {
els.dropZone.classList.remove("drag-over");
}
}
function handleDrop(event) {
event.preventDefault();
els.dropZone.classList.remove("drag-over");
const file = event.dataTransfer.files[0];
if (!file) return;
uploadFile(file);
}
function handleEvent(event) {
switch (event.type) {
case "user.list":
@ -212,6 +280,7 @@ function handleEvent(event) {
}
function addIncomingText(event) {
setPanel("activityPanel", true);
const text = event.text || event.transfer?.text || "";
const item = upsertActivity({
key: transferKey(event.transfer),
@ -224,14 +293,18 @@ function addIncomingText(event) {
copy.type = "button";
copy.textContent = "复制";
copy.className = "secondary";
copy.addEventListener("click", () => {
navigator.clipboard.writeText(text);
copy.addEventListener("click", async () => {
if (await copyTextToClipboard(text)) {
updateTransferActivity(event.transfer, "已复制", "ok");
} else {
updateTransferActivity(event.transfer, "复制失败", "bad");
}
});
setActivityActions(item, [copy]);
}
function addIncomingFile(event) {
setPanel("activityPanel", true);
const transfer = event.transfer;
if (!transfer) return;
const item = upsertActivity({
@ -310,14 +383,22 @@ function renderIdentity() {
function renderServerInfo() {
const info = state.serverInfo;
if (!info) return;
const urls = (info.urls || []).filter((url) => /^http:\/\/(10\.|172\.(1[6-9]|2\d|3[01])\.|192\.168\.)/.test(url));
const urls = (info.urls || []).filter(Boolean);
if (urls.length === 0) {
els.serverAddress.textContent = "未检测到内网 IP";
els.serverAddress.textContent = "未检测到可用地址";
els.serverAddress.title = "";
els.copyServerAddress.disabled = true;
return;
}
els.serverAddress.textContent = urls[0];
els.serverAddress.title = urls.join("\n");
els.copyServerAddress.disabled = false;
}
async function copyServerAddress() {
const text = els.serverAddress.textContent.trim();
if (!text || text === "检测中" || text.startsWith("未检测到")) return false;
return copyTextToClipboard(text);
}
function renderUsers() {
@ -325,6 +406,12 @@ function renderUsers() {
els.peerCount.textContent = peers.length;
els.peerList.innerHTML = "";
els.targetSelect.innerHTML = "";
if (state.selectedPeerId && !peers.some((user) => user.id === state.selectedPeerId)) {
state.selectedPeerId = "";
}
if (!state.selectedPeerId && peers.length > 0) {
state.selectedPeerId = peers[0].id;
}
if (peers.length === 0) {
const empty = document.createElement("div");
empty.className = "peer";
@ -335,23 +422,41 @@ function renderUsers() {
const option = document.createElement("option");
option.value = user.id;
option.textContent = `${user.name} (${user.code})`;
option.selected = user.id === state.selectedPeerId;
els.targetSelect.append(option);
const card = document.createElement("div");
const card = document.createElement("button");
card.type = "button";
card.className = "peer";
card.innerHTML = `<strong></strong><code></code>`;
card.querySelector("strong").textContent = user.name;
card.querySelector("code").textContent = user.code;
card.addEventListener("click", () => {
els.targetSelect.value = user.id;
document.querySelectorAll(".peer.selected").forEach((node) => node.classList.remove("selected"));
card.classList.add("selected");
});
if (user.id === state.selectedPeerId) card.classList.add("selected");
card.addEventListener("click", () => selectPeer(user.id));
els.peerList.append(card);
}
if (state.selectedPeerId) els.targetSelect.value = state.selectedPeerId;
const hasTarget = peers.length > 0;
els.sendText.disabled = !hasTarget;
els.sendFile.disabled = !hasTarget;
els.dropZone.disabled = !hasTarget;
renderSelectedPeer();
}
function selectPeer(userId) {
state.selectedPeerId = userId;
els.targetSelect.value = userId;
renderUsers();
}
function renderSelectedPeer() {
const peer = state.users.find((user) => user.id === state.selectedPeerId);
if (!peer) {
els.selectedPeer.textContent = "打开“成员”选择接收方";
els.dropZone.querySelector("#dropHint").textContent = "选择在线成员后,把文件拖到这里,或点击选择文件";
return;
}
els.selectedPeer.textContent = `发送给 ${peer.name} · ${peer.code}`;
els.dropZone.querySelector("#dropHint").textContent = "把文件拖到这里,或点击选择文件";
}
function addActivity(title, body, tone = "") {
@ -397,6 +502,42 @@ function setActivityActions(item, buttons) {
for (const button of buttons) actions.append(button);
}
async function copyTextToClipboard(text) {
if (globalThis.isSecureContext === false) {
return copyTextWithSelection(text);
}
const clipboard = navigator.clipboard;
if (clipboard?.writeText) {
try {
await clipboard.writeText(text);
return true;
} catch {}
}
return copyTextWithSelection(text);
}
function copyTextWithSelection(text) {
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.setAttribute("readonly", "");
textArea.style.position = "fixed";
textArea.style.top = "-9999px";
textArea.style.left = "-9999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
textArea.setSelectionRange(0, text.length);
try {
return document.execCommand("copy");
} catch {
return false;
} finally {
document.body.removeChild(textArea);
}
}
function updateTransferActivity(transfer, status, tone) {
if (!transfer) return;
const item = upsertActivity({

159
web/app.test.mjs Normal file
View File

@ -0,0 +1,159 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import vm from "node:vm";
function loadAppContext(overrides = {}) {
const selectors = new Map();
const body = {
children: [],
appendChild(node) {
node.parentElement = this;
this.children.push(node);
return node;
},
removeChild(node) {
this.children = this.children.filter((child) => child !== node);
node.parentElement = null;
return node;
}
};
const document = {
body,
userActivation: true,
execCommand(command) {
if (command !== "copy") return false;
if (!this.userActivation) return false;
this.copiedText = this.activeElement?.value || "";
return true;
},
querySelector(selector) {
if (!selectors.has(selector)) {
selectors.set(selector, makeElement());
}
return selectors.get(selector);
},
querySelectorAll() {
return [];
},
createElement(tagName) {
const element = makeElement(tagName);
element.ownerDocument = document;
return element;
}
};
const context = {
document,
localStorage: {
getItem() {
return "";
},
setItem() {}
},
navigator: {},
isSecureContext: false,
location: { protocol: "http:", host: "192.168.1.10:10051" },
setTimeout() {},
clearTimeout() {},
WebSocket: { OPEN: 1 }
};
Object.assign(context, overrides);
const source = readFileSync(new URL("./app.js", import.meta.url), "utf8")
.replace("const state = {", "globalThis.state = {")
.replace(/boot\(\)\.catch\([\s\S]*?\n\}\);?\s*$/, "");
vm.runInNewContext(source, context);
return context;
}
function makeElement(tagName = "div") {
return {
tagName,
children: [],
className: "",
style: {},
value: "",
parentElement: null,
append(...nodes) {
for (const node of nodes) {
node.parentElement = this;
this.children.push(node);
}
},
focus() {
if (this.ownerDocument) this.ownerDocument.activeElement = this;
},
select() {
this.selected = true;
},
setSelectionRange(start, end) {
this.selectionStart = start;
this.selectionEnd = end;
},
setAttribute() {},
addEventListener() {},
querySelector() {
return makeElement();
}
};
}
test("copyTextToClipboard falls back when navigator.clipboard is unavailable", async () => {
const context = loadAppContext();
const text = '{\n "copy": "json text"\n}';
const copied = await context.copyTextToClipboard(text);
assert.equal(copied, true);
assert.equal(context.document.copiedText, text);
});
test("copyTextToClipboard uses the synchronous fallback first on insecure remote pages", async () => {
const context = loadAppContext();
context.navigator.clipboard = {
async writeText() {
context.document.userActivation = false;
throw new Error("Clipboard API blocked on insecure context");
}
};
const text = `[
{
"id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImFlNjc5NWRjLTRiYWUtNDE4YS04NjVkLTA4YTY0MzllZWRhNiIsInR5cCI6IkpXVCJ9..UVl-YCSs3lfN6QLMGH03qfE3pBH7YYuEV2be8hV6VQDFRX0-bMMlWvB9sE0DCnfnDSRCOw4_fh7V72fg",
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImFlNjc5NWRjLTRiYWUtNDE4YS04NjVkLTA4YTY0MzllZWRhNiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiaHR0cHM6LykJzi2DPDA1mEUCMRCyg_3tGuskm0bQlbo0_ttDv53sF-fO-7nEPHqBDO7KpKPQPvG9w3HdTXtxPktHNkcmO5453BHc61ONukP2QJUp-OBv6T2mvC4ZKq6TlgOaXxrH32sMV4VtixWDbmmlrZ0zbXD72_WMS9mWR7wQLDN21-fCyaLma0cbLuWyxSqyWvkMIeuBEnFcTZVAcrgwd1lTw0e-pdsfVGyDiqDg2ZNs_Bk7vdk8c3VVcpZA5o7SEZUEaJRN-9ncI11INQpf5BubH8zCMnFa5u2fLfvtThZ_JON75mGKPBdwJYpY5FMjscBipu95RXf4ch0PQieCSoROx21YI6z7gSvvMHL-rCc",
"refresh_token": "rt.1.AACMpNpZuZ1c2Q0I9Bdcv7uo-5HKMEM3oz3XDEe_94-NGxq9TPQODzZ6SzYo66U6Ef4Efyub2ocxy4NrJRqtzz-ZthgvY6SG4PvQJYdUH9MZEwFCRsq22FTb__oE_t_QGVqGSbNIhZ2XhT8Lzvb7gI9utaKG9uH3P1zofogkRXlC3Xb8zd8okhjRl8QDFz8",
"account_id": "c1f",
"last_refresh": "",
"email": "l,
"type": "",
"expired": "2Z"
}
]`;
const copied = await context.copyTextToClipboard(text);
assert.equal(copied, true);
assert.equal(context.document.copiedText, text);
});
test("renderServerInfo displays configured public URLs without private LAN filtering", () => {
const context = loadAppContext();
const serverAddress = context.document.querySelector("#serverAddress");
context.state.serverInfo = {
urls: ["https://drop.company.lan", "http://10.20.8.138:10051"]
};
context.renderServerInfo();
assert.equal(serverAddress.textContent, "https://drop.company.lan");
assert.equal(serverAddress.title, "https://drop.company.lan\nhttp://10.20.8.138:10051");
});
test("copyServerAddress copies the visible server URL", async () => {
const context = loadAppContext();
const serverAddress = context.document.querySelector("#serverAddress");
serverAddress.textContent = "http://10.20.8.138:10051";
const copied = await context.copyServerAddress();
assert.equal(copied, true);
assert.equal(context.document.copiedText, "http://10.20.8.138:10051");
});

9
web/icon.svg Normal file
View File

@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" role="img" aria-labelledby="title desc">
<title id="title">Internal Drop icon</title>
<desc id="desc">A simple blue local transfer mark with a white drop arrow and receiving line.</desc>
<rect width="256" height="256" rx="58" fill="#1e88e5"/>
<circle cx="128" cy="128" r="74" fill="none" stroke="#ffffff" stroke-width="14" opacity="0.24"/>
<path d="M128 66v96" fill="none" stroke="#ffffff" stroke-width="18" stroke-linecap="round"/>
<path d="M92 105 128 69l36 36" fill="none" stroke="#ffffff" stroke-width="18" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M82 178h92" fill="none" stroke="#ffffff" stroke-width="18" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 736 B

View File

@ -4,26 +4,78 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Internal Drop</title>
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="stylesheet" href="/styles.css">
</head>
<body>
<main class="app-shell">
<section class="topbar">
<header class="topbar">
<div class="brand-block">
<span class="product-kicker">LAN transfer desk</span>
<img class="brand-mark" src="/icon.svg" alt="" aria-hidden="true">
<div class="brand-copy">
<span class="product-kicker">LAN transfer</span>
<h1>Internal Drop</h1>
</div>
<div class="top-meta">
<div class="server-line">
<span>服务器</span>
<code id="serverAddress">检测中</code>
</div>
<nav class="utility-nav" aria-label="工具面板">
<button class="panel-toggle" type="button" data-panel="peersPanel" aria-expanded="false">成员 <span id="peerCount">0</span></button>
<button class="panel-toggle" type="button" data-panel="textPanel" aria-expanded="false">文字</button>
<button class="panel-toggle" type="button" data-panel="activityPanel" aria-expanded="false">状态</button>
<button class="panel-toggle" type="button" data-panel="identityPanel" aria-expanded="false">我的 ID</button>
<button class="panel-toggle" type="button" data-panel="serverPanel" aria-expanded="false">服务器</button>
</nav>
<div id="connectionState" class="state">连接中</div>
</div>
</header>
<section class="drop-stage" aria-label="文件投放区">
<div class="selected-peer" id="selectedPeer">未选择接收方</div>
<button id="dropZone" class="drop-zone" type="button" aria-label="选择或拖入文件发送" aria-describedby="dropHint">
<span class="drop-ring" aria-hidden="true"></span>
<span class="drop-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none">
<path d="M12 15V4m0 0 4.5 4.5M12 4 7.5 8.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M5 14.5v2.8A2.7 2.7 0 0 0 7.7 20h8.6a2.7 2.7 0 0 0 2.7-2.7v-2.8" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
</svg>
</span>
<span id="dropHint">选择在线成员后,把文件拖到这里,或点击选择文件</span>
</button>
<input id="fileInput" type="file" aria-label="选择文件">
<progress id="uploadProgress" max="100" value="0"></progress>
</section>
<section class="identity-bar">
<div class="identity-code">
<section class="panel-dock" aria-label="可折叠信息面板">
<aside id="peersPanel" class="dock-panel" hidden>
<header>
<h2>在线成员</h2>
<span class="panel-note">选择一个接收方</span>
</header>
<select id="targetSelect" aria-label="发送给"></select>
<div id="peerList" class="peer-list"></div>
</aside>
<aside id="textPanel" class="dock-panel text-panel" hidden>
<header>
<h2>发送文字</h2>
<span class="panel-note">发送给当前选中成员</span>
</header>
<textarea id="textInput" rows="3" placeholder="输入要发送的文字"></textarea>
<button id="sendText" type="button">发送文字</button>
</aside>
<aside id="activityPanel" class="dock-panel activity-panel" hidden>
<header>
<h2>接收与状态</h2>
<button id="clearLog" class="secondary small-button" type="button">清空</button>
</header>
<div id="activityList" class="activity-list"></div>
</aside>
<aside id="identityPanel" class="dock-panel" hidden>
<header>
<h2>我的 ID</h2>
<span class="panel-note">用于识别当前设备</span>
</header>
<div class="identity-card">
<span>用户码</span>
<strong id="userCode">------</strong>
</div>
@ -35,45 +87,18 @@
<button id="saveName" type="button">保存</button>
<button id="regenCode" type="button" class="secondary">换码</button>
</div>
</section>
<section class="workspace">
<aside class="peer-panel">
<header>
<h2>在线成员</h2>
<span id="peerCount">0</span>
</header>
<div id="peerList" class="peer-list"></div>
</aside>
<section class="send-panel">
<div class="target-row">
<label for="targetSelect">发送给</label>
<select id="targetSelect"></select>
</div>
<div class="composer">
<label for="textInput">文字</label>
<textarea id="textInput" rows="3" placeholder="输入要发送的文字"></textarea>
<button id="sendText" type="button">发送文字</button>
</div>
<div class="file-box">
<input id="fileInput" type="file">
<button id="sendFile" type="button">发送文件</button>
<progress id="uploadProgress" max="100" value="0"></progress>
</div>
</section>
<section class="activity-panel">
<aside id="serverPanel" class="dock-panel" hidden>
<header>
<h2>接收与状态</h2>
<button id="clearLog" type="button">清空</button>
<h2>服务器 IP</h2>
<span class="panel-note">可分享访问地址</span>
</header>
<div id="activityList" class="activity-list"></div>
</section>
<code id="serverAddress" class="server-address">检测中</code>
<button id="copyServerAddress" type="button" class="secondary">复制地址</button>
</aside>
</section>
</main>
<script src="/app.js"></script>
<script src="/app.js?v=20260622-public-urls-v1"></script>
</body>
</html>

View File

@ -1,24 +1,26 @@
:root {
color-scheme: light;
--bg: #eef2f5;
--bg: #f5f7fb;
--bg-2: #e9f0f7;
--surface: #ffffff;
--surface-subtle: #f7f9fb;
--surface-soft: #f8fafc;
--ink: #111827;
--muted: #64748b;
--line: #d8e0e8;
--line-strong: #c6d1dc;
--primary: #0f766e;
--primary-strong: #115e59;
--primary-soft: #e3f5f2;
--blue: #2563eb;
--muted: #667085;
--line: #d9e2ec;
--line-strong: #c8d3df;
--primary: #176b87;
--primary-strong: #0f5369;
--primary-soft: #e7f4f7;
--blue: #2f6fed;
--blue-soft: #eaf1ff;
--ok: #166534;
--ok-soft: #eaf7ee;
--warn: #9a5b00;
--warn-soft: #fff4dc;
--warn: #995f00;
--warn-soft: #fff5df;
--bad: #a33838;
--bad-soft: #fff0f0;
--shadow: 0 16px 40px rgba(28, 45, 64, 0.08);
--shadow-sm: 0 8px 24px rgba(31, 45, 61, 0.08);
--shadow-lg: 0 24px 80px rgba(31, 45, 61, 0.16);
}
* {
@ -28,9 +30,11 @@
body {
margin: 0;
min-height: 100vh;
overflow-x: hidden;
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0) 220px),
var(--bg);
radial-gradient(circle at top left, rgba(47, 111, 237, 0.12), transparent 34vw),
radial-gradient(circle at bottom right, rgba(23, 107, 135, 0.12), transparent 30vw),
linear-gradient(180deg, var(--bg), var(--bg-2));
color: var(--ink);
font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
@ -44,39 +48,27 @@ textarea {
button {
min-height: 44px;
border: 1px solid var(--primary);
border: 1px solid var(--line-strong);
border-radius: 8px;
background: var(--primary);
color: #fff;
background: var(--surface);
color: var(--ink);
cursor: pointer;
padding: 0 16px;
padding: 0 14px;
font-weight: 700;
transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease;
}
button:hover {
background: var(--primary-strong);
border-color: var(--primary-strong);
}
button.secondary,
.activity button.secondary {
background: #fff;
color: var(--primary-strong);
border-color: var(--line-strong);
}
button.secondary:hover,
.activity button.secondary:hover {
border-color: var(--primary);
background: var(--primary-soft);
color: var(--primary-strong);
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
outline: 3px solid rgba(37, 99, 235, 0.22);
outline: 3px solid rgba(47, 111, 237, 0.22);
outline-offset: 2px;
}
@ -86,34 +78,37 @@ button:disabled {
}
.app-shell {
width: min(1240px, calc(100% - 36px));
position: relative;
min-height: 100dvh;
width: min(1200px, calc(100% - 32px));
margin: 0 auto;
padding: 24px 0 36px;
}
.topbar,
.identity-bar,
.peer-panel,
.send-panel,
.activity-panel {
background: rgba(255, 255, 255, 0.92);
border: 1px solid rgba(216, 224, 232, 0.92);
border-radius: 8px;
box-shadow: var(--shadow);
padding: 22px 0 34px;
}
.topbar {
display: flex;
display: grid;
grid-template-columns: minmax(180px, 1fr) auto auto;
align-items: center;
justify-content: space-between;
gap: 20px;
margin-bottom: 12px;
padding: 18px 20px;
gap: 16px;
min-height: 64px;
}
.brand-block {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 48px;
height: 48px;
border-radius: 15px;
box-shadow: 0 10px 28px rgba(23, 107, 135, 0.24);
}
.brand-copy {
display: grid;
gap: 4px;
gap: 2px;
}
.product-kicker {
@ -127,94 +122,209 @@ button:disabled {
h1,
h2 {
margin: 0;
letter-spacing: 0;
line-height: 1.2;
letter-spacing: 0;
}
h1 {
font-size: 28px;
font-size: clamp(24px, 4vw, 34px);
}
h2 {
font-size: 15px;
}
.top-meta {
.utility-nav {
display: flex;
align-items: center;
justify-content: flex-end;
flex-wrap: wrap;
gap: 10px;
min-width: 0;
}
.server-line {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
color: var(--muted);
}
.server-line span {
font-size: 12px;
font-weight: 700;
}
.server-line code {
display: inline-block;
max-width: min(460px, 52vw);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
border: 1px solid var(--line);
.panel-toggle {
min-height: 40px;
border-radius: 999px;
background: var(--surface-subtle);
color: #334155;
padding: 5px 10px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
background: rgba(255, 255, 255, 0.82);
backdrop-filter: blur(12px);
padding: 0 13px;
font-size: 13px;
box-shadow: 0 6px 20px rgba(31, 45, 61, 0.06);
}
.identity-bar {
display: grid;
grid-template-columns: auto minmax(220px, 320px) auto;
align-items: end;
gap: 12px;
margin-bottom: 16px;
padding: 14px 16px;
.panel-toggle[aria-expanded="true"] {
border-color: var(--primary);
background: var(--primary);
color: #fff;
}
.identity-code,
.nickname-field {
display: grid;
gap: 5px;
}
.identity-code span,
.nickname-field span,
.target-row label,
.composer label {
color: var(--muted);
font-size: 12px;
font-weight: 700;
}
.identity-code strong {
#peerCount {
display: inline-flex;
align-items: center;
min-height: 44px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--primary-soft);
padding: 0 14px;
color: var(--primary-strong);
font: 800 20px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
justify-content: center;
min-width: 22px;
margin-left: 4px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.65);
padding: 1px 6px;
font-size: 12px;
}
.identity-actions {
.state {
justify-self: end;
border: 1px solid var(--line-strong);
border-radius: 999px;
background: rgba(255, 255, 255, 0.82);
color: var(--muted);
padding: 8px 12px;
white-space: nowrap;
font-size: 13px;
font-weight: 800;
}
.state.online {
border-color: #b8dfc8;
background: var(--ok-soft);
color: var(--ok);
}
.state.offline {
border-color: #efc4c4;
background: var(--bad-soft);
color: var(--bad);
}
.drop-stage {
display: grid;
place-items: center;
min-height: calc(100dvh - 132px);
padding: 28px 0;
}
.selected-peer {
align-self: end;
margin-bottom: 16px;
border: 1px solid rgba(200, 211, 223, 0.9);
border-radius: 999px;
background: rgba(255, 255, 255, 0.74);
color: #334155;
padding: 8px 14px;
font-size: 13px;
font-weight: 800;
box-shadow: var(--shadow-sm);
}
.drop-zone {
position: relative;
display: grid;
place-items: center;
gap: 10px;
width: min(520px, 78vw);
aspect-ratio: 1;
border: 1px solid rgba(200, 211, 223, 0.95);
border-radius: 50%;
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.88)),
var(--surface);
color: var(--ink);
box-shadow: var(--shadow-lg);
text-align: center;
padding: 52px;
}
.drop-zone:hover,
.drop-zone.drag-over {
border-color: var(--primary);
background: linear-gradient(180deg, #ffffff, var(--primary-soft));
}
.drop-zone:disabled {
opacity: 0.82;
}
.drop-ring {
position: absolute;
inset: 10%;
border: 1px dashed rgba(23, 107, 135, 0.28);
border-radius: 50%;
pointer-events: none;
}
.drop-icon {
display: grid;
place-items: center;
width: 78px;
height: 78px;
border-radius: 50%;
background: var(--blue-soft);
color: var(--blue);
}
.drop-icon svg {
width: 38px;
height: 38px;
}
.drop-zone #dropHint {
max-width: 290px;
color: var(--muted);
font-size: clamp(16px, 2.2vw, 20px);
font-weight: 800;
}
#fileInput {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
clip-path: inset(50%);
white-space: nowrap;
}
#uploadProgress {
width: min(360px, 70vw);
height: 9px;
margin-top: 18px;
accent-color: var(--primary);
}
.panel-dock {
position: fixed;
z-index: 20;
top: 92px;
right: max(18px, calc((100vw - 1200px) / 2));
display: grid;
gap: 10px;
width: min(420px, calc(100vw - 28px));
pointer-events: none;
}
.dock-panel {
pointer-events: auto;
border: 1px solid rgba(217, 226, 236, 0.95);
border-radius: 8px;
background: rgba(255, 255, 255, 0.96);
box-shadow: var(--shadow-lg);
padding: 16px;
backdrop-filter: blur(16px);
}
.dock-panel[hidden] {
display: none;
}
.dock-panel header {
display: flex;
gap: 8px;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.panel-note {
color: var(--muted);
font-size: 12px;
}
input,
@ -230,95 +340,33 @@ textarea {
}
textarea {
min-height: 92px;
max-height: 170px;
min-height: 96px;
max-height: 180px;
resize: vertical;
}
.state {
border: 1px solid var(--line);
border-radius: 999px;
background: var(--surface-subtle);
color: var(--muted);
padding: 6px 12px;
white-space: nowrap;
font-size: 13px;
font-weight: 700;
}
.state.online {
border-color: #b8dfc8;
background: var(--ok-soft);
color: var(--ok);
}
.state.offline {
border-color: #efc4c4;
background: var(--bad-soft);
color: var(--bad);
}
.workspace {
display: grid;
grid-template-columns: minmax(220px, 270px) minmax(360px, 1fr) minmax(420px, 520px);
gap: 16px;
align-items: start;
}
.peer-panel,
.send-panel,
.activity-panel {
min-height: 420px;
padding: 16px;
}
.peer-panel header,
.activity-panel header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 14px;
}
#peerCount {
border-radius: 999px;
background: var(--blue-soft);
color: var(--blue);
min-width: 30px;
padding: 3px 9px;
text-align: center;
font-size: 12px;
font-weight: 800;
}
.peer-list,
.activity-list {
display: grid;
gap: 8px;
}
.peer-list {
margin-top: 10px;
}
.peer {
display: grid;
width: 100%;
min-height: 58px;
border: 1px solid var(--line);
border-radius: 8px;
padding: 11px 12px;
cursor: pointer;
background: #fff;
transition: background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}
.peer:hover {
border-color: var(--primary);
box-shadow: 0 8px 24px rgba(15, 118, 110, 0.08);
}
.peer.selected {
border-color: var(--primary);
background: var(--primary-soft);
padding: 10px 12px;
text-align: left;
}
.peer strong {
display: block;
overflow-wrap: anywhere;
}
@ -328,23 +376,73 @@ textarea {
font-size: 12px;
}
.target-row,
.composer,
.file-box {
.peer.selected {
border-color: var(--primary);
background: var(--primary-soft);
}
.text-panel {
display: grid;
gap: 9px;
margin-bottom: 16px;
gap: 10px;
}
.file-box {
border-top: 1px solid var(--line);
padding-top: 16px;
.text-panel header {
margin-bottom: 2px;
}
progress {
width: 100%;
height: 10px;
accent-color: var(--primary);
.identity-card,
.nickname-field {
display: grid;
gap: 6px;
margin-bottom: 12px;
}
.identity-card span,
.nickname-field span {
color: var(--muted);
font-size: 12px;
font-weight: 800;
}
.identity-card strong {
display: inline-flex;
align-items: center;
min-height: 48px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--primary-soft);
padding: 0 14px;
color: var(--primary-strong);
font: 900 22px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.identity-actions {
display: flex;
gap: 8px;
}
.server-address {
display: block;
overflow-wrap: anywhere;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--surface-soft);
padding: 12px;
color: #334155;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.small-button,
.activity button {
min-height: 34px;
padding: 0 10px;
font-size: 12px;
}
.secondary,
.activity button.secondary {
background: #fff;
color: var(--primary-strong);
}
.activity {
@ -388,7 +486,7 @@ progress {
.activity-status {
border-radius: 999px;
background: var(--surface-subtle);
background: var(--surface-soft);
color: var(--muted);
padding: 4px 8px;
font-size: 12px;
@ -407,13 +505,6 @@ progress {
gap: 6px;
}
.activity button {
min-height: 32px;
border-radius: 7px;
padding: 0 10px;
font-size: 12px;
}
.activity-progress {
grid-column: 1 / -1;
height: 5px;
@ -458,47 +549,45 @@ progress {
}
}
@media (max-width: 1080px) {
.workspace {
grid-template-columns: minmax(210px, 260px) minmax(0, 1fr);
}
.activity-panel {
grid-column: 1 / -1;
}
}
@media (max-width: 760px) {
@media (max-width: 820px) {
.app-shell {
width: min(100% - 20px, 1240px);
padding-top: 10px;
width: min(100% - 20px, 1200px);
padding-top: 12px;
}
.topbar,
.identity-bar {
align-items: flex-start;
.topbar {
grid-template-columns: 1fr;
}
.topbar,
.top-meta,
.identity-actions {
flex-direction: column;
align-items: stretch;
.utility-nav,
.state {
justify-self: stretch;
}
.workspace {
grid-template-columns: 1fr;
.utility-nav {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.peer-panel,
.send-panel,
.activity-panel {
.panel-toggle {
width: 100%;
padding: 0 10px;
}
.drop-stage {
min-height: auto;
padding: 36px 0 20px;
}
.server-line code {
max-width: 100%;
.drop-zone {
width: min(440px, 86vw);
padding: 34px;
}
.panel-dock {
position: static;
width: 100%;
margin-top: 12px;
}
.activity {
@ -513,3 +602,14 @@ progress {
grid-column: 1 / -1;
}
}
@media (max-width: 520px) {
.utility-nav {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.drop-icon {
width: 64px;
height: 64px;
}
}