Exports can now be multiplatform

This commit is contained in:
patben8 committed 2026-09-27 14:35:27 +02:00
1 parent 99d590a051
commit c2f5191962
18 files changed
+373 -86

No files matched your search

+10 -4
View File
@@ -277,6 +277,8 @@ export interface PlatformOption {
/** The library lives on plugged-in media, so `found` changes between calls —
* and `found === 0` means "nothing plugged in", not "not installed". */
removable: boolean
/** As an export target: its library is only found at a drive's ROOT. */
drive_root?: boolean
}
export interface EditState {
@@ -447,8 +449,9 @@ export interface SourceStatus {
export interface ExportSet {
id: string
name: string
/** Platform id of the export TARGET, e.g. "traktor". */
target: string
/** Platform ids of the export TARGETS, e.g. ["traktor", "onelibrary"]. Never
* empty. They share one destination and ONE copy of the audio. */
targets: string[]
destination: string
playlist_ids: string[]
/** LOOSE tracks only — tracks a referenced playlist supplies are not listed. */
@@ -492,6 +495,9 @@ export interface ExportPreview {
blocked: 'destination_not_empty' | 'nothing_to_export' | 'unsupported_target' | null
/** The destination already holds a Konduktor export, which will be replaced. */
replacing: boolean
/** Targets whose library is only found at a drive's root, when the destination
* is not one. A warning — the export can still run. */
not_drive_root: string[]
}
export interface FsPlace {
@@ -649,9 +655,9 @@ export const api = {
// All scoped to the LOADED library on the server, by its stable id, so
// nothing here has to carry which collection it means.
exports: () => getJSON<ExportSet[]>('/api/exports'),
createExport: (body: { name: string; target: string; destination: string }) =>
createExport: (body: { name: string; targets: string[]; destination: string }) =>
send<ExportSet>('POST', '/api/exports', body),
updateExport: (id: string, body: Partial<Pick<ExportSet, 'name' | 'target' | 'destination'>>) =>
updateExport: (id: string, body: Partial<Pick<ExportSet, 'name' | 'targets' | 'destination'>>) =>
send<ExportSet>('PATCH', `/api/exports/${encodeURIComponent(id)}`, body),
deleteExport: (id: string) =>
send<{ deleted: boolean }>('DELETE', `/api/exports/${encodeURIComponent(id)}`),
+37 -9
View File
@@ -5,7 +5,11 @@ import { api, type ExportSet } from '../api'
import { FolderPicker } from './FolderPicker'
/**
* Create or edit an export: its name, its target platform and where it lands.
* Create or edit an export: its name, its target platforms and where it lands.
*
* Several platforms can be ticked. They share the destination and ONE copy of
* the audio (under `Contents/`), each writing its own library beside it — so a
* stick can carry a Traktor collection and a OneLibrary library at once.
*
* All three are settled up front, and the destination especially is NOT a
* detail deferred to export time. A Traktor `<LOCATION>` is a volume name plus
@@ -23,7 +27,7 @@ interface Props {
export function ExportDialog({ editing, onClose, onSaved, onError }: Props) {
const [name, setName] = useState(editing?.name ?? '')
const [target, setTarget] = useState(editing?.target ?? 'traktor')
const [chosen, setChosen] = useState<string[]>(editing?.targets ?? ['traktor'])
const [destination, setDestination] = useState(editing?.destination ?? '')
const [browsing, setBrowsing] = useState(false)
const [busy, setBusy] = useState(false)
@@ -42,12 +46,29 @@ export function ExportDialog({ editing, onClose, onSaved, onError }: Props) {
enabled: !!editing,
}).data?.destination_conflict
const valid = name.trim() !== '' && destination.trim() !== ''
// Some targets are only found at a drive's root (a CDJ looks for `PIONEER/`
// there and nowhere else). Warned, not refused: the other targets are fine in
// any folder. Checked against the same polled drive list the sidebar uses.
const drives = useQuery({ queryKey: ['drives'], queryFn: api.drives })
const trim = (p: string) => p.replace(/[\\/]+$/, '') || p
const atDriveRoot =
destination.trim() !== '' &&
(drives.data ?? []).some((d) => trim(d.path) === trim(destination.trim()))
const needsRoot = (targets.data ?? []).filter(
(p) => p.drive_root && chosen.includes(p.platform),
)
const toggle = (platform: string, on: boolean) =>
setChosen((prev) =>
on ? [...prev.filter((t) => t !== platform), platform] : prev.filter((t) => t !== platform),
)
const valid = name.trim() !== '' && destination.trim() !== '' && chosen.length > 0
const save = async () => {
setBusy(true)
try {
const body = { name: name.trim(), target, destination: destination.trim() }
const body = { name: name.trim(), targets: chosen, destination: destination.trim() }
const saved = editing
? await api.updateExport(editing.id, body)
: await api.createExport(body)
@@ -102,10 +123,10 @@ export function ExportDialog({ editing, onClose, onSaved, onError }: Props) {
}`}
>
<input
type="radio"
type="checkbox"
disabled={!p.installed}
checked={target === p.platform}
onChange={() => setTarget(p.platform)}
checked={chosen.includes(p.platform)}
onChange={(e) => toggle(p.platform, e.target.checked)}
className="accent-accent"
/>
<span className={p.installed ? 'text-text' : 'text-faint'}>{p.name}</span>
@@ -137,9 +158,16 @@ export function ExportDialog({ editing, onClose, onSaved, onError }: Props) {
</button>
</div>
<div className="mt-1 text-[11px] text-faint">
The folder gets a <span className="font-mono">collection.nml</span> and a copy of
every track, in your own folder structure.
The folder gets a library for each platform, plus one copy of every track under{' '}
<span className="font-mono">Contents/</span>, in your own folder structure.
</div>
{needsRoot.length > 0 && destination.trim() !== '' && !atDriveRoot && (
<div className="mt-2 rounded well px-3 py-2 text-xs text-gold">
{needsRoot.map((p) => p.name).join(' and ')} is only found at the top of a
drive. Choose the drive itself rather than a folder on it, or players won’t see
this export.
</div>
)}
{conflict && (
<div className="mt-2 rounded well px-3 py-2 text-xs text-gold">
“{conflict}” already exports here. Exporting replaces whatever the other one
+30 -11
View File
@@ -38,6 +38,10 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
const [starting, setStarting] = useState(false)
const pollRef = useRef<number | null>(null)
// Platform names for wording the facts the preview and result carry as ids.
const platforms = useQuery({ queryKey: ['export-targets'], queryFn: api.exportTargets })
const nameOf = (id: string) => platforms.data?.find((p) => p.platform === id)?.name ?? id
const preview = useQuery<ExportPreview>({
queryKey: ['export-preview', set.id],
queryFn: () => api.exportPreview(set.id),
@@ -155,9 +159,19 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
This folder already holds an export. Its files will be replaced.
</div>
)}
{/* A warning, not a block: the other targets are fine anywhere,
and staging a stick's contents in a folder is legitimate. */}
{p.not_drive_root.length > 0 && (
<div className="rounded well px-3 py-2 text-xs text-gold">
{p.not_drive_root.map(nameOf).join(' and ')} is only found at the top of a
drive, and this folder isn’t one — players won’t see it unless you move the
folder’s contents to a drive’s top level.
</div>
)}
<div className="text-xs text-faint">
Writes a <span className="font-mono">collection.nml</span> plus a copy of every
track, in your own folder structure.
Writes a library for {set.targets.map(nameOf).join(' and ')}, sharing one copy
of every track under <span className="font-mono">Contents/</span>, in your own
folder structure.
</div>
</div>
)}
@@ -209,21 +223,26 @@ export function ExportRunDialog({ set, onClose, onDone, onError }: Props) {
)}
{job.state === 'cancelled' && (
<div className="text-xs text-muted">
Cancelled. Everything this export copied was removed, and no library file was
Cancelled. Everything this export copied was removed, and no library was
written.
</div>
)}
{job.state === 'failed' && <div className="text-xs text-pink">{job.error}</div>}
{job.state === 'failed' && (
<div className="text-xs text-pink">
{job.error} — nothing was left behind: no audio, and no library for any platform.
</div>
)}
{job.state === 'done' && (
<div className="space-y-1 text-xs text-mint">
<div>Done — the folder is ready.</div>
{/* Ben's workflow: the exported collection.nml is swapped into
a Traktor install, which REPLACES that machine's own. */}
<div className="text-faint">
To use it: quit Traktor, back up its existing{' '}
<span className="font-mono">collection.nml</span>, then put this one in its
place.
</div>
{(
(job.result as { libraries?: { platform: string; library: string }[] } | null)
?.libraries ?? []
).map((l) => (
<div key={l.platform} className="text-faint">
{nameOf(l.platform)}: <span className="font-mono">{l.library}</span>
</div>
))}
</div>
)}
</div>
+1 -1
View File
@@ -197,7 +197,7 @@ function ExportRow({
</span>
</button>
<button
title="Edit name, target and destination"
title="Edit name, platforms and destination"
onClick={onEdit}
className="shrink-0 px-1 text-xs text-faint opacity-0 hover:text-text group-hover:opacity-100"
>