Skip to content

Latest commit

 

History

History
137 lines (118 loc) · 8.43 KB

CLAUDE.md

File metadata and controls

137 lines (118 loc) · 8.43 KB

ModelPublisher — Claude Context

What this project does

CLI tool that automates publishing 3D printable models to multiple platforms (Printables, MakerWorld, Cults3D, Thangs, MakerOnline, Patreon) using Playwright browser automation.

Stack

  • .NET 10, C#
  • Playwright.NET — browser automation (Brave browser, headless=false)
  • System.CommandLine 2.0.3 — use SetAction / ParseResult.GetValue (old Handler API is gone)
  • Spectre.Console — always wrap user-data strings with Markup.Escape(), square brackets crash it

Run the tool

cd C:\Source\ModelPublisher
dotnet run --project src\ModelPublisher.Cli -- "C:\Users\chris\Downloads\Models\<model-name>\manifest.json" --platforms printables

Key source files

File Purpose
src/ModelPublisher.Cli/Program.cs CLI entry point
src/ModelPublisher.Core/PublishCommand.cs Orchestrator — reads manifest, resolves tier, runs publishers, writes results JSON
src/ModelPublisher.Core/Platforms/IPlatformPublisher.cs Publisher interface
src/ModelPublisher.Core/Platforms/PrintablesPublisher.cs Only fully working publisher
src/ModelPublisher.Core/Shared/BrowserContextFactory.cs Launches persistent Brave context per platform
src/ModelPublisher.Core/Shared/AuthGuard.cs Pauses for human login when not authenticated
src/ModelPublisher.Core/Shared/FileUploadHelper.cs UploadSequentialAsync — uploads one file at a time, waits for NetworkIdle
src/ModelPublisher.Core/Shared/MarkdownHelper.cs ToPlainText and ToTipTapHtml — converts markdown for platforms that need it
src/ModelPublisher.Core/Models/ReleaseManifest.cs Deserializes manifest.json; GetPlatformConfig<T>() deserializes typed platform config
src/ModelPublisher.Core/Models/PlatformConfig.cs Base record with Tier + PrintProfiles — all platform configs inherit from this
src/ModelPublisher.Core/Platforms/PatreonConfig.cs Patreon-specific config: FreePost, AccessTierId
src/ModelPublisher.Core/Models/PublishResult.cs Result record — Tier is set by orchestrator via with, not by publishers

Manifest format

{
  "title": "...",
  "description": "... markdown ...",
  "tags": [],
  "license": "CC-BY-4.0",
  "files": {
    "models": ["./model.3mf"],
    "cover": "./cover-photo.jpg",
    "photos": ["./cover-photo.jpg", "./detail.jpg"]
  },
  "platforms": {
    "printables": {
      "tier": "free",
      "print_profiles": ["./profiles/printables-0.2mm.3mf"]
    },
    "patreon": {
      "tier": "premium",
      "free_post": false,
      "access_tier_id": "YOUR_TIER_ID"
    }
  }
}
  • cover is optional. If set, PhotosOrdered(coverFirst) deduplicates and positions it.
  • manifest.ManifestDirectory is set after deserialization; use ResolveFilePath() for all file paths.
  • print_profiles is optional on any platform; defaults to []. Paths are relative to manifest dir.
  • To read typed config in a publisher: manifest.GetPlatformConfig<PlatformConfig>(PlatformKey) (returns null if platform not listed). Use a subclass (e.g. PatreonConfig) for platform-specific fields.
  • Platforms stays Dictionary<string, JsonElement> internally — GetPlatformConfig<T> deserializes on demand.

Platform status

Key Platform Status
printables Printables.com Working
makerworld MakerWorld.com Stub — needs codegen selectors
cults3d Cults3D.com Stub — needs codegen selectors
thangs Thangs.com Stub — needs codegen selectors
makeronline Maker.online Stub — needs codegen selectors
patreon Patreon.com Stub — clipboard paste approach, needs verification

