First push
This commit is contained in:
seclusionenthusiast committed 2026-03-03 14:52:19 +09:00
commit c4a020c191
146 files changed
+40796

No files matched your search

+522
View File
@@ -0,0 +1,522 @@
import type {
Job,
ModelOption,
FormatOption,
ModeOption,
PresetsResponse,
LyricsSource,
LyricsData,
DynamicLevels,
LyricsStyleOptions,
SubsonicSong,
SubsonicConfig,
ImportedFile,
Project,
ProjectDetail,
ModelDownloadInfo,
ModelDownloadProgress,
} from '../types'
const BASE = '/api'
async function request<T>(url: string, init?: RequestInit): Promise<T> {
const res = await fetch(url, init)
if (!res.ok) {
const text = await res.text()
throw new Error(`${res.status}: ${text}`)
}
return res.json() as Promise<T>
}
// ---------- Jobs ----------
export const getJob = (id: string) =>
request<Job>(`${BASE}/jobs/${id}`)
export const listJobs = () =>
request<Job[]>(`${BASE}/jobs`)
export const cancelJob = (id: string) =>
request<{ detail: string }>(`${BASE}/jobs/${id}`, { method: 'DELETE' })
export const downloadUrl = (jobId: string, filename: string) =>
`${BASE}/jobs/${jobId}/download/${encodeURIComponent(filename)}`
// ---------- Separate ----------
export const getSepModels = () =>
request<ModelOption[]>(`${BASE}/separate/models`)
export const getSepFormats = () =>
request<FormatOption[]>(`${BASE}/separate/formats`)
export const getPresets = () =>
request<PresetsResponse>(`${BASE}/separate/presets`)
export const submitSeparate = (
file: File,
model: string,
outputFormat: string,
options?: {
presetType?: string
staticOption?: string
dynamicLevels?: DynamicLevels
projectName?: string
sepPowerPreset?: string
}
) => {
const fd = new FormData()
fd.append('file', file)
fd.append('model', model)
fd.append('output_format', outputFormat)
if (options?.presetType) {
fd.append('preset_type', options.presetType)
}
if (options?.staticOption) {
fd.append('static_option', options.staticOption)
}
if (options?.dynamicLevels) {
fd.append('dynamic_levels', JSON.stringify(options.dynamicLevels))
}
if (options?.projectName) {
fd.append('project_name', options.projectName)
}
if (options?.sepPowerPreset) {
fd.append('sep_power_preset', options.sepPowerPreset)
}
return request<{ job_id: string; preset_type: string; project_name?: string }>(
`${BASE}/separate`,
{ method: 'POST', body: fd }
)
}
// ---------- Transcribe ----------
export const getTranscribeModes = () =>
request<ModeOption[]>(`${BASE}/transcribe/modes`)
export const submitTranscribe = (file: File, mode: string) => {
const fd = new FormData()
fd.append('file', file)
fd.append('mode', mode)
return request<{ job_id: string }>(`${BASE}/transcribe`, { method: 'POST', body: fd })
}
// ---------- ABC Convert ----------
export const submitAbcConvert = (files: File[], songTitle: string) => {
const fd = new FormData()
files.forEach((f) => fd.append('files', f))
fd.append('song_title', songTitle)
return request<{ job_id: string }>(`${BASE}/abc-convert`, { method: 'POST', body: fd })
}
// ---------- Pipeline ----------
export const submitPipeline = (
file: File,
sepModel: string,
sepFormat: string,
transcribeMode: string,
songTitle: string,
) => {
const fd = new FormData()
fd.append('file', file)
fd.append('sep_model', sepModel)
fd.append('sep_format', sepFormat)
fd.append('transcribe_mode', transcribeMode)
fd.append('song_title', songTitle)
return request<{ job_id: string }>(`${BASE}/pipeline`, { method: 'POST', body: fd })
}
// ---------- LRC Alignment ----------
export const getLyricsSources = () =>
request<LyricsSource[]>(`${BASE}/lrc/sources`)
export const extractLyrics = (file: File) => {
const fd = new FormData()
fd.append('file', file)
return request<LyricsData>(`${BASE}/lrc/extract`, { method: 'POST', body: fd })
}
export const submitLrcAlign = (
audio: File,
options: {
lyricsSource: string
lyricsText?: string
outputFilename?: string
styleOptions?: LyricsStyleOptions
}
) => {
const fd = new FormData()
fd.append('audio', audio)
fd.append('lyrics_source', options.lyricsSource)
if (options.lyricsText) {
fd.append('lyrics_text', options.lyricsText)
}
if (options.outputFilename) {
fd.append('output_filename', options.outputFilename)
}
if (options.styleOptions) {
fd.append('style_options', JSON.stringify(options.styleOptions))
}
return request<{ job_id: string }>(`${BASE}/lrc/align`, { method: 'POST', body: fd })
}
export const submitLrcAlignWithFile = (
audio: File,
lyricsFile: File,
outputFilename?: string,
styleOptions?: LyricsStyleOptions
) => {
const fd = new FormData()
fd.append('audio', audio)
fd.append('lyrics_file', lyricsFile)
if (outputFilename) {
fd.append('output_filename', outputFilename)
}
if (styleOptions) {
fd.append('style_options', JSON.stringify(styleOptions))
}
return request<{ job_id: string }>(`${BASE}/lrc/align-with-file`, { method: 'POST', body: fd })
}
export const submitLrcAlignExisting = (
projectName: string,
options: {
lyricsSource: string
lyricsText?: string
outputFilename?: string
styleOptions?: LyricsStyleOptions
}
) => {
const fd = new FormData()
fd.append('project_name', projectName)
fd.append('lyrics_source', options.lyricsSource)
if (options.lyricsText) {
fd.append('lyrics_text', options.lyricsText)
}
if (options.outputFilename) {
fd.append('output_filename', options.outputFilename)
}
if (options.styleOptions) {
fd.append('style_options', JSON.stringify(options.styleOptions))
}
return request<{ job_id: string }>(`${BASE}/lrc/align-existing`, { method: 'POST', body: fd })
}
// ---------- Quick-action helpers (from existing project/job on server) ----------
export const submitTranscribeFromProject = (projectName: string, mode = 'music') => {
const fd = new FormData()
fd.append('project_name', projectName)
fd.append('mode', mode)
return request<{ job_id: string; stem: string }>(`${BASE}/transcribe/from-project`, { method: 'POST', body: fd })
}
export const submitAbcConvertFromJob = (sourceJobId: string, songTitle = '') => {
const fd = new FormData()
fd.append('source_job_id', sourceJobId)
fd.append('song_title', songTitle)
return request<{ job_id: string }>(`${BASE}/abc-convert/from-job`, { method: 'POST', body: fd })
}
// ---------- Subsonic ----------
export const getSubsonicConfig = () =>
request<SubsonicConfig>(`${BASE}/subsonic/config`)
export const saveSubsonicConfig = (url: string, username: string, password: string) =>
request<SubsonicConfig>(`${BASE}/subsonic/config`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url, username, password }),
})
export const deleteSubsonicConfig = () =>
request<SubsonicConfig>(`${BASE}/subsonic/config`, { method: 'DELETE' })
export const searchSubsonic = (q: string, count = 20) =>
request<SubsonicSong[]>(`${BASE}/subsonic/search?q=${encodeURIComponent(q)}&count=${count}`)
export const importSubsonicSong = (song: SubsonicSong) =>
request<ImportedFile>(`${BASE}/subsonic/import`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ id: song.id, title: song.title, artist: song.artist, suffix: song.suffix }),
})
export const listImports = () =>
request<ImportedFile[]>(`${BASE}/subsonic/imports`)
export const deleteImport = (filename: string) =>
request<{ detail: string }>(`${BASE}/subsonic/imports/${encodeURIComponent(filename)}`, { method: 'DELETE' })
// ---------- Separate from imported file ----------
export const submitSeparateFromPath = (
filePath: string,
model: string,
outputFormat: string,
options?: {
presetType?: string
staticOption?: string
dynamicLevels?: DynamicLevels
projectName?: string
sepPowerPreset?: string
}
) => {
const fd = new FormData()
fd.append('file_path', filePath)
fd.append('model', model)
fd.append('output_format', outputFormat)
if (options?.presetType) fd.append('preset_type', options.presetType)
if (options?.staticOption) fd.append('static_option', options.staticOption)
if (options?.dynamicLevels) fd.append('dynamic_levels', JSON.stringify(options.dynamicLevels))
if (options?.projectName) fd.append('project_name', options.projectName)
if (options?.sepPowerPreset) fd.append('sep_power_preset', options.sepPowerPreset)
return request<{ job_id: string; preset_type: string }>(`${BASE}/separate/from-path`, { method: 'POST', body: fd })
}
// ---------- Projects ----------
export const listProjects = () =>
request<Project[]>(`${BASE}/projects`)
export const getProjectDetail = (id: string) =>
request<ProjectDetail>(`${BASE}/projects/${id}`)
export const deleteProject = (id: string) =>
request<{ detail: string }>(`${BASE}/projects/${id}`, { method: 'DELETE' })
export const transcribeProject = (id: string, stemName: string, mode: string) =>
request<{ job_id: string }>(`${BASE}/projects/${id}/transcribe`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ stem_name: stemName, mode }),
})
export const abcProject = (id: string, stemName: string, songTitle?: string) =>
request<{ job_id: string }>(`${BASE}/projects/${id}/abc`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ stem_name: stemName, song_title: songTitle }),
})
export const mixProject = (
id: string,
presetType: 'static' | 'dynamic',
opts?: { staticOption?: string; dynamicLevels?: Record<string, number> }
) =>
request<{ job_id: string }>(`${BASE}/projects/${id}/mix`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
preset_type: presetType,
static_option: opts?.staticOption,
dynamic_levels: opts?.dynamicLevels,
}),
})
export const lrcProject = (
id: string,
stemName: string,
opts: {
lyricsSource: string
lyricsText?: string
outputFilename?: string
timingPrecision?: 'word' | 'syllable'
lrcPowerPreset?: string
}
) =>
request<{ job_id: string }>(`${BASE}/projects/${id}/lrc`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
stem_name: stemName,
lyrics_source: opts.lyricsSource,
lyrics_text: opts.lyricsText,
output_filename: opts.outputFilename,
timing_precision: opts.timingPrecision ?? 'word',
lrc_power_preset: opts.lrcPowerPreset ?? 'standard',
}),
})
// ---------- Stem Reprocessing ----------
export const reprocessStem = (
projectId: string,
stemName: string,
model: string,
options?: {
outputFormat?: string
}
) =>
request<{ job_id: string }>(`${BASE}/projects/${projectId}/reprocess`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
stem_name: stemName,
model,
output_format: options?.outputFormat ?? 'mp3',
}),
})
// ---------- Lyric Transcription (Whisper AI) ----------
export const lyricTranscribeProject = (
projectId: string,
stemName: string,
opts?: {
model?: string
language?: string
task?: 'transcribe' | 'translate'
outputFormats?: string[]
initialPrompt?: string
temperature?: number
wordTimestamps?: boolean
conditionOnPreviousText?: boolean
beamSize?: number
diarize?: boolean
}
) => {
const wordTs = opts?.wordTimestamps ?? true
return request<{ job_id: string }>(`${BASE}/projects/${projectId}/lyric-transcribe`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
stem_name: stemName,
model: opts?.model ?? 'large-v2',
language: opts?.language || undefined,
task: opts?.task ?? 'transcribe',
output_formats: opts?.outputFormats ?? (wordTs ? ['elrc', 'lrc', 'txt'] : ['lrc', 'txt']),
initial_prompt: opts?.initialPrompt,
temperature: opts?.temperature ?? 0.0,
word_timestamps: wordTs,
condition_on_previous_text: opts?.conditionOnPreviousText ?? true,
beam_size: opts?.beamSize ?? undefined,
engine: 'whisperx',
diarize: opts?.diarize ?? false,
}),
})
}
// ---------- Stem Rename ----------
export const renameStem = (
projectId: string,
stemName: string,
newName: string
) =>
request<{ success: boolean; new_path: string }>(`${BASE}/projects/${projectId}/rename-stem`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
stem_name: stemName,
new_name: newName,
}),
})
// ---------- Per-Instrument Models ----------
export const getPerInstrumentModels = () =>
request<ModelOption[]>(`${BASE}/separate/per-instrument-models`)
// ---------- Model Management ----------
export const listModels = () =>
request<ModelDownloadInfo[]>(`${BASE}/models/list`)
export const downloadModel = (modelId: string) =>
request<{ success: boolean; message: string }>(`${BASE}/models/download`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model_id: modelId }),
})
export const pauseModelDownload = (modelId: string) =>
request<{ success: boolean; message: string }>(`${BASE}/models/pause`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model_id: modelId }),
})
export const resumeModelDownload = (modelId: string) =>
request<{ success: boolean; message: string }>(`${BASE}/models/resume`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model_id: modelId }),
})
export const cancelModelDownload = (modelId: string) =>
request<{ success: boolean; message: string }>(`${BASE}/models/cancel`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model_id: modelId }),
})
export const deleteModel = (modelId: string) =>
request<{ success: boolean; message: string }>(`${BASE}/models/${modelId}`, {
method: 'DELETE',
})
export const getModelProgress = (modelId: string) =>
request<ModelDownloadProgress>(`${BASE}/models/progress/${modelId}`)
export const getAllModelProgress = () =>
request<Record<string, ModelDownloadProgress>>(`${BASE}/models/progress`)
// ---------------------------------------------------------------------------
// Project cleanup / maintenance
// ---------------------------------------------------------------------------
export const cleanupVerify = () =>
request<{ projects_with_missing_files: { project_id: string; name: string; missing_files: string[] }[]; total: number }>(
`${BASE}/projects/cleanup/verify`
)
export const cleanupWriteMetadata = () =>
request<{ written: number; errors: { project: string; error: string }[] }>(
`${BASE}/projects/cleanup/write-metadata`,
{ method: 'POST' }
)
export const cleanupRenameStems = () =>
request<{ renamed: number; errors: { project: string; file: string; error: string }[] }>(
`${BASE}/projects/cleanup/rename-stems`,
{ method: 'POST' }
)
export const cleanupPurgeOrphaned = () =>
request<{ purged: number }>(
`${BASE}/projects/cleanup/purge-orphaned`,
{ method: 'POST' }
)
export const cleanupCleanLrcFiles = () =>
request<{ files_modified: number; lines_removed: number; errors: { file: string; error: string }[] }>(
`${BASE}/projects/cleanup/clean-lrc-files`,
{ method: 'POST' }
)
// ── System ───────────────────────────────────────────────────────────────────
export const getGpuInfo = () =>
request<{ cuda_available: boolean; cuda_ok: boolean; name: string | null; total_mb: number; free_mb: number }>(
`${BASE}/system/gpu-info`
)
export const resetGpu = () =>
request<{ ok: boolean; cuda_available: boolean; cuda_ok: boolean }>(
`${BASE}/system/gpu-reset`,
{ method: 'POST' }
)