sc-postiz-poster/lib/constants.js
2026-10-19 01:20:42 -05:00

76 lines
2.8 KiB
JavaScript

// Compile-time constants for the postiz-poster plugin.
const PLUGIN_NAME = "postiz-poster";
// The plugin's one trigger action.
const ACTION_NAME = "post_to_postiz";
// Postiz public REST API (docs.postiz.com/public-api). The surface is identical
// for self-hosted and cloud; only the base URL (plugin config) differs: cloud is
// https://api.postiz.com, self-hosted is the backend URL (NEXT_PUBLIC_BACKEND_URL,
// normally <site>/api). Endpoint paths below are appended to <baseUrl><PATH_BASE>.
const PATH_BASE = "/public/v1";
const ENDPOINTS = {
INTEGRATIONS: "/integrations", // GET -> [{ id, name, identifier, disabled, ... }]
UPLOAD_FROM_URL: "/upload-from-url", // POST { url } -> { id, path, ... }
POSTS: "/posts" // POST -> create / schedule a post
};
// Postiz post "type": publish now, schedule for a date, or save as a draft.
const POST_TYPES = {
NOW: "now",
SCHEDULE: "schedule",
DRAFT: "draft"
};
// Header carrying the Postiz public API key -- the bare key, no Bearer prefix
// (docs.postiz.com/public-api).
const AUTH_HEADER = "Authorization";
// Per-request timeout for posting (run) and the shorter one for listing channels
// while an admin opens a config page (Saltcorn builds action config forms on
// every view-builder load).
const REQUEST_TIMEOUT_MS = 15000;
const CONFIG_LIST_TIMEOUT_MS = 3000;
// How long a config-page channel listing (or its failure) is reused.
const CHANNEL_CACHE_TTL_MS = 60000;
// Largest Postiz response body read, and how much of one an error message quotes.
const MAX_RESPONSE_BYTES = 1024 * 1024;
const ERROR_SNIPPET_CHARS = 300;
// Provider settings Postiz requires beyond settings.__type, with the plugin's
// defaults.
const PROVIDER_DEFAULT_SETTINGS = {
"x": { who_can_reply_post: "everyone" },
"instagram": { post_type: "post" },
"instagram-standalone": { post_type: "post" }
};
// Providers whose posts need per-post choices this plugin does not collect
// (youtube title/type, tiktok, reddit subreddit, pinterest board): Postiz rejects
// them with a 400. The MCP tools flag such channels and warn in previews.
const UNSUPPORTED_PROVIDERS = ["youtube", "tiktok", "reddit", "pinterest"];
// The media reference a dry run puts in a payload in place of an upload: Postiz
// assigns the real { id, path } when it fetches the media.
const MEDIA_PLACEHOLDER = { id: "assigned-by-postiz-on-upload", path: "assigned-by-postiz-on-upload" };
module.exports = {
PLUGIN_NAME,
ACTION_NAME,
PATH_BASE,
ENDPOINTS,
POST_TYPES,
AUTH_HEADER,
REQUEST_TIMEOUT_MS,
CONFIG_LIST_TIMEOUT_MS,
CHANNEL_CACHE_TTL_MS,
MAX_RESPONSE_BYTES,
ERROR_SNIPPET_CHARS,
PROVIDER_DEFAULT_SETTINGS,
UNSUPPORTED_PROVIDERS,
MEDIA_PLACEHOLDER
};