Printables — working selectors

  • Model input: input[type='file'][accept*='.3mf'] (also stl, obj, zip variants)
  • Photo input: input[type='file'][id='photos-upload-input'] — use manifest.Files.PhotosOrdered(coverFirst: false) (Printables uses last-uploaded as cover — though this is unconfirmed, see GitHub issue #5)
  • Title: GetByRole(AriaRole.Textbox, new() { Name = "Model name (required)" })
  • Summary: GetByRole(AriaRole.Textbox, new() { Name = "Summary (required)" })
  • Tags: GetByRole(AriaRole.Textbox, new() { Name = "Additional tags" }) + Enter per tag
  • Original model: GetByRole(AriaRole.Radio, new() { Name = "Original model – I made it" })
  • AI generated: GetByRole(AriaRole.Radio, new() { Name = "No — fully human-made" })
  • Description: inject via EvaluateAsync — MarkdownHelper.ToTipTapHtml(manifest.Description) → set el.innerHTML → dispatch input + change events
  • License: GetByRole(AriaRole.Button, new() { Name = "License (required)" })
  • Submit: GetByRole(AriaRole.Button, new() { Name = "Save draft" }) → wait for URL **/model/**
  • Auth check: [data-cy='user-menu'], .user-avatar, [aria-label='User menu']

Known gotchas

  • Printables description: uses TipTap (ProseMirror). FillAsync doesn't work — use EvaluateAsync to set innerHTML directly.
  • MarkdownHelper.ToPlainText: list markers replaced with • / 1. (not stripped). Lists processed before bold/italic to avoid * bullets being consumed by the bold regex.
  • PublishResult.Tier: init-only, set by orchestrator with result with { Tier = tier! }. Publishers do not set it.
  • Spectre.Console: any string containing [ or ] from user data must be wrapped in Markup.Escape().
  • System.CommandLine 2.0.3: SetAction + ParseResult.GetValue only — old Handler API removed.

Slopwatch

  • Installed globally: dotnet tool install --global Slopwatch.Cmd (v0.4.0)
  • Baseline initialized at .slopwatch/baseline.json (0 pre-existing issues on master)
  • Run after code changes: powershell.exe -Command "cd 'C:\Source\ModelPublisher'; slopwatch analyze -d ."
  • Detects: disabled tests, empty catch blocks, warning suppression, arbitrary delays, NoWarn in csproj, CPM bypass

GitHub workflow

  • Repo: https://github.com/TheCraftyMaker/ModelPublisher
  • master is protected — PRs required, no direct pushes, enforce_admins=true
  • Auto-delete branches on merge is enabled
  • gh CLI is NOT on bash PATH — call via: powershell.exe -Command "& 'C:\Program Files\GitHub CLI\gh.exe' ..."
  • All commits must include: Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
  • See .claude/skills/github-modelp/SKILL.md for the full workflow reference

Browser profiles

Persistent Chromium sessions stored in profiles/{platformKey}/ relative to working directory. Gitignored — contains login cookies. On first run per platform, the browser pauses for manual login.

Cloudflare / bot detection

Cloudflare detects Playwright's CDP protocol and blocks access even when a human clicks "I'm human". This affects MakerWorld and Patreon. Two mitigations are in place in BrowserContextFactory:

  • --disable-blink-features=AutomationControlled launch arg
  • Init script removing navigator.webdriver, spoofing canvas/WebGL/plugins

When these aren't enough, use --profile-path to run with the real Brave profile (which has cf_clearance cookies from normal browsing). Brave must be fully closed first.

# For publishing:
dotnet run --project src\ModelPublisher.Cli -- "manifest.json" --platforms makerworld --profile-path "C:\Users\chris\AppData\Local\BraveSoftware\Brave-Browser\User Data\Profile 1"

# For codegen:
dotnet run --project src\ModelPublisher.Cli -- codegen makerworld https://makerworld.com/en/my/models/publish?type=original --profile-path "C:\Users\chris\AppData\Local\BraveSoftware\Brave-Browser\User Data\Profile 1"

Google OAuth is blocked in all automated browsers (Playwright injects CDP which Google detects). Log into Cloudflare-protected platforms using email/password, not Google, during the AuthGuard pause.

Running Playwright codegen

npx playwright codegen does NOT work from Claude Code's bash shell (node not on PATH, GUI can't open in background). Always run codegen manually from a Windows terminal.

For sites without Cloudflare / bot detection — use the .NET playwright.ps1 (built output):

pwsh "C:\Source\ModelPublisher\src\ModelPublisher.Cli\bin\Debug\net10.0\playwright.ps1" codegen https://example.com

For sites with Cloudflare / Google auth (e.g. Patreon) — codegen won't work (Chromium is blocked). Instead: open the page in the regular Brave browser, interact with the form, and use DevTools (F12) to inspect elements. Paste HTML snippets into the conversation to extract selectors.