### Install and Setup Go with update-golang script Source: https://github.com/bigjk/snd/wiki/Building Clones the update-golang repository, navigates into it, and executes the update script to install and set up Go. Ensure Go is available from the command line after installation. ```bash git clone https://github.com/udhos/update-golang cd update-golang sudo ./update-golang.sh ``` -------------------------------- ### Install Frontend Dependencies and Build Source: https://github.com/bigjk/snd/wiki/Building Navigates to the frontend directory, installs Node.js dependencies using npm, and then builds the frontend application. This step is required if you are not using a pre-built frontend. ```bash cd ./frontend npm i npm run build ``` -------------------------------- ### Install Git using apt-get or brew Source: https://github.com/bigjk/snd/wiki/Building Installs git using package managers. Use apt-get for Debian/Ubuntu based systems and brew for macOS. ```bash sudo apt-get install git ``` ```bash brew install git ``` -------------------------------- ### Install Git and USB Library Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Installs essential tools like Git and the libusb library required for the project. ```bash sudo apt-get install git libusb-1.0.0 ``` -------------------------------- ### Build S&D Frontend from Source Source: https://context7.com/bigjk/snd/llms.txt Commands to build the S&D frontend. Requires Node.js and npm to be installed. ```bash # Build the frontend (requires Node.js + npm) cd frontend npm install npm run build cd .. ``` -------------------------------- ### Build S&D with Electron and USB Support from Source Source: https://context7.com/bigjk/snd/llms.txt Builds the S&D binary with both Electron desktop window and raw USB support. Ensure libusb is installed. ```bash # Build with Electron desktop window + USB cd cmd/app && go build -o ../../snd -tags="ELECTRON LIBUSB" && cd ../.. ``` -------------------------------- ### Build S&D with Raw USB Support from Source Source: https://context7.com/bigjk/snd/llms.txt Builds the S&D binary with raw USB support. Requires installing libusb development libraries for your operating system. ```bash # Build with raw USB support (requires libusb-1.0) sudo apt-get install libusb-1.0-0-dev # Debian/Ubuntu # brew install libusb # macOS cd cmd/app && go build -o ../../snd -tags="LIBUSB" && cd ../.. ``` -------------------------------- ### Start snd Application Source: https://github.com/bigjk/snd/wiki/Building Executes the compiled snd application. The web interface will be available at http://localhost:7123. ```bash ./snd ``` -------------------------------- ### Full Skeleton Data Example for Weapon Source: https://github.com/bigjk/snd/wiki/Templates A comprehensive example of skeleton data for a weapon, including properties like category, cost, damage, name, properties, and weight. This structure guides data entry and template design. ```json { "category": "Martial Melee Weapons", "cost": "10 gp", "damage_dice": "1d8", "damage_type": "slashing", "name": "Battleaxe", "properties": [ "versatile (1d10)" ], "weight": "4 lb." } ``` -------------------------------- ### Get Application Settings Source: https://context7.com/bigjk/snd/llms.txt Retrieves the current application settings. This operation requires an empty JSON array as the request body. ```bash # Get current settings curl -X POST http://127.0.0.1:7123/api/getSettings \ -H "Content-Type: application/json" -d '[]' ``` -------------------------------- ### CSV Data Import Example Source: https://github.com/bigjk/snd/wiki/Import-&-Export This CSV format is used for importing data into the system. Ensure your data adheres to this structure for successful import. ```csv Name,Author,Slug,Description Mundane Loot,BigJk,mundane-loot,Some mundane loot duh! Name,Worth,Weight,Whatever Gem Dust,1gp,10,A Stick,Nothing,10,B Cool Sword,30gp,2,C Bag of Dust,450gp,10,D 1kg of Salt,2sp,5,E Snail,100gp,2,F Beer,1sp,5,G Silver Dagger,10gp,1,H ``` -------------------------------- ### Docker Compose for Sales & Dungeons Source: https://github.com/bigjk/snd/blob/master/README.md A Docker Compose configuration to set up and run Sales & Dungeons. This example demonstrates port mapping, device binding for USB printers, group permissions, and volume mounting for persistent user data. ```yaml version: "3" services: snd: image: ghcr.io/bigjk/snd:master ports: - "7123:7123" devices: - "/dev/bus/usb" group_add: - uucp volumes: - "/some/place/to/persist:/app/userdata" ``` -------------------------------- ### List all templates using curl Source: https://context7.com/bigjk/snd/llms.txt Use the GET /api/extern/templates endpoint to retrieve a list of all available templates. This is useful for discovering available print formats. ```bash # List all templates curl http://127.0.0.1:7123/api/extern/templates # Expected output: # [ # { # "id": "tmpl:BigJk+magic-items", # "name": "Magic Items", # "author": "BigJk", # "slug": "magic-items", # "description": "Prints a formatted magic item card." # }, # { # "id": "tmpl:BigJk+spell-card", # "name": "Spell Card", # "author": "BigJk", # "slug": "spell-card", # "description": "A compact spell reference card." # } # ] ``` -------------------------------- ### Get Printer Endpoint Information Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Retrieves detailed information about a specific USB device, including its endpoint addresses, using the vendor and product IDs. ```bash lsusb -v -d 0416:5011 | grep bEndpointAddress ``` -------------------------------- ### Nunjucks Print Template Example Source: https://context7.com/bigjk/snd/llms.txt This HTML/CSS template uses Nunjucks for dynamic content rendering. It accesses entry data via 'it', images via 'images', and printer settings via 'settings'. Includes custom filters and extensions. ```html

