删除不必要的文件
This commit is contained in:
Vaica committed 2026-06-01 19:40:25 +08:00
1 parent e0e75708a7
commit 8f9fbfb97c
103 files changed
-6926

No files matched your search

-105
View File
@@ -1,105 +0,0 @@
const fs = require("fs");
const path = "E:/GitHub/blog/bot/index.js";
let c = fs.readFileSync(path, "utf8");
function findBlock(name) {
var idx = c.indexOf("CMD_HANDLERS." + name);
if (idx === -1) return null;
var depth = 0;
var i = idx;
for (; i < c.length; i++) {
if (c[i] === "{") depth++;
else if (c[i] === "}") {
depth--;
if (depth === 0) break;
}
}
return { start: idx, end: i + 2 };
}
// Fix 2: link_toggle
var b = findBlock("link_toggle");
if (!b) { console.log("ERR: link_toggle not found"); process.exit(1); }
var nb =
"CMD_HANDLERS.link_toggle = async function (chatId, url) {\n" +
" if (!url) return sendMessage(chatId, \"Usage: /link_toggle <url>\\nToggle visibility of a link.\");\n" +
" try {\n" +
" // Fetch all links to find current hidden state\n" +
" const listRes = await fetch(\"http://127.0.0.1:\" + WRITE_PORT + \"/api/rss/links?all=1\");\n" +
" const listData = await listRes.json();\n" +
" var link = (listData.links || []).find(function(l) { return l.url === url; });\n" +
" if (!link) return sendMessage(chatId, \"\u274c Link not found: \" + url);\n" +
" var newHidden = !link.hidden;\n" +
" const res = await fetch(\"http://127.0.0.1:\" + WRITE_PORT + \"/api/rss/links\", {\n" +
" method: \"PUT\",\n" +
" headers: { \"Content-Type\": \"application/json\" },\n" +
" body: JSON.stringify({ oldUrl: url, hidden: newHidden }),\n" +
" });\n" +
" if (!res.ok) throw new Error((await res.json()).error || \"Toggle failed\");\n" +
" var label = newHidden ? \"\uD83D\uDD12 Hidden\" : \"\uD83C\uDF10 Visible\";\n" +
" return sendMessage(chatId, label + \": \" + url);\n" +
" } catch (e) {\n" +
" return sendMessage(chatId, \"\u274c \" + e.message);\n" +
" }\n" +
"};\n";
c = c.substring(0, b.start) + nb + c.substring(b.end);
console.log("2/4: link_toggle fixed");
// Fix 3: feed_check
b = findBlock("feed_check");
if (!b) { console.log("ERR: feed_check not found"); process.exit(1); }
nb =
"CMD_HANDLERS.feed_check = async function (chatId) {\n" +
" try {\n" +
" // First get all feeds\n" +
" const feedsRes = await fetch(\"http://127.0.0.1:\" + WRITE_PORT + \"/api/rss/feeds\");\n" +
" const feedsData = await feedsRes.json();\n" +
" var feeds = feedsData.feeds || [];\n" +
" if (feeds.length === 0) return sendMessage(chatId, \"No feeds to check.\");\n" +
" var results = [];\n" +
" for (var i = 0; i < feeds.length; i++) {\n" +
" var f = feeds[i];\n" +
" try {\n" +
" var hRes = await fetch(\"http://127.0.0.1:\" + WRITE_PORT + \"/api/rss/feeds?health=\" + encodeURIComponent(f.url));\n" +
" var hData = await hRes.json();\n" +
" results.push({ feedTitle: f.feedTitle, url: f.url, ok: hData.ok, status: hData.status, latency: hData.latency, error: hData.error });\n" +
" } catch (e2) {\n" +
" results.push({ feedTitle: f.feedTitle, url: f.url, ok: false, error: e2.message });\n" +
" }\n" +
" }\n" +
" var lines = [\"\uD83D\uDCE1 <b>Feed Health</b>\\n\"];\n" +
" results.forEach(function(r) {\n" +
" var icon = r.ok ? \"\u2705\" : \"\u274c\";\n" +
" var label = (r.feedTitle || r.url).slice(0, 40);\n" +
" var info = r.ok ? (r.latency || 0) + \"ms\" : (r.error || \"error\");\n" +
" lines.push(icon + \" \" + label + \" (\" + info + \")\");\n" +
" });\n" +
" return sendMessage(chatId, lines.join(\"\\n\"));\n" +
" } catch (e) {\n" +
" return sendMessage(chatId, \"Please /start Write first.\");\n" +
" }\n" +
"};\n";
c = c.substring(0, b.start) + nb + c.substring(b.end);
console.log("3/4: feed_check fixed");
// Fix 4: feed_del
b = findBlock("feed_del");
if (!b) { console.log("ERR: feed_del not found"); process.exit(1); }
nb =
"CMD_HANDLERS.feed_del = async function (chatId, url) {\n" +
" if (!url) return sendMessage(chatId, \"Usage: /feed_del <url>\\nUse /feeds to find the URL.\");\n" +
" try {\n" +
" const res = await fetch(\"http://127.0.0.1:\" + WRITE_PORT + \"/api/rss/feeds?url=\" + encodeURIComponent(url), {\n" +
" method: \"DELETE\",\n" +
" });\n" +
" if (!res.ok) throw new Error((await res.json()).error || \"Delete failed\");\n" +
" return sendMessage(chatId, \"\u2702 Feed deleted: \" + url);\n" +
" } catch (e) {\n" +
" return sendMessage(chatId, \"\u274c \" + e.message);\n" +
" }\n" +
"};\n";
c = c.substring(0, b.start) + nb + c.substring(b.end);
console.log("4/4: feed_del fixed");
fs.writeFileSync(path, c, "utf8");
console.log("All fixes applied successfully!");
-40
View File
@@ -1,40 +0,0 @@
const fs = require("fs");
const path = "E:/GitHub/blog/bot/index.js";
let c = fs.readFileSync(path, "utf8");
function findBlock(name) {
var idx = c.indexOf("CMD_HANDLERS." + name);
if (idx === -1) return null;
var depth = 0;
var i = idx;
for (; i < c.length; i++) {
if (c[i] === "{") depth++;
else if (c[i] === "}") {
depth--;
if (depth === 0) break;
}
}
return { start: idx, end: i + 2 };
}
// Fix 1: link_del (was missed earlier)
var b = findBlock("link_del");
if (!b) { console.log("ERR: link_del not found"); process.exit(1); }
var nb =
"CMD_HANDLERS.link_del = async function (chatId, url) {\n" +
" if (!url) return sendMessage(chatId, \"Usage: /link_del <url>\\nUse /links to find the URL.\");\n" +
" try {\n" +
" const res = await fetch(\"http://127.0.0.1:\" + WRITE_PORT + \"/api/rss/links?url=\" + encodeURIComponent(url), {\n" +
" method: \"DELETE\",\n" +
" });\n" +
" if (!res.ok) throw new Error((await res.json()).error || \"Delete failed\");\n" +
" return sendMessage(chatId, \"\u2702 Link deleted: \" + url);\n" +
" } catch (e) {\n" +
" return sendMessage(chatId, \"\u274c \" + e.message);\n" +
" }\n" +
"};\n";
c = c.substring(0, b.start) + nb + c.substring(b.end);
console.log("1/1: link_del fixed");
fs.writeFileSync(path, c, "utf8");
console.log("Done!");
-134
View File
@@ -1,134 +0,0 @@
const fs = require("fs");
const path = require("path");
const html = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<title>WriteBot</title>
<style>
:root{color-scheme:dark;--bg:#111827;--card:#1f2937;--text:#f3f4f6;--muted:#9ca3af;--accent:#60a5fa;--accent-hover:#93bbfd;--danger:#fca5a5;--success:#86efac;--line:#374151}
*{box-sizing:border-box;margin:0;padding:0}
body{background:var(--bg);color:var(--text);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;padding:20px}
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:28px;max-width:420px;width:100%}
h1{font-size:18px;font-weight:700;margin-bottom:6px}
.sub{font-size:13px;color:var(--muted);margin-bottom:20px}
.status-row{display:flex;align-items:center;gap:10px;padding:12px 16px;background:rgba(255,255,255,0.03);border-radius:8px;margin-bottom:16px}
.dot{width:10px;height:10px;border-radius:50%;flex-shrink:0}
.dot.running{background:var(--success)}
.dot.starting{background:#fbbf24}
.dot.stopped{background:var(--muted)}
.status-text{font-size:14px;font-weight:500}
.status-ip{font-size:12px;color:var(--muted);margin-top:2px}
.actions{display:flex;gap:8px;flex-wrap:wrap}
.btn{padding:10px 20px;border-radius:8px;font-size:14px;font-weight:600;border:none;cursor:pointer;transition:all 0.15s;color:#fff}
.btn-primary{background:var(--accent)}
.btn-primary:hover{background:var(--accent-hover)}
.btn-primary:disabled{opacity:0.4;cursor:not-allowed}
.btn-secondary{background:transparent;border:1px solid var(--line);color:var(--text)}
.btn-secondary:hover{background:rgba(255,255,255,0.05)}
.btn-danger{background:transparent;border:1px solid var(--danger);color:var(--danger)}
.btn-danger:hover{background:rgba(252,165,165,0.1)}
.link-row{margin-top:16px;padding:10px 14px;background:rgba(255,255,255,0.03);border-radius:8px;font-size:13px;color:var(--muted);word-break:break-all}
.link-row a{color:var(--accent);text-decoration:none}
.quick-links{display:flex;gap:8px;margin-bottom:12px;flex-wrap:wrap}
.ql-btn{padding:6px 14px;border-radius:6px;background:rgba(255,255,255,0.05);border:1px solid var(--line);color:var(--accent);text-decoration:none;font-size:13px;font-weight:500;transition:all 0.15s}
.ql-btn:hover{background:rgba(255,255,255,0.1)}
.footer{margin-top:20px;font-size:11px;color:var(--muted);text-align:center}
</style>
</head>
<body>
<div class="card">
<h1>WriteBot</h1>
<div class="sub">Ctrl+D bookmark this page</div>
<div class="quick-links">
<a href="http://localhost:1313/posts/" class="ql-btn" target="_blank">Posts</a>
<a href="http://localhost:8016/" class="ql-btn" target="_blank">Write</a>
</div>
<div class="sub" id="sub">Loading...</div>
<div class="status-row">
<div class="dot" id="dot"></div>
<div>
<div class="status-text" id="statusText">-</div>
<div class="status-ip" id="statusIp"></div>
</div>
</div>
<div class="actions">
<button class="btn btn-primary" id="btnStart" onclick="action(\x27start\x27)">Start Write</button>
<button class="btn btn-secondary" id="btnOpen" onclick="openWrite()">Open</button>
<button class="btn btn-danger" id="btnStop" onclick="action(\x27stop\x27)">Stop</button>
</div>
<div class="link-row" id="linkRow" style="display:none">
Copy: <a href="#" id="lanLink" onclick="copyLink(event)"></a>
</div>
<div class="footer"><a href="https://usj.cc" style="color:var(--muted)">usj.cc</a></div>
</div>
<script>
var port=${8016};
var ipCache="";
function updateUI(s){var d=document.getElementById("dot"),st=document.getElementById("statusText"),si=document.getElementById("statusIp"),bs=document.getElementById("btnStart"),bo=document.getElementById("btnOpen"),lr=document.getElementById("linkRow"),ll=document.getElementById("lanLink");d.className="dot";if(s.running){d.classList.add("running");st.textContent="Running";if(s.ip)ipCache=s.ip;si.textContent="http://"+ipCache+":"+s.port;bs.disabled=true;bo.disabled=false;lr.style.display="block";ll.href="http://"+ipCache+":"+s.port;ll.textContent="http://"+ipCache+":"+s.port;document.getElementById("sub").textContent="Write is serving at"}else if(s.starting){d.classList.add("starting");st.textContent="Starting...";si.textContent="";bs.disabled=true;bo.disabled=true;lr.style.display="none";document.getElementById("sub").textContent="Please wait..."}else{d.classList.add("stopped");st.textContent="Stopped";si.textContent="";bs.disabled=false;bo.disabled=true;lr.style.display="none";document.getElementById("sub").textContent="Click Start to launch Write"}}
async function fetchStatus(){try{var r=await fetch("/status");var s=await r.json();updateUI(s)}catch(e){document.getElementById("sub").textContent="Cannot reach API"}}
async function action(a){document.getElementById("sub").textContent="Working...";await fetch("/"+a,{method:"POST"});fetchStatus()}
function openWrite(){window.open("http://"+(ipCache||"localhost:"+port))}
function copyLink(e){e.preventDefault();navigator.clipboard.writeText(document.getElementById("lanLink").textContent).catch(function(){})}
fetchStatus();
setInterval(fetchStatus,5000);
</script>
</body>
</html>`;
const fileContent = `// admin-panel.js - Minimal web admin panel + HTTP control API
const http = require("http");
const config = require("./config");
const { getLanIP } = require("./helpers");
const { startWriteServer, stopWriteServer, getWriteStatus } = require("./write-server");
const ADMIN_HTML = \`${html}\`.replace("var port=8016", "var port=\${config.WRITE_PORT}");
function createControlServer() {
const server = http.createServer((req, res) => {
const url = new URL(req.url, "http://127.0.0.1:" + config.CONTROL_PORT);
const path = url.pathname;
res.setHeader("Access-Control-Allow-Origin", "*");
if (path === "/" && req.method === "GET") {
res.setHeader("Content-Type", "text/html; charset=utf-8");
res.end(ADMIN_HTML);
} else if (path === "/status" && req.method === "GET") {
res.setHeader("Content-Type", "application/json");
const s = getWriteStatus();
s.ip = getLanIP();
s.port = config.WRITE_PORT;
res.end(JSON.stringify(s));
} else if (path === "/start" && req.method === "POST") {
res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify(startWriteServer()));
} else if (path === "/stop" && req.method === "POST") {
res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify({ ok: stopWriteServer() }));
} else if (path === "/ip" && req.method === "GET") {
res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify({ ip: getLanIP(), port: config.WRITE_PORT }));
} else if (path === "/health" && req.method === "GET") {
res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify({ ok: true }));
} else {
res.statusCode = 404;
res.setHeader("Content-Type", "application/json");
res.end(JSON.stringify({ error: "not found" }));
}
});
server.listen(config.CONTROL_PORT, "127.0.0.1", () => {
console.log("[control] http://127.0.0.1:" + config.CONTROL_PORT);
});
return server;
}
module.exports = { createControlServer };
`;
fs.writeFileSync(path.join(__dirname, "src", "admin-panel.js"), fileContent, "utf8");
console.log("admin-panel.js written (" + fileContent.length + " bytes)");
-3
View File
@@ -1,3 +0,0 @@
var fs=require("fs");
var c=fs.readFileSync("E:/GitHub/blog/bot/index.js","utf8");
function fb(n){var i=c.indexOf("CMD_HANDLERS."+n);if(i===-1)return null;var d=0;for(var j=i;j<c.length;j++){if(c[j]==="{")d++;else if(c[j]==="}"){d--;if(d===0)break;}}return{start:i,end:j+2}}
-55
View File
@@ -1,55 +0,0 @@
const fs = require("fs");
const path = "E:/GitHub/blog/bot/index.js";
let c = fs.readFileSync(path, "utf8");
// Insert start/stop/status/ip handlers before CMD_HANDLERS.view
var insertAt = c.indexOf("\nCMD_HANDLERS.view = async function");
if (insertAt === -1) { console.log("ERR: view not found"); process.exit(1); }
insertAt++; // after the newline
var handlers = `
CMD_HANDLERS.start = async function (chatId) {
if (writeProcess && writeReady) {
var ip = getLanIP();
await sendMessage(chatId, "\u2705 Write is running\n\nDesktop: http://localhost:" + WRITE_PORT + "\nPhone: http://" + ip + ":" + WRITE_PORT);
return CMD_HANDLERS.help(chatId);
}
if (writeProcess && !writeReady) {
return sendMessage(chatId, "\u23f3 Write is starting, please wait...");
}
var result = startWriteServer();
if (!result.started) return sendMessage(chatId, "\u274c Failed to start");
await sendMessage(chatId, "\u23f3 Starting Write...");
var ready = await waitForReady(WRITE_PORT);
if (ready) {
writeReady = true;
var ip = getLanIP();
await sendMessage(chatId, "\u2705 Write is ready!\n\nDesktop: http://localhost:" + WRITE_PORT + "\nPhone: http://" + ip + ":" + WRITE_PORT);
return CMD_HANDLERS.help(chatId);
}
return sendMessage(chatId, "\u274c Start timed out, check console log.");
},
async stop(chatId) {
if (!writeProcess) return sendMessage(chatId, "\u23f8 Write is not running.");
stopWriteServer();
return sendMessage(chatId, "\u26a1 Write stopped.");
},
async status(chatId) {
var s = getWriteStatus();
var status = s.running ? "\u2705 Running" : s.starting ? "\u23f3 Starting..." : "\u23f8 Stopped";
var lines = ["Status: " + status];
if (s.running) {
lines.push("Local: http://localhost:" + WRITE_PORT);
lines.push("Phone: http://" + s.ip + ":" + WRITE_PORT);
}
return sendMessage(chatId, lines.join("\n"));
},
async ip(chatId) {
var ip = getLanIP();
return sendMessage(chatId, "Phone: http://" + ip + ":" + WRITE_PORT + " (" + PREFER_IFACE + ")");
},
`;
c = c.substring(0, insertAt) + handlers + c.substring(insertAt);
fs.writeFileSync(path, c, "utf8");
console.log("start/stop/status/ip restored");
-63
View File
@@ -1,63 +0,0 @@
const fs = require("fs");
const path = "E:/GitHub/blog/bot/index.js";
let c = fs.readFileSync(path, "utf8");
// Fix the broken start/stop/status/ip handlers (newlines got literalized)
// Remove the broken block and re-insert correctly
var brokenStart = c.indexOf("\nCMD_HANDLERS.start = async function (chatId) {");
if (brokenStart === -1) { console.log("ERR: no start"); process.exit(1); }
// Find end of ip handler (the `},` before CMD_HANDLERS.view)
var afterIp = c.indexOf("CMD_HANDLERS.view = async function", brokenStart);
if (afterIp === -1) { console.log("ERR: no view after"); process.exit(1); }
// Remove broken block
c = c.substring(0, brokenStart + 1) + c.substring(afterIp);
// Insert correct handlers
var correctHandlers = `
CMD_HANDLERS.start = async function (chatId) {
if (writeProcess && writeReady) {
var ip = getLanIP();
await sendMessage(chatId, "\\u2705 Write is running\\n\\nDesktop: http://localhost:" + WRITE_PORT + "\\nPhone: http://" + ip + ":" + WRITE_PORT);
return CMD_HANDLERS.help(chatId);
}
if (writeProcess && !writeReady) {
return sendMessage(chatId, "\\u23f3 Write is starting, please wait...");
}
var result = startWriteServer();
if (!result.started) return sendMessage(chatId, "\\u274c Failed to start");
await sendMessage(chatId, "\\u23f3 Starting Write...");
var ready = await waitForReady(WRITE_PORT);
if (ready) {
writeReady = true;
var ip = getLanIP();
await sendMessage(chatId, "\\u2705 Write is ready!\\n\\nDesktop: http://localhost:" + WRITE_PORT + "\\nPhone: http://" + ip + ":" + WRITE_PORT);
return CMD_HANDLERS.help(chatId);
}
return sendMessage(chatId, "\\u274c Start timed out, check console log.");
},
async stop(chatId) {
if (!writeProcess) return sendMessage(chatId, "\\u23f8 Write is not running.");
stopWriteServer();
return sendMessage(chatId, "\\u26a1 Write stopped.");
},
async status(chatId) {
var s = getWriteStatus();
var status = s.running ? "\\u2705 Running" : s.starting ? "\\u23f3 Starting..." : "\\u23f8 Stopped";
var lines = ["Status: " + status];
if (s.running) {
lines.push("Local: http://localhost:" + WRITE_PORT);
lines.push("Phone: http://" + s.ip + ":" + WRITE_PORT);
}
return sendMessage(chatId, lines.join("\\n"));
},
async ip(chatId) {
var ip = getLanIP();
return sendMessage(chatId, "Phone: http://" + ip + ":" + WRITE_PORT + " (" + PREFER_IFACE + ")");
},
`;
c = c.substring(0, brokenStart + 1) + correctHandlers + c.substring(brokenStart + 1);
fs.writeFileSync(path, c, "utf8");
console.log("start/stop/status/ip fixed");