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

Accept Suno share links on the Suno publish posts

Claude571031d03f0c
diff --git a/client/src/components/musicVideo/PublishKitPanel.jsx b/client/src/components/musicVideo/PublishKitPanel.jsx
index 7380e5aaed..f2c23b04ee 100644
--- a/client/src/components/musicVideo/PublishKitPanel.jsx
+++ b/client/src/components/musicVideo/PublishKitPanel.jsx
@@ -1,4 +1,4 @@
-import { useRef, useState } from 'react';
+import { useEffect, useRef, useState } from 'react';
import { Package, Download, Copy, Sparkles, Image as ImageIcon, Captions, ListOrdered } from 'lucide-react';
import useProviderModels from '../../hooks/useProviderModels.js';
import ProviderModelSelector from '../ProviderModelSelector.jsx';
@@ -85,6 +85,9 @@ export default function PublishKitPanel({ project, publishKit, enabledTargets })
const [notes, setNotes] = useState(kit.notes || '');
const [youtubeUrl, setYoutubeUrl] = useState(kit.links?.youtube || '');
const [songUrl, setSongUrl] = useState(kit.links?.song || '');
+ // The server saves a Suno share link as the song page it opens; show what was saved.
+ const savedSongUrl = kit.links?.song || '';
+ useEffect(() => { setSongUrl(savedSongUrl); }, [savedSongUrl]);
const [include, setInclude] = useState({ ...DEFAULT_INCLUDE, ...(kit.draftOptions?.include || {}) });
const [length, setLength] = useState(kit.draftOptions?.length === 'full' ? 'full' : 'short');
// Same filter as the server's timedLines: only cues with text and a start time reach the writer.
diff --git a/client/src/components/musicVideo/PublishPostingPanel.jsx b/client/src/components/musicVideo/PublishPostingPanel.jsx
index 1d094c21c2..964ea3e540 100644
--- a/client/src/components/musicVideo/PublishPostingPanel.jsx
+++ b/client/src/components/musicVideo/PublishPostingPanel.jsx
@@ -1,4 +1,4 @@
-import { useState } from 'react';
+import { useEffect, useState } from 'react';
import ConfirmButtonPair from '../ui/ConfirmButtonPair.jsx';
import { safeReadJsonStorage, safeWriteJsonStorage } from '../../lib/safeStorage.js';
import { ExternalLink, X as XIcon, LogIn, Link as LinkIcon, Check, ChevronDown, ChevronRight, Undo2 } from 'lucide-react';
@@ -291,6 +291,12 @@ function TargetRow({ project, kit, entry, publishing }) {
const [confirmDiscard, setConfirmDiscard] = useState(false);
const [confirmAgain, setConfirmAgain] = useState(false);
const draft = publishing.drafts[target];
+ // A Suno share link the draft followed: show the song page it opened instead.
+ const draftSongUrl = draft?.songUrl;
+ useEffect(() => {
+ if (!draftSongUrl) return;
+ setOptions((prev) => (prev.songUrl && prev.songUrl !== draftSongUrl ? { ...prev, songUrl: draftSongUrl } : prev));
+ }, [draftSongUrl]);
// A done platform folds to its header so the ones still to do are easy to reach.
const [open, setOpen] = useState(() => !kit.posts?.[target]);
const busy = publishing.busy[target];
diff --git a/client/src/components/musicVideo/PublishPostingPanel.test.jsx b/client/src/components/musicVideo/PublishPostingPanel.test.jsx
index 052db1cd42..676edafc1e 100644
--- a/client/src/components/musicVideo/PublishPostingPanel.test.jsx
+++ b/client/src/components/musicVideo/PublishPostingPanel.test.jsx
@@ -30,6 +30,16 @@ describe('PublishPostingPanel (#9282)', () => {
expect(within(row('YouTube')).getByRole('link')).toHaveAttribute('href', 'https://youtu.be/abc');
});
+ it('shows the Suno song page a pasted share link resolved to once the draft is filled', () => {
+ const song = 'https://suno.com/song/0a1b2c3d-1111-4222-8333-444455556666';
+ const { rerender } = render(<PublishPostingPanel project={project()} publishing={hook()} />);
+ expandAll();
+ const field = () => within(row('Suno')).getByLabelText('Song URL (the take to publish)');
+ fireEvent.change(field(), { target: { value: 'https://suno.com/s/AbCdEf123' } });
+ rerender(<PublishPostingPanel project={project()} publishing={hook({ drafts: { suno: { draftId: 'd1', summary: {}, songUrl: song } } })} />);
+ expect(field()).toHaveValue(song);
+ });
+
it('fills a Reddit draft with the subreddit and post type, dropping blanks', () => {
const publishing = hook();
render(<PublishPostingPanel project={project()} publishing={publishing} />);
diff --git a/server/services/musicVideo/publish/index.js b/server/services/musicVideo/publish/index.js
index f78cd3a2cf..952c0a2e0e 100644
--- a/server/services/musicVideo/publish/index.js
+++ b/server/services/musicVideo/publish/index.js
@@ -12,7 +12,8 @@ import { ServerError } from '../../../lib/errorHandler.js';
import { PATHS, ensureDir } from '../../../lib/fileUtils.js';
import { safeUnder } from '../../../lib/ffmpeg.js';
import { getProject, mutateProjectRecord } from '../projects.js';
-import { buildPublishPayload } from './payloads.js';
+import { buildPublishPayload, publishSongUrl } from './payloads.js';
+import { canonicalizeSunoUrl, isSunoShareLink } from '../../sunoShareLink.js';
import { connectPortosBrowser, serializeBrowserOperation as serialize } from './browser.js';
import { assertAccount, assertPlatformEnabled, getPublishPlatforms, normalizePost } from './platforms.js';
import { youtubeAdapter, shortsAdapter } from './youtube.js';
@@ -39,6 +40,8 @@ const drafts = new Map();
const draftPresentation = (draft) => ({
draftId: draft.id, projectId: draft.projectId, target: draft.target, summary: draft.summary,
screenshot: draft.screenshot, state: draft.state, createdAt: draft.createdAt, manualPublication: true,
+ // The song page a Suno share link resolved to, so the form can show it.
+ songUrl: draft.payload?.songUrl ?? null,
});
const emitDraft = (draft, state = draft.state) => musicVideoEvents.emit('publish-draft', {
projectId: draft.projectId, draftId: draft.id, target: draft.target, state,
@@ -134,6 +137,19 @@ function withPlatformDefaults(target, options, platforms) {
return { ...options, [key]: platforms?.[target]?.account || '' };
}
+// The Suno targets find the song by the id in its page URL; a share link
+// (suno.com/s/…, what Suno's Share button copies) carries none until followed.
+const SUNO_SONG_TARGETS = new Set(['suno', 'sunoHook']);
+async function withSongPage(target, project, options, deps) {
+ if (!SUNO_SONG_TARGETS.has(target)) return options;
+ const url = publishSongUrl(project, options);
+ if (!isSunoShareLink(url)) return options;
+ const songUrl = await canonicalizeSunoUrl(url, deps).catch(() => {
+ throw new ServerError('That Suno share link did not open a song page. Open it in a browser and paste the suno.com/song/… address it lands on', { status: 422, code: 'PUBLISH_ASSET_MISSING' });
+ });
+ return { ...options, songUrl };
+}
+
/** The release audio a distributor uploads: the project's own source song. */
async function withAudio(target, payload, project, deps) {
if (target !== 'distrokid') return payload;
@@ -166,7 +182,8 @@ export async function preparePublishDraft(projectId, target, options = {}, deps
const urls = existing.url ? [existing.url] : [];
throw new ServerError(`Already posted to ${adapter.label}. Confirm "Post again" to fill another draft`, { status: 409, code: 'PUBLISH_ALREADY_POSTED', context: { target, urls } });
}
- let payload = resolveFiles(buildPublishPayload(target, project, withPlatformDefaults(target, options, platforms)));
+ const resolved = await withSongPage(target, project, withPlatformDefaults(target, options, platforms), deps);
+ let payload = resolveFiles(buildPublishPayload(target, project, resolved));
payload = await withAudio(target, payload, project, deps);
payload = await withCovers(target, payload, deps);
for (const draft of [...drafts.values()]) if (draft.projectId === projectId && draft.target === target) await closeDraft(draft, deps);
@@ -213,7 +230,9 @@ export async function listPublishDrafts(projectId, deps = {}) {
}
/** Record or update one platform's post by hand: its link, reception (good/mixed/poor) and notes. */
-export async function recordPublishPost(projectId, target, input = {}) {
+export async function recordPublishPost(projectId, target, input = {}, deps = {}) {
+ // The Suno post's link is the song the Hook plays: keep its song page, not a share link.
+ if (target === 'suno' && isSunoShareLink(input.url)) input = { ...input, url: await canonicalizeSunoUrl(input.url, deps).catch(() => input.url) };
const { project } = await mutateProjectRecord(projectId, (current) => {
const kit = current.publishKit && typeof current.publishKit === 'object' ? current.publishKit : {};
const posts = { ...(kit.posts || {}) };
diff --git a/server/services/musicVideo/publish/index.test.js b/server/services/musicVideo/publish/index.test.js
index 6fc5bb4d0a..85177ff42f 100644
--- a/server/services/musicVideo/publish/index.test.js
+++ b/server/services/musicVideo/publish/index.test.js
@@ -78,6 +78,26 @@ describe('publish drafts (#9282)', () => {
.rejects.toMatchObject({ status: 422, message: expect.stringMatching(/publication/) });
});
+ it('follows a Suno share link to its song page for the Suno post, and records the song page', async () => {
+ const songId = '0a1b2c3d-1111-4222-8333-444455556666';
+ const { id } = await projects.createProject({ name: 'Release' });
+ const { connect } = fakeBrowser();
+ const suno = adapter({ label: 'Suno' });
+ const resolveUrl = vi.fn(async () => `https://suno.com/song/${songId}?sh=abc`);
+ const deps = { connect, adapters: { suno }, platforms: { suno: { enabled: true, account: null } }, resolveUrl };
+ const draft = await preparePublishDraft(id, 'suno', { songUrl: 'https://suno.com/s/AbCdEf123' }, deps);
+ expect(resolveUrl).toHaveBeenCalledWith('https://suno.com/s/AbCdEf123', expect.objectContaining({ allowUrl: expect.any(Function) }));
+ expect(suno.prepare).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ songUrl: `https://suno.com/song/${songId}` }));
+ expect(draft.songUrl).toBe(`https://suno.com/song/${songId}`);
+
+ const dead = { ...deps, resolveUrl: vi.fn(async () => null) };
+ await expect(preparePublishDraft(id, 'suno', { songUrl: 'https://suno.com/s/Gone1234' }, dead))
+ .rejects.toMatchObject({ status: 422, message: expect.stringMatching(/suno\.com\/song/) });
+
+ const { post } = await recordPublishPost(id, 'suno', { url: 'https://suno.com/s/AbCdEf123' }, { resolveUrl });
+ expect(post.url).toBe(`https://suno.com/song/${songId}`);
+ });
+
it('fills a reviewable draft but never submits it; records a manually published link', async () => {
const id = await readyProject();
const { connect, pages } = fakeBrowser();
diff --git a/server/services/musicVideo/publish/payloads.js b/server/services/musicVideo/publish/payloads.js
index f913e3449a..80939e9688 100644
--- a/server/services/musicVideo/publish/payloads.js
+++ b/server/services/musicVideo/publish/payloads.js
@@ -62,7 +62,12 @@ function pickVerticalCut(project, options) {
/** The full video's public link: the recorded YouTube post, else the one the director gave the kit. */
const fullVideoUrl = (kit) => text(kit.posts?.youtube?.url) || text(kit.links?.youtube) || '';
-const songUrl = (kit, options) => text(options?.songUrl) || text(kit.posts?.suno?.url) || text(kit.links?.song) || '';
+/** The Suno song a post links or plays: the director's pick, else the recorded Suno post, else the kit's song link. */
+export const publishSongUrl = (project, options) => {
+ const kit = kitOf(project);
+ return text(options?.songUrl) || text(kit.posts?.suno?.url) || text(kit.links?.song) || '';
+};
+const songUrl = (kit, options) => publishSongUrl({ publishKit: kit }, options);
function requireTitle(platform, title) {
if (!title) throw missing(`Write the ${platform} title in the release copy first`);
@@ -197,7 +202,7 @@ const BUILDERS = {
suno: (project, kit, options = {}) => {
const song = songUrl(kit, options);
// The adapter finds the song's own menu by its id, so the URL must carry it.
- if (!/^https:\/\/(www\.)?suno\.com\/song\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i.test(song)) throw missing('Give the Suno song URL to publish (suno.com/song/…)');
+ if (!/^https:\/\/(www\.)?suno\.com\/song\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i.test(song)) throw missing('Give the Suno song URL to publish (suno.com/song/… or a suno.com/s/… share link)');
const video = fullVideoUrl(kit);
const lead = text(kit.copy?.youtube?.description).split(/\n\s*\n/)[0] || '';
const caption = [lead, video ? `Music video: ${video}` : ''].filter(Boolean).join(' ').slice(0, 500);
@@ -207,7 +212,7 @@ const BUILDERS = {
sunoHook: (project, kit, options = {}) => {
const song = songUrl(kit, options);
const songId = song.match(SUNO_SONG_URL)?.[1]?.toLowerCase();
- if (!songId) throw missing('Give the Suno song URL the Hook plays (suno.com/song/…)');
+ if (!songId) throw missing('Give the Suno song URL the Hook plays (suno.com/song/… or a suno.com/s/… share link)');
const cut = pickVerticalCut(project, options);
const caption = text(kit.copy?.tiktok?.caption) || text(kit.copy?.shorts?.description).slice(0, 300);
const duration = Number(project?.audioAnalysis?.durationSec);
diff --git a/server/services/musicVideo/publishKit.js b/server/services/musicVideo/publishKit.js
index cbf7646791..71fbe1474f 100644
--- a/server/services/musicVideo/publishKit.js
+++ b/server/services/musicVideo/publishKit.js
@@ -26,6 +26,7 @@ import { suggestSocialCuts } from './socialCuts.js';
import { musicVideoAspect } from '../../lib/musicVideoAspect.js';
import { musicVideoDependencyChanges } from '../../lib/musicVideoDependencies.js';
import { buildChapters, buildSrt, buildPublishCopyPrompt, parsePublishCopy, normalizeCopyOptions, PUBLISH_PLATFORMS } from './publishKitText.js';
+import { canonicalizeSunoUrl, isSunoShareLink } from '../sunoShareLink.js';
const jobs = new Map();
const projectBuilds = new Map();
@@ -260,8 +261,13 @@ export async function selectPublishKitThumbnail(projectId, filename) {
}
/** Merge edited copy fields per platform (only known platforms and string/array fields). */
-export async function updatePublishKitCopy(projectId, patch) {
+export async function updatePublishKitCopy(projectId, patch, deps = {}) {
await requireProject(projectId);
+ // Keep the song page, not a Suno share link: the Suno posts find the song by the id in its URL.
+ // A link that can't be followed now is kept as typed; publishing follows it again.
+ if (isSunoShareLink(patch?.links?.song)) {
+ patch = { ...patch, links: { ...patch.links, song: await canonicalizeSunoUrl(patch.links.song, deps).catch(() => patch.links.song) } };
+ }
return mutateProjectRecord(projectId, (current) => {
const kit = projectPublishKit(current);
const copy = { ...(kit.copy || {}) };
diff --git a/server/services/musicVideo/publishKit.test.js b/server/services/musicVideo/publishKit.test.js
index f921ee98ec..2d838728b8 100644
--- a/server/services/musicVideo/publishKit.test.js
+++ b/server/services/musicVideo/publishKit.test.js
@@ -349,6 +349,16 @@ describe('publishing kit copy (#9281)', () => {
expect(project.publishKit).not.toHaveProperty('copyEditedAt');
});
+ it('saves a Suno share link as the song page it opens, and keeps it as typed when it cannot be followed', async () => {
+ const { id } = await projects.createProject({ name: 'Example Song' });
+ const songId = '0a1b2c3d-1111-4222-8333-444455556666';
+ const resolveUrl = async () => `https://suno.com/song/${songId}`;
+ let { project } = await kit.updatePublishKitCopy(id, { links: { song: 'https://suno.com/s/AbCdEf123' } }, { resolveUrl });
+ expect(project.publishKit.links.song).toBe(`https://suno.com/song/${songId}`);
+ ({ project } = await kit.updatePublishKitCopy(id, { links: { song: 'https://suno.com/s/Gone1234' } }, { resolveUrl: async () => null }));
+ expect(project.publishKit.links.song).toBe('https://suno.com/s/Gone1234');
+ });
+
it('clears tags an earlier draft wrote once hashtags are unticked', async () => {
const { id } = await projects.createProject({ name: 'Example Song' });
const reply = JSON.stringify({ youtube: { title: 'Drafted', description: 'd', tags: ['model tag'] } });
diff --git a/server/services/sunoShareLink.js b/server/services/sunoShareLink.js
new file mode 100644
index 0000000000..956f1762aa
--- /dev/null
+++ b/server/services/sunoShareLink.js
@@ -0,0 +1,38 @@
+/**
+ * Suno share links (`suno.com/s/<code>`, what Suno's Share button copies)
+ * resolved to the song they point at. The share link is a redirect to the
+ * song page; it is followed on Suno's own hosts only.
+ */
+import { resolvePublicUrl } from '../lib/safeUrlFetch.js';
+import { isSunoHost, isSunoSongUrl, sunoSongIdFromUrl } from '../lib/sunoSong.js';
+
+const TIMEOUT_MS = 20_000;
+// Suno serves its pages to browsers; a bare fetch user agent can get a challenge page instead.
+export const SUNO_FETCH_HEADERS = { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0 Safari/537.36' };
+
+/** The canonical song page for a song id. */
+export const canonicalSunoSongUrl = (songId) => `https://suno.com/song/${songId}`;
+
+/** True for a Suno share link: a Suno song link that carries no song id until resolved. */
+export const isSunoShareLink = (url) => isSunoSongUrl(url) && !sunoSongIdFromUrl(url);
+
+/** The song id a Suno song page or share link leads to; throws when a share link leads nowhere. */
+export async function resolveSunoSongId(url, deps = {}) {
+ const direct = sunoSongIdFromUrl(url);
+ if (direct) return direct;
+ const finalUrl = await (deps.resolveUrl || resolvePublicUrl)(String(url).trim(), {
+ timeoutMs: TIMEOUT_MS, headers: SUNO_FETCH_HEADERS, allowUrl: (u) => u.protocol === 'https:' && isSunoHost(u.hostname),
+ });
+ const songId = sunoSongIdFromUrl(finalUrl);
+ if (!songId) throw new Error('That Suno link did not lead to a song page');
+ return songId;
+}
+
+/**
+ * `url` with a share link swapped for its song page; any other value (a song
+ * page, an empty or unrelated string) comes back unchanged.
+ */
+export async function canonicalizeSunoUrl(url, deps = {}) {
+ if (!isSunoShareLink(url)) return url;
+ return canonicalSunoSongUrl(await resolveSunoSongId(url, deps));
+}
diff --git a/server/services/trackSunoImport.js b/server/services/trackSunoImport.js
index 8034092dc6..185f0a2222 100644
--- a/server/services/trackSunoImport.js
+++ b/server/services/trackSunoImport.js
@@ -18,10 +18,11 @@ import { ServerError } from '../lib/errorHandler.js';
import { shortId } from '../lib/fileUtils.js';
import { findFfmpeg, probeVideoDuration, runFfmpegProcess } from '../lib/ffmpeg.js';
import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay } from '../lib/sseUtils.js';
-import { fetchPublicBinary, fetchPublicText, resolvePublicUrl } from '../lib/safeUrlFetch.js';
+import { fetchPublicBinary, fetchPublicText } from '../lib/safeUrlFetch.js';
import {
- isSunoSongUrl, isSunoHost, sunoSongIdFromUrl, sunoCdnAudioUrl, sunoCdnVideoUrl, parseSunoSongPage, SUNO_URL_INVALID_MESSAGE,
+ isSunoSongUrl, sunoCdnAudioUrl, sunoCdnVideoUrl, parseSunoSongPage, SUNO_URL_INVALID_MESSAGE,
} from '../lib/sunoSong.js';
+import { resolveSunoSongId, SUNO_FETCH_HEADERS as HEADERS } from './sunoShareLink.js';
import { importUploadedTrack, MUSIC_UPLOAD_MAX_BYTES } from './pipeline/musicLibrary.js';
import { createTrack } from './tracks/index.js';
import { RENDER_SOURCES } from './tracks/logic.js';
@@ -31,8 +32,6 @@ const PAGE_MAX_BYTES = 5 * 1024 * 1024;
const AUDIO_TIMEOUT_MS = 5 * 60 * 1000;
// The song's video carries a picture track too, so it may run well past the audio cap.
const VIDEO_MAX_BYTES = 250 * 1024 * 1024;
-// Suno serves its pages to browsers; a bare fetch user agent can get a challenge page instead.
-const HEADERS = { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0 Safari/537.36' };
// Suno's CDN serves audio/mpeg; a missing type or octet-stream is still worth probing.
const isAudioResponse = (contentType) => {
@@ -147,18 +146,6 @@ export function cancelSunoImport(jobId) {
return true;
}
-// A share link (suno.com/s/…) redirects to the song page; follow it on Suno's own hosts only.
-async function resolveSongId(url) {
- const direct = sunoSongIdFromUrl(url);
- if (direct) return direct;
- const finalUrl = await resolvePublicUrl(url, {
- timeoutMs: PAGE_TIMEOUT_MS, headers: HEADERS, allowUrl: (u) => u.protocol === 'https:' && isSunoHost(u.hostname),
- });
- const songId = sunoSongIdFromUrl(finalUrl);
- if (!songId) throw new Error('That Suno link did not lead to a song page');
- return songId;
-}
-
/**
* Kick off a Suno song import. Throws 400 for a URL that isn't a Suno song
* link; everything after that runs detached and reports over SSE.
@@ -181,7 +168,7 @@ export async function startSunoImport(url) {
};
try {
broadcastSse(job, { type: 'progress', percent: 5, stage: 'reading' });
- const songId = await resolveSongId(url.trim());
+ const songId = await resolveSunoSongId(url.trim());
// The page only adds metadata; a page Suno won't serve still imports the audio.
const html = await fetchPublicText(`https://suno.com/song/${songId}`, {
timeoutMs: PAGE_TIMEOUT_MS, headers: HEADERS, maxBytes: PAGE_MAX_BYTES, throwOnUnsafe: false,