Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

Keep the Substack publication parser private to the payload builder

Claude84061a7e32b7
diff --git a/server/services/musicVideo/publish/payloads.js b/server/services/musicVideo/publish/payloads.js
index f43a84ee8f..b4c85a7d6d 100644
--- a/server/services/musicVideo/publish/payloads.js
+++ b/server/services/musicVideo/publish/payloads.js
@@ -85,7 +85,7 @@ const instagramSafe = (caption) => caption.replace(/@(\w)/g, '$1');
* The publication's host from what the director typed: a bare name means
* name.substack.com; a custom domain or a pasted URL keeps only its host.
*/
-export function substackPublication(value) {
+function substackPublication(value) {
const host = text(value).toLowerCase().replace(/^https?:\/\//, '').replace(/^@/, '').split(/[/?#]/)[0];
if (/^[a-z0-9-]{1,63}$/.test(host)) return `${host}.substack.com`;
return /^(?:[a-z0-9-]{1,63}\.)+[a-z]{2,}$/.test(host) ? host : null;
diff --git a/server/services/musicVideo/publish/payloads.test.js b/server/services/musicVideo/publish/payloads.test.js
index 52873c7732..e6d8aa8b2c 100644
--- a/server/services/musicVideo/publish/payloads.test.js
+++ b/server/services/musicVideo/publish/payloads.test.js
@@ -3,7 +3,7 @@
* director's per-platform options, or a 422 naming the missing piece.
*/
import { describe, expect, it } from 'vitest';
-import { buildPublishPayload, substackPublication } from './payloads.js';
+import { buildPublishPayload } from './payloads.js';
import { captureMusicVideoEvidence } from '../../../lib/musicVideoDependencies.js';
const kit = (over = {}) => ({
@@ -103,11 +103,11 @@ describe('buildPublishPayload (#9282)', () => {
});
it('reads the Substack publication from a name, a pasted URL or a custom domain', () => {
- expect(substackPublication('example')).toBe('example.substack.com');
- expect(substackPublication('https://Example.substack.com/p/old-post')).toBe('example.substack.com');
- expect(substackPublication('news.example.com')).toBe('news.example.com');
- expect(substackPublication('not a host')).toBeNull();
const copy = { substack: { title: 'Song', subtitle: '', body: 'Body' } };
+ const host = (publication) => buildPublishPayload('substack', project({ copy }), { publication }).publication;
+ expect(host('https://Example.substack.com/p/old-post')).toBe('example.substack.com');
+ expect(host('news.example.com')).toBe('news.example.com');
+ expect(() => host('not a host')).toThrow(/Substack publication/);
expect(buildPublishPayload('substack', project({ copy }), { publication: 'example' }))
.toEqual({ publication: 'example.substack.com', videoUrl: 'https://youtu.be/abc', title: 'Song', subtitle: '', body: 'Body' });
expect(() => buildPublishPayload('substack', project({ copy, links: {} }), { publication: 'example' })).toThrow(/publish to YouTube first/);