{{ it.name }}

{{ it.rarity }} {% if it.attunement %} Requires Attunement {% endif %}
{{ it.description | markdown }}
{% js "modifier" %} (state) => Math.floor((state.it.bonus - 10) / 2) {% endjs %}

Modifier: +{{ modifier }}

{% data "rarityColors" %} { "Common": "#aaa", "Uncommon": "#1a9", "Rare": "#55f", "Very Rare": "#a0a", "Legendary": "#fa0" } {% enddata %} {{ it.rarity }} {% for attack in it.attacks %}
{{ attack.name }}: {{ attack.damage }}
{% endfor %} ``` -------------------------------- ### Skeleton Data: List Property (Simple) Source: https://github.com/bigjk/snd/wiki/Templates Example of an 'attacks' property defined as a simple list of strings in skeleton data. This allows for a list of basic text values. ```json { "attacks": [ "Bite", "Slash" ] } ``` -------------------------------- ### Skeleton Data: Image Property Source: https://github.com/bigjk/snd/wiki/Templates Example of an 'icon' property marked for image input using '!IMAGE'. This special notation indicates that an image should be used for this field. ```json { "icon": "!IMAGE" } ``` -------------------------------- ### Get All Entries for a Template Source: https://context7.com/bigjk/snd/llms.txt Retrieves all entries associated with a given template ID. The template ID is sent as a string within a JSON array. ```bash # Get all entries for a template curl -X POST http://127.0.0.1:7123/api/getEntries \ -H "Content-Type: application/json" \ -d '["tmpl:BigJk+magic-items"]' ``` -------------------------------- ### Python SDK for SndAPI Source: https://context7.com/bigjk/snd/llms.txt The Python SDK simplifies interaction with the internal RPC API. Initialize it with the base URL and call methods directly. Ensure the 'requests' library is installed. ```python # pip install requests import snd_sdk api = snd_sdk.SndAPI("http://127.0.0.1:7123") # --- Read current settings and update printer width --- settings = api.get_settings() settings["printerWidth"] = 576 api.save_settings(settings) # --- List templates and get a specific one --- templates = api.get_templates() print(f"Found {len(templates)} templates") template = api.get_template("tmpl:BigJk+magic-items") # --- Save an entry and trigger a print --- entry = { "name": "Potion of Healing", "rarity": "Common", "description": "Restores 2d4+2 hit points when consumed." } saved = api.save_entry("tmpl:BigJk+magic-items", entry) api.print(f"tmpl:BigJk+magic-items:{saved['id']}") # --- Use AI to generate an entry --- result = api.ai_prompt("openai", "gpt-4o-mini", "Generate a unique magic ring for D&D 5e as JSON with: name, rarity, description.") import json ring_data = json.loads(result) api.save_entry("tmpl:BigJk+magic-items", ring_data) # --- Sync local content to cloud --- api.sync_local_to_cloud() # --- Export a template as a ZIP --- api.exports_template_zip("tmpl:BigJk+magic-items", []) ``` -------------------------------- ### Get dmesg output for printer Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server This command shows kernel messages, which can help identify the printer's USB vendor and product IDs. ```bash dmesg ``` -------------------------------- ### Skeleton Data: Number Property Source: https://github.com/bigjk/snd/wiki/Templates Example of an 'hp' property defined as a number type in skeleton data. This will render as a number input field. ```json { "hp": 120 } ``` -------------------------------- ### Get Single Entry by ID Source: https://context7.com/bigjk/snd/llms.txt Fetches a specific entry using both the template ID and the entry ID. Both IDs are provided as strings within a JSON array. ```bash # Get a single entry curl -X POST http://127.0.0.1:7123/api/getEntry \ -H "Content-Type: application/json" \ -d '["tmpl:BigJk+magic-items", "entry-id-here"]' ``` -------------------------------- ### Skeleton Data: Text Property Source: https://github.com/bigjk/snd/wiki/Templates Example of a 'description' property defined as a text type in skeleton data. This will render as a standard text input field during entry creation or editing. ```json { "description": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam" } ``` -------------------------------- ### List all generators using curl Source: https://context7.com/bigjk/snd/llms.txt Use the GET /api/extern/generators endpoint to retrieve a list of all procedural content generators. This includes their configuration schemas, which detail user-adjustable parameters. ```bash # List all generators with their config schemas curl http://127.0.0.1:7123/api/extern/generators # Expected output: # [ # { # "id": "gen:BigJk+dungeon-generator", # "name": "Dungeon Generator", # "author": "BigJk", # "slug": "dungeon-generator", # "description": "Randomly generates a dungeon with descriptions.", # "config": [ # { # "key": "type", # "name": "Algorithm Type", # "type": "Options", # "default": { "choices": ["Uniform","Digger","Rogue"], "selected": "Uniform" } # }, # { "key": "doors", "name": "Add Doors", "type": "Checkbox", "default": true }, # { "key": "container", "name": "Add Loot Container", "type": "Checkbox", "default": true }, # { "key": "container_chance", "name": "Loot Container Chance", "type": "Number", "default": 10 } # ] # } # ] ``` -------------------------------- ### Skeleton Data: List Property (Complex) Source: https://github.com/bigjk/snd/wiki/Templates Example of an 'attacks' property defined as a list of objects in skeleton data. Each object can have 'name' and 'damage' properties, allowing for structured list items. ```json { "attacks": [ { "name": "Bite", "damage": 20 } ] } ``` -------------------------------- ### Create Go Working Directory Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Create the standard Go working directory structure, including bin, src, and pkg subdirectories. ```bash mkdir -p ~/go/{bin,src,pkg} ``` -------------------------------- ### Build S&D Headless Server from Source Source: https://context7.com/bigjk/snd/llms.txt Instructions to build the headless S&D server binary from source. This version does not include USB or Electron support. ```bash # Install dependencies git clone https://github.com/BigJk/snd && cd snd go mod tidy # Build headless server (no USB, no Electron) cd cmd/app && go build -o ../../snd && cd ../.. ``` -------------------------------- ### Manage Go Dependencies Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Downloads and tidies Go module dependencies for the project. ```bash go mod tidy go mod download ``` -------------------------------- ### Add Go Bin to PATH (Permanent) Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Make the Go binary directory permanently available in your PATH by adding it to the user's profile. ```bash echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile ``` -------------------------------- ### Fetch All Templates Source: https://context7.com/bigjk/snd/llms.txt Use this endpoint to retrieve metadata for all available templates. It requires an empty JSON array as the request body. ```bash # Get all templates curl -X POST http://127.0.0.1:7123/api/getTemplates -H "Content-Type: application/json" -d '[]' ``` -------------------------------- ### Compile and Run Sales'n'Dungeons Server Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Compiles and runs the Sales'n'Dungeons headless server using libusb. The first run may take longer due to compilation. ```bash cd ~/go/src/snd go run cmd/headless-libusb/main.go ``` -------------------------------- ### Download Frontend Archive Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Downloads the frontend archive using wget. Ensure you replace the URL with the latest version. ```bash wget -c http://snd.ftp.sh:2015/frontend-only/03.04.2020%20frontend%20%5Bf3d261ae%5D.zip ``` -------------------------------- ### List All Data Sources Source: https://context7.com/bigjk/snd/llms.txt Fetches a list of all available data sources. This operation requires an empty JSON array as the request body. ```bash # List all data sources curl -X POST http://127.0.0.1:7123/api/getSources \ -H "Content-Type: application/json" -d '[]' ``` -------------------------------- ### Run Sales & Dungeons via Docker Source: https://github.com/bigjk/snd/blob/master/README.md This command pulls the latest master image of Sales & Dungeons and runs it as a container. Ensure you map the correct USB device and persistent storage path. The `group_add` parameter may need adjustment based on your system's group permissions for USB devices. ```bash docker pull ghcr.io/bigjk/snd:master ``` ```bash docker run -p 7123:7123 --device=/dev/bus/usb --group-add uucp -v /some/place/to/persist:/app/userdata ghcr.io/bigjk/snd:master ``` -------------------------------- ### Download Go for Raspberry Pi Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Download the Go programming language archive for ARMv6 architecture. Ensure you select the correct version for your Raspberry Pi's architecture. ```bash wget -c https://dl.google.com/go/go1.14.linux-armv6l.tar.gz ``` -------------------------------- ### Get Entries Merged with Source Data Source: https://context7.com/bigjk/snd/llms.txt Retrieves entries for a template, merged with data from its linked sources. Requires the template ID as a string within a JSON array. ```bash # Get entries merged with source data for a template curl -X POST http://127.0.0.1:7123/api/getEntriesWithSources \ -H "Content-Type: application/json" \ -d '["tmpl:BigJk+magic-items"]' ``` -------------------------------- ### Add Go Bin to PATH (Temporary) Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Temporarily add the Go binary directory to your system's PATH for the current terminal session. ```bash export PATH=$PATH:/usr/local/go/bin ``` -------------------------------- ### Build snd Application Source: https://github.com/bigjk/snd/wiki/Building Compiles the snd application. The -o flag specifies the output file path. Replace %YOUR_BUILD_TAGS% with a space-separated list of optional features like ELECTRON or LIBUSB. ```go cd ./cmd/app go build -o ./../../snd -tags="%YOUR_BUILD_TAGS%" cd ../../ ``` -------------------------------- ### Render Template to Image (Screenshot API) Source: https://context7.com/bigjk/snd/llms.txt Use this endpoint to render a template to a PNG image as a base64 data URL. It requires the template ID and entry data in JSON format. ```bash # Render a template entry to a PNG (returns base64 data URL) curl -X POST http://127.0.0.1:7123/api/screenshot \ -H "Content-Type: application/json" \ -d '["tmpl:BigJk+magic-items", "{\"name\":\"Amulet of Health\",\"rarity\":\"Rare\",\"description\":\"Your Constitution score is 19 while you wear this amulet.\"}"]' # Output: base64 encoded PNG data URL # "data:image/png;base64,iVBORw0KGgo..." ``` -------------------------------- ### screenshot Source: https://context7.com/bigjk/snd/llms.txt Renders a template with given entry data to a PNG image and returns it as a base64-encoded data URL. Useful for previewing templates programmatically. ```APIDOC ## screenshot — Render a template to an image without printing ### Description Renders a template with given entry data to a PNG image and returns it as a base64-encoded data URL. Useful for previewing templates programmatically. Takes a template/entry print ID and the entry data JSON string. ### Method POST ### Endpoint /api/screenshot ### Request Body - **template_id** (string) - Required - The ID of the template to render. - **entry_data** (string) - Required - A JSON string representing the entry data. ### Request Example ```bash curl -X POST http://127.0.0.1:7123/api/screenshot \ -H "Content-Type: application/json" \ -d '["tmpl:BigJk+magic-items", "{\"name\":\"Amulet of Health\",\"rarity\":\"Rare\",\"description\":\"Your Constitution score is 19 while you wear this amulet.\"}"]' ``` ### Response #### Success Response (200) - **data_url** (string) - A base64 encoded PNG data URL. ### Response Example ``` "data:image/png;base64,iVBORw0KGgo..." ``` ``` -------------------------------- ### Rolling Dice with RPG Dice Roller Source: https://github.com/bigjk/snd/wiki/Generators The embedded RPG Dice Roller can be used to roll dice and get numeric outputs directly. Access it via the global variable 'rpgDiceRoller'. ```javascript dice.roll('1d6+2').total ``` -------------------------------- ### Download snd Dependencies Source: https://github.com/bigjk/snd/wiki/Building Fetches and downloads all the necessary dependencies for the snd project using Go modules. ```go go mod tidy ``` -------------------------------- ### Generate Content Using AI Source: https://context7.com/bigjk/snd/llms.txt Sends a prompt to a configured AI provider to generate or transform content. Requires the provider ID, model name, and prompt string, all within a JSON array. ```bash # Generate a magic item description using AI curl -X POST http://127.0.0.1:7123/api/aiPrompt \ -H "Content-Type: application/json" \ -d '["openai", "gpt-4o-mini", "Generate a unique rare magic sword with a name, description, and special ability for D&D 5e. Return as JSON with fields: name, rarity, description, special_ability."]' ``` -------------------------------- ### Extract Frontend Archive Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Extracts the downloaded frontend archive into the Sales'n'Dungeons source directory. ```bash tar -C ~/go/src/snd/ http://snd.ftp.sh:2015/frontend-only/03.04.2020%20frontend%20%5Bf3d261ae%5D.zip ``` -------------------------------- ### aiPrompt Source: https://context7.com/bigjk/snd/llms.txt Generates or transforms entry content using AI. Sends a prompt to the configured AI provider and returns generated content. ```APIDOC ## aiPrompt ### Description Generates or transforms entry content using AI. Sends a prompt to the configured AI provider (OpenAI, OpenRouter, or a custom OpenAI-compatible local endpoint) and returns generated content. ### Method POST ### Endpoint `/api/aiPrompt` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **aiPrompt**: `[providerId: string, model: string, prompt: string]` ### Request Example ```bash # Generate a magic item description using AI curl -X POST http://127.0.0.1:7123/api/aiPrompt \ -H "Content-Type: application/json" \ -d '["openai", "gpt-4o-mini", "Generate a unique rare magic sword with a name, description, and special ability for D&D 5e. Return as JSON with fields: name, rarity, description, special_ability."]' ``` ### Response #### Success Response (200) - **aiPrompt**: Generated content from the AI provider. The format depends on the prompt, but often JSON. #### Response Example ```json { "name": "Sword of the Arcane", "rarity": "Rare", "description": "A finely crafted longsword humming with latent magical energy.", "special_ability": "Once per day, you can cast the Mage Hand cantrip as a bonus action." } ``` ``` -------------------------------- ### List Templates Source: https://github.com/bigjk/snd/wiki/API-Routes Retrieves a list of all available templates stored within Sales & Dungeons. ```APIDOC ## (GET) /api/extern/templates ### Description Returns a list of all templates stored in S&D. ### Method GET ### Endpoint /api/extern/templates ### Response #### Success Response (200) - **id** (string) - Unique identifier for the template. - **name** (string) - The display name of the template. - **author** (string) - The author of the template. - **slug** (string) - A URL-friendly identifier for the template. - **description** (string) - A brief description of the template. ### Response Example ```json [ { "id":"tmpl:Author+slug", "name":"Cool Template", "author":"Author", "slug":"slug", "description":"..." } ] ``` ``` -------------------------------- ### Docker Compose for Headless S&D Source: https://context7.com/bigjk/snd/llms.txt A docker-compose.yml file to run S&D in headless mode. Mounts a volume for persistence and passes through the USB device for direct printer access. ```yaml # docker-compose.yml version: "3" services: snd: image: ghcr.io/bigjk/snd:master ports: - "7123:7123" devices: - "/dev/bus/usb" group_add: - uucp # group allowed to read the USB device volumes: - "/mnt/snd-data:/app/userdata" ``` -------------------------------- ### getSettings / saveSettings Source: https://context7.com/bigjk/snd/llms.txt Manages application settings. `getSettings` retrieves the current settings, and `saveSettings` persists updated settings. ```APIDOC ## getSettings / saveSettings ### Description Reads and updates application settings. `getSettings` returns the current settings object. `saveSettings` takes a settings object and persists it. ### Method POST ### Endpoint `/api/` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **getSettings**: `[]` (empty array for positional arguments) - **saveSettings**: `[settingsObject: object]` (object containing settings to save. Key fields include `printerWidth`, `explicitInit`, `forceStandardMode`, and `cutAfterPrint`) ### Request Example ```bash # Get current settings curl -X POST http://127.0.0.1:7123/api/getSettings \ -H "Content-Type: application/json" -d '[]' # Update printer width for an 80mm printer curl -X POST http://127.0.0.1:7123/api/saveSettings \ -H "Content-Type: application/json" \ -d '[{"printerWidth": 576, "explicitInit": false, "forceStandardMode": true, "cutAfterPrint": true}]' ``` ### Response #### Success Response (200) - **getSettings**: Current settings object. - **saveSettings**: Confirmation of save operation (details not specified). ``` -------------------------------- ### List all templates Source: https://context7.com/bigjk/snd/llms.txt Retrieves a JSON array of all templates stored in the S&D instance, including their IDs, name, author, slug, and description. ```APIDOC ## GET /api/extern/templates — List all templates ### Description Returns a JSON array of all templates stored in the running S&D instance, including their unique IDs (formed as `tmpl:Author+slug`), name, author, slug, and description. ### Method GET ### Endpoint /api/extern/templates ### Response #### Success Response (200) - **id** (string) - Unique template ID (e.g., `tmpl:Author+slug`) - **name** (string) - The name of the template - **author** (string) - The author of the template - **slug** (string) - The slug of the template - **description** (string) - A brief description of the template ### Request Example ```bash curl http://127.0.0.1:7123/api/extern/templates ``` ### Response Example ```json [ { "id": "tmpl:BigJk+magic-items", "name": "Magic Items", "author": "BigJk", "slug": "magic-items", "description": "Prints a formatted magic item card." }, { "id": "tmpl:BigJk+spell-card", "name": "Spell Card", "author": "BigJk", "slug": "spell-card", "description": "A compact spell reference card." } ] ``` ``` -------------------------------- ### Add User to LP Group Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Adds the 'pi' user to the 'lp' system group, granting necessary permissions to use the printer. ```bash sudo usermod -a -G lp pi ``` -------------------------------- ### Extract Go Archive on Raspberry Pi Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Extract the downloaded Go archive to the /usr/local directory. This command requires superuser privileges. ```bash sudo tar -C /usr/local -xvzf go1.14.linux-armv6l.tar.gz ``` -------------------------------- ### Print a template entry or run a generator Source: https://context7.com/bigjk/snd/llms.txt Triggers a print job on the configured printer using either a template with provided data or a generator with specified configuration. ```APIDOC ## POST /api/extern/print/:id — Print a template entry or run a generator ### Description Triggers a print job on the configured printer. For templates, the POST body is a JSON object matching the template's entry data schema. For generators, the POST body is a JSON object matching the generator's config schema. The `:id` path parameter is the full template ID (e.g., `tmpl:Author+slug`) or generator ID (e.g., `gen:Author+slug`). ### Method POST ### Endpoint /api/extern/print/:id ### Parameters #### Path Parameters - **id** (string) - Required - The full template ID (e.g., `tmpl:Author+slug`) or generator ID (e.g., `gen:Author+slug`). #### Request Body - **(JSON object)** - The data for the template entry or the configuration for the generator. ### Request Example (Template) ```bash curl -X POST http://127.0.0.1:7123/api/extern/print/tmpl:BigJk+magic-items \ -H "Content-Type: application/json" \ -d { "name": "Sword of Flame", "rarity": "Rare", "attunement": true, "description": "This blade crackles with fire. On a hit, it deals an extra 2d6 fire damage.", "weight": "3 lb.", "cost": "—" } ``` ### Request Example (Generator) ```bash curl -X POST http://127.0.0.1:7123/api/extern/print/gen:BigJk+dungeon-generator \ -H "Content-Type: application/json" \ -d { "seed": 42, "type": { "choices": ["Uniform","Digger","Rogue"], "selected": "Digger" }, "doors": true, "container": true, "container_chance": 25 } ``` ``` -------------------------------- ### Create or Update Data Source Source: https://context7.com/bigjk/snd/llms.txt Creates a new data source or updates an existing one. The source definition, including its ID, name, and entries, is provided as a JSON object within an array. ```bash # Create a new data source curl -X POST http://127.0.0.1:7123/api/saveSource \ -H "Content-Type: application/json" \ -d '[{"id": "ds:MyUser+loot-table", "name": "Loot Table", "author": "MyUser", "slug": "loot-table", "entries": [{"name": "Gold Coin", "worth": "1gp"}, {"name": "Silver Dagger", "worth": "10gp"}]}]' ``` -------------------------------- ### Clone Sales'n'Dungeons Source Code Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Clones the latest source code from the Sales'n'Dungeons GitHub repository into the specified Go source directory. ```bash cd ~/go/src git clone https://github.com/BigJk/SnD ``` -------------------------------- ### Programmatic CSV Import with Python SDK Source: https://context7.com/bigjk/snd/llms.txt Shows how to import CSV data programmatically using the S&D Python SDK. Ensure the API endpoint is correctly configured. ```python import snd_sdk, csv, io api = snd_sdk.SndAPI("http://127.0.0.1:7123") csv_rows = [ ["Name", "Author", "Slug", "Description"], ["Mundane Loot", "MyUser", "mundane-loot", "A table of mundane loot"], ["Name", "Worth", "Weight", "Notes"], ["Gem Dust", "1gp", "10", "For rituals"], ["Cool Sword", "30gp", "2", "Well-balanced"], ] api.imports_source_csv(csv_rows) ``` -------------------------------- ### Clone snd Repository Source: https://github.com/bigjk/snd/wiki/Building Clones the BigJk/snd repository into the current directory and navigates into the cloned repository. ```bash git clone https://github.com/BigJk/snd cd ./snd ``` -------------------------------- ### List USB Devices Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Lists all USB devices connected to the Raspberry Pi, used to identify the printer's hardware address. ```bash lsusb ``` -------------------------------- ### getTemplates / getTemplate Source: https://context7.com/bigjk/snd/llms.txt Fetches template metadata. `getTemplates` retrieves all templates, while `getTemplate` retrieves a specific template by its ID. ```APIDOC ## getTemplates / getTemplate ### Description Fetches template metadata. `getTemplates` returns all templates. `getTemplate` takes a template ID string and returns the full template object including its print template HTML, list template, skeleton data, and attached images. ### Method POST ### Endpoint `/api/` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **getTemplates**: `[]` (empty array for positional arguments) - **getTemplate**: `[templateId: string]` (array containing the template ID) ### Request Example ```bash # Get all templates curl -X POST http://127.0.0.1:7123/api/getTemplates -H "Content-Type: application/json" -d '[]' # Get a specific template by ID curl -X POST http://127.0.0.1:7123/api/getTemplate \ -H "Content-Type: application/json" \ -d '["tmpl:BigJk+magic-items"]' ``` ### Response #### Success Response (200) - **getTemplates**: Array of template objects. - **getTemplate**: Template object containing `id`, `name`, `author`, `slug`, `skeletonData`, `printTemplate`, `listTemplate`, and `images`. #### Response Example ```json { "id": "tmpl:BigJk+magic-items", "name": "Magic Items", "author": "BigJk", "slug": "magic-items", "skeletonData": "{\"name\":\"Sword\",\"rarity\":\"Rare\"}", "printTemplate": "
{{ it.name }}
", "listTemplate": "{{ it.name }}", "images": {} } ``` ``` -------------------------------- ### getSources / saveSource / getEntriesWithSources Source: https://context7.com/bigjk/snd/llms.txt Manages data sources. `getSources` lists all sources, `saveSource` creates or updates a source, and `getEntriesWithSources` fetches template entries merged with source data. ```APIDOC ## getSources / saveSource / getEntriesWithSources ### Description Manages data sources, which are named collections of structured entries. `getSources` lists all sources. `saveSource` creates or updates a source. `getEntriesWithSources` fetches all entries for a template merged with data from its linked sources. ### Method POST ### Endpoint `/api/` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **getSources**: `[]` (empty array for positional arguments) - **saveSource**: `[sourceObject: object]` (object representing the data source to save. Includes `id`, `name`, `author`, `slug`, and `entries`) - **getEntriesWithSources**: `[templateId: string]` ### Request Example ```bash # List all data sources curl -X POST http://127.0.0.1:7123/api/getSources \ -H "Content-Type: application/json" -d '[]' # Create a new data source curl -X POST http://127.0.0.1:7123/api/saveSource \ -H "Content-Type: application/json" \ -d '[{"id": "ds:MyUser+loot-table", "name": "Loot Table", "author": "MyUser", "slug": "loot-table", "entries": [{"name": "Gold Coin", "worth": "1gp"}, {"name": "Silver Dagger", "worth": "10gp"}]}]' # Get entries merged with source data for a template curl -X POST http://127.0.0.1:7123/api/getEntriesWithSources \ -H "Content-Type: application/json" \ -d '["tmpl:BigJk+magic-items"]' ``` ### Response #### Success Response (200) - **getSources**: Array of data source objects. - **saveSource**: Confirmation of save operation (details not specified). - **getEntriesWithSources**: Array of entry objects merged with source data. ``` -------------------------------- ### Running Headless S&D Docker Container Source: https://context7.com/bigjk/snd/llms.txt Commands to pull and run the S&D Docker image directly. Adjust device paths and group as necessary for your system. ```bash # Pull and run directly (replace /dev/bus/usb and group as needed) docker pull ghcr.io/bigjk/snd:master docker run -p 7123:7123 \ --device=/dev/bus/usb \ --group-add "$(stat -c '%g' /dev/bus/usb)" \ -v /mnt/snd-data:/app/userdata \ ghcr.io/bigjk/snd:master # Access the web UI open http://127.0.0.1:7123 ``` -------------------------------- ### Update Application Settings Source: https://context7.com/bigjk/snd/llms.txt Persists updated application settings. The new settings object is passed as a JSON array containing a single object. ```bash # Update printer width for an 80mm printer curl -X POST http://127.0.0.1:7123/api/saveSettings \ -H "Content-Type: application/json" \ -d '[{"printerWidth": 576, "explicitInit": false, "forceStandardMode": true, "cutAfterPrint": true}]' ``` -------------------------------- ### List all generators Source: https://context7.com/bigjk/snd/llms.txt Retrieves a JSON array of all procedural content generators, including their IDs, name, author, slug, description, and configuration schema. ```APIDOC ## GET /api/extern/generators — List all generators ### Description Returns a JSON array of all procedural content generators, including their IDs, name, author, slug, description, and full config schema showing user-adjustable parameters and their types/defaults. ### Method GET ### Endpoint /api/extern/generators ### Response #### Success Response (200) - **id** (string) - Unique generator ID (e.g., `gen:Author+slug`) - **name** (string) - The name of the generator - **author** (string) - The author of the generator - **slug** (string) - The slug of the generator - **description** (string) - A brief description of the generator - **config** (array) - An array of configuration objects for the generator - **key** (string) - The key for the configuration parameter - **name** (string) - The display name for the parameter - **type** (string) - The type of the parameter (e.g., Options, Checkbox, Number) - **default** (object) - The default value and options for the parameter ### Request Example ```bash curl http://127.0.0.1:7123/api/extern/generators ``` ### Response Example ```json [ { "id": "gen:BigJk+dungeon-generator", "name": "Dungeon Generator", "author": "BigJk", "slug": "dungeon-generator", "description": "Randomly generates a dungeon with descriptions.", "config": [ { "key": "type", "name": "Algorithm Type", "type": "Options", "default": { "choices": ["Uniform","Digger","Rogue"], "selected": "Uniform" } }, { "key": "doors", "name": "Add Doors", "type": "Checkbox", "default": true }, { "key": "container", "name": "Add Loot Container", "type": "Checkbox", "default": true }, { "key": "container_chance", "name": "Loot Container Chance", "type": "Number", "default": 10 } ] } ] ``` ``` -------------------------------- ### Allow Unverified Mac App Source: https://github.com/bigjk/snd/blob/master/README.md If your Mac reports the Sales & Dungeons app as from an unverified developer, use this command in the terminal to allow it to run. Refer to Apple's documentation for more details on managing developer settings. ```bash xattr -d com.apple.quarantine "/Applications/Sales & Dungeons.app/" ``` -------------------------------- ### Using Image Property in Template Source: https://github.com/bigjk/snd/wiki/Templates Shows how to display an image property within an HTML template. The 'it' variable refers to the current entry's data. ```html ``` -------------------------------- ### SndAPI Source: https://context7.com/bigjk/snd/llms.txt Python SDK for the internal RPC API. Wraps all internal RPC endpoints. ```APIDOC ## SndAPI — Python SDK for the internal RPC API ### Description The auto-generated Python SDK wraps all internal RPC endpoints. Initialize with the base URL and call methods directly. Requires the `requests` library. ### Initialization ```python import snd_sdk api = snd_sdk.SndAPI("http://127.0.0.1:7123") ``` ### Methods #### `get_settings()` Retrieves current system settings. #### `save_settings(settings)` Saves the provided system settings. #### `get_templates()` Lists all available templates. #### `get_template(template_id)` Retrieves a specific template by its ID. #### `save_entry(template_id, entry_data)` Saves a new entry for a given template. #### `print(print_id)` Triggers a print job for a specific entry. #### `ai_prompt(provider, model, prompt)` Uses AI to generate content based on the provided prompt. #### `sync_local_to_cloud()` Synchronizes local content to the cloud. #### `exports_template_zip(template_id, files_to_exclude)` Exports a template as a ZIP archive. ``` -------------------------------- ### Save New Entry to Template Source: https://context7.com/bigjk/snd/llms.txt Saves a new entry to a specified template. Requires the template ID and the entry object, both included in a JSON array. ```bash # Save a new entry to a template curl -X POST http://127.0.0.1:7123/api/saveEntry \ -H "Content-Type: application/json" \ -d '["tmpl:BigJk+magic-items", {"name": "Ring of Protection", "rarity": "Uncommon", "attunement": true, "description": "+1 bonus to AC and saving throws."} ]' ``` -------------------------------- ### List Generators Source: https://github.com/bigjk/snd/wiki/API-Routes Retrieves a list of all available generators within Sales & Dungeons. ```APIDOC ## (GET) /api/extern/generators ### Description Returns a list of all generators stored in S&D. ### Method GET ### Endpoint /api/extern/generators ### Response #### Success Response (200) - **id** (string) - Unique identifier for the generator. - **name** (string) - The display name of the generator. - **author** (string) - The author of the generator. - **slug** (string) - A URL-friendly identifier for the generator. - **description** (string) - A detailed description of the generator. - **config** (array) - Configuration options for the generator. - **key** (string) - The internal key for the configuration option. - **name** (string) - The display name of the configuration option. - **description** (string) - A description of the configuration option. - **type** (string) - The type of the configuration option (e.g., Options, Checkbox, Number). - **default** (object) - The default value for the configuration option. - **choices** (array) - List of available choices for 'Options' type. - **selected** (string) - The default selected choice for 'Options' type. ### Response Example ```json [ { "id":"gen:BigJk+dungeon-generator", "name":"Dungeon Generator", "author":"BigJk", "slug":"dungeon-generator", "description":"This randomly generates a dungeon with some basic description. How you use the door and loot descriptions is up to you. The descriptions are based on the \"AX1: Old School Adventure Accessories - D30 DM Companion\" by Richard J. LeBlanc, Jr.", "config":[ { "key":"type", "name":"Algorithm Type", "description":"Which algorithm to use for generation.", "type":"Options", "default":{ "choices":[ "Uniform", "Digger", "Rogue" ], "selected":"Uniform" } }, { "key":"doors", "name":"Add Doors", "description":"Add description of doors and if they are locked.", "type":"Checkbox", "default":true }, { "key":"container", "name":"Add Loot Container", "description":"Adds some loot containers.", "type":"Checkbox", "default":true }, { "key":"container_chance", "name":"Loot Container Chance", "description":"Percentage (0 - 100%) chance of a loot container present in a room.", "type":"Number", "default":10 } ] } ] ``` ``` -------------------------------- ### Print Raw ESC/POS Commands Source: https://github.com/bigjk/snd/wiki/API-Routes Sends raw ESC/POS commands as bytes to the configured printer. This is useful for direct printing control from external applications. ```APIDOC ## (POST) /api/extern/print_raw ### Description Sends raw ESC/POS commands as bytes to the configured printer. This is used by the `Remote S&D Printing` to send prints to different S&D instances. ### Method POST ### Endpoint /api/extern/print_raw ### Parameters #### Request Body - **(bytes)** Raw ESC/POS command data to be sent to the printer. ``` -------------------------------- ### Restart Sales'n'Dungeons Server Source: https://github.com/bigjk/snd/wiki/Raspberry-Pi-as-SnD-Server Restarts the Sales'n'Dungeons server after user group modifications. ```bash go run cmd/headless-libusb/main.go ```