Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
branches: [main, Testing]
pull_request:
branches: [main]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: pip install -r requirements.txt

- name: Syntax check
run: python -m py_compile app.py generator.py

- name: Import smoke test
run: python -c "import app; print('app imports OK')"
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ data/
Thumbs.db
.vscode/

# Local database (your drafts library)
*.db

# Generated logo
logo.png

# Never commit secrets
.env
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Set these as environment variables before starting the server:
| `PEXELS_API_KEY` | Better stock images (falls back to Openverse without it) |
| `LLM_MODEL` | Override the Claude model (default: `claude-sonnet-4-5`) |
| `PORT` | Change the web server port (default: 5000) |
| `LINKEDIN_CLIENT_ID` / `LINKEDIN_CLIENT_SECRET` | From your LinkedIn developer app — enables "Connect LinkedIn" and one-click posting |
| `BASE_URL` | Public URL of the site (e.g. `https://postpilot-nsks.onrender.com`), used for the OAuth redirect. Default: `http://localhost:5000` |
| `SECRET_KEY` | Random string for login sessions (generate one; without it, logins reset on every server restart) |

PowerShell example:

Expand Down
86 changes: 85 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@
})
.catch(() => { $("llm-badge").textContent = "offline"; });

// LinkedIn connection state
let liConnected = false;
const liBtn = $("li-connect");

function refreshLinkedIn() {
fetch("/api/linkedin/status")
.then((r) => r.json())
.then((s) => {
if (!s.configured) { liBtn.style.display = "none"; return; }
liBtn.style.display = "";
liConnected = s.connected;
if (s.connected) {
liBtn.textContent = `LinkedIn: ${s.name} ✓ (disconnect)`;
liBtn.onclick = () => {
fetch("/api/linkedin/logout", { method: "POST" }).then(refreshLinkedIn);
};
} else {
liBtn.textContent = "Connect LinkedIn";
liBtn.onclick = () => { window.location.href = "/auth/linkedin"; };
}
})
.catch(() => {});
}
refreshLinkedIn();

// Surface OAuth errors passed back as ?li_error=...
const liError = new URLSearchParams(window.location.search).get("li_error");
if (liError) setError("LinkedIn sign-in failed: " + liError);

function setError(msg) {
errorBox.textContent = msg;
errorBox.classList.toggle("visible", !!msg);
Expand Down Expand Up @@ -67,7 +96,11 @@
card.innerHTML = `
<div class="post-header">
<h3>Variant ${i + 1}</h3>
<button class="btn btn-ghost btn-sm copy-btn">Copy text</button>
<div style="display:flex; gap:8px;">
<button class="btn btn-ghost btn-sm copy-btn">Copy text</button>
<button class="btn btn-ghost btn-sm save-btn">Save to library</button>
<button class="btn btn-primary btn-sm li-post-btn">Post to LinkedIn</button>
</div>
</div>
${imgHtml}
<div class="post-body">${esc(d.text)}</div>
Expand All @@ -85,6 +118,57 @@
});
});

const saveBtn = card.querySelector(".save-btn");
saveBtn.addEventListener("click", async () => {
saveBtn.disabled = true;
try {
const r = await fetch("/api/library/save", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(d),
});
if (!r.ok) throw new Error((await r.json()).error || "Save failed");
saveBtn.textContent = "Saved ✓";
saveBtn.classList.add("copied");
} catch (e) {
saveBtn.disabled = false;
setError(e.message);
}
});

const liPostBtn = card.querySelector(".li-post-btn");
liPostBtn.addEventListener("click", async () => {
if (!liConnected) {
if (confirm("You need to connect your LinkedIn account first. Connect now?"))
window.location.href = "/auth/linkedin";
return;
}
if (!confirm("Post this draft to your LinkedIn profile? It will be publicly visible."))
return;
liPostBtn.disabled = true;
liPostBtn.textContent = "Posting…";
try {
const r = await fetch("/api/linkedin/post", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
text: d.text,
image_src: d.image ? d.image.src : "",
draft_id: d.id || "",
}),
});
const res = await r.json();
if (!r.ok) throw new Error(res.error || "Posting failed");
liPostBtn.textContent = res.with_image ? "Posted with image ✓" : "Posted ✓";
liPostBtn.classList.add("copied");
} catch (e) {
liPostBtn.disabled = false;
liPostBtn.textContent = "Post to LinkedIn";
setError(e.message);
if (String(e.message).includes("reconnect")) refreshLinkedIn();
}
});

results.appendChild(card);
});
}
Expand Down
Loading
Loading