Local social media automation dashboard for TikTok, Instagram, and YouTube.
Add debug artifact cleanup command
Katzcae084ec24127b
diff --git a/README.md b/README.mdindex 1a484c6..29b5e74 100644--- a/README.md+++ b/README.md@@ -163,6 +163,7 @@ Caption sidecars can use the same base filename:```bashnpm run dashboard+npm run clean:debugnpm run doctornpm run checknpm run login@@ -176,6 +177,7 @@ npm run autodownloadNotes:- The dashboard is the preferred workflow.+- `clean:debug` removes local debug screenshots and dashboard logs only.- `login`, `post`, and `daemon` are TikTok CLI flows.- Instagram and YouTube posting are managed through the dashboard.- `uniquify` and `video-info` require FFmpeg and ffprobe.diff --git a/SETUP.md b/SETUP.mdindex dc5b248..ff72c0b 100644--- a/SETUP.md+++ b/SETUP.md@@ -179,6 +179,7 @@ empty to run without a logo overlay.```bashnpm run dashboard+npm run clean:debugnpm run doctornpm run checknpm run login@@ -228,6 +229,7 @@ npm run autodownload- `yt-dlp missing`: add `autodownload/yt-dlp.exe` or skip downloader features.- `No session found`: open the dashboard and log in for that platform.- Upload opens but does not finish: inspect `last-*.png` and dashboard logs.+- Stale debug screenshots/logs: run `npm run clean:debug`.- Schedule looks saved but nothing posts after restart: start the scheduler again.- Dashboard refuses remote bind: use `DASHBOARD_HOST=127.0.0.1` or explicitly set `DASHBOARD_ALLOW_REMOTE=true`.diff --git a/package.json b/package.jsonindex 06b0a07..db8e88c 100644--- a/package.json+++ b/package.json@@ -6,6 +6,7 @@"main": "src/cli.js","scripts": {"start": "node src/dashboard-server.js",+ "clean:debug": "node scripts/clean-runtime.js","check": "npm run check:syntax && npm test","check:syntax": "node scripts/check-syntax.js","doctor": "node scripts/doctor.js",diff --git a/scripts/clean-runtime.js b/scripts/clean-runtime.jsnew file mode 100644index 0000000..3d22449--- /dev/null+++ b/scripts/clean-runtime.js@@ -0,0 +1,78 @@+#!/usr/bin/env node+const fs = require("fs");+const path = require("path");++const projectRoot = path.resolve(__dirname, "..");++function collectCleanupTargets(root = projectRoot) {+ const targets = [];++ if (!fs.existsSync(root)) {+ return targets;+ }++ for (const entry of fs.readdirSync(root, { withFileTypes: true })) {+ if (!entry.isFile()) {+ continue;+ }++ if (/^last-.*\.png$/i.test(entry.name) || /^\.dashboard\..*\.log$/i.test(entry.name)) {+ targets.push(path.join(root, entry.name));+ }+ }++ const localLogDir = path.join(root, ".local");+ for (const logName of ["dashboard.out.log", "dashboard.err.log"]) {+ const logPath = path.join(localLogDir, logName);+ if (fs.existsSync(logPath)) {+ targets.push(logPath);+ }+ }++ return Array.from(new Set(targets)).sort();+}++function removeTargets(targets, { dryRun = false } = {}) {+ for (const target of targets) {+ if (dryRun) {+ console.log(`[dry-run] remove ${target}`);+ continue;+ }++ fs.rmSync(target, { force: true });+ console.log(`removed ${target}`);+ }+}++function printHelp() {+ console.log("Usage: npm run clean:debug -- [--dry-run]");+ console.log("");+ console.log("Removes local debug screenshots and dashboard logs only.");+ console.log("Profiles, queue media, account state, and .env are left untouched.");+}++function main(argv = process.argv.slice(2)) {+ if (argv.includes("--help") || argv.includes("-h")) {+ printHelp();+ return;+ }++ const dryRun = argv.includes("--dry-run");+ const targets = collectCleanupTargets(projectRoot);++ if (targets.length === 0) {+ console.log("No debug artifacts found.");+ return;+ }++ removeTargets(targets, { dryRun });+}++if (require.main === module) {+ main();+}++module.exports = {+ collectCleanupTargets,+ removeTargets,+};diff --git a/test/clean-runtime.test.js b/test/clean-runtime.test.jsnew file mode 100644index 0000000..b8a20e1--- /dev/null+++ b/test/clean-runtime.test.js@@ -0,0 +1,51 @@+const test = require("node:test");+const assert = require("node:assert/strict");+const fs = require("fs");+const os = require("os");+const path = require("path");++const { collectCleanupTargets, removeTargets } = require("../scripts/clean-runtime");++function touch(filePath) {+ fs.mkdirSync(path.dirname(filePath), { recursive: true });+ fs.writeFileSync(filePath, "x");+}++test("clean debug targets only include screenshots and dashboard logs", () => {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "autosocial-clean-"));+ try {+ const expectedTargets = [+ path.join(root, ".dashboard.out.log"),+ path.join(root, ".local", "dashboard.err.log"),+ path.join(root, ".local", "dashboard.out.log"),+ path.join(root, "last-upload-error.png"),+ path.join(root, "last-youtube-upload-success.png"),+ ];+ for (const target of expectedTargets) {+ touch(target);+ }++ const preserved = [+ path.join(root, ".env"),+ path.join(root, ".profiles", "default", "tiktok", "session"),+ path.join(root, "accounts-state.json"),+ path.join(root, "queue", "default", "tiktok", "pending", "video.mp4"),+ ];+ for (const target of preserved) {+ touch(target);+ }++ assert.deepEqual(collectCleanupTargets(root), expectedTargets.sort());++ removeTargets(collectCleanupTargets(root));++ for (const target of expectedTargets) {+ assert.equal(fs.existsSync(target), false);+ }+ for (const target of preserved) {+ assert.equal(fs.existsSync(target), true);+ }+ } finally {+ fs.rmSync(root, { recursive: true, force: true });+ }+});