Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
- **Extensions in the source order**: installed extensions show up in the source priority list and can be dragged like any other source. By default they sit right before Soulseek.
- Needs FLACidal-Core v0.30.0.

### Web parity
- **Server file browser** (English, French, German, keyboard and screen reader friendly) replaces the native pickers in the browser: Analyzer, Converter, Resampler, Lyrics and File Manager choose files and folders on the server. Tools stay inside the download folder and the library paths (`GET /api/browse?scope=tools`); picking a download folder or library works anywhere on the server and lists folders only (`scope=folders`). `GET /api/browse/flac` lists the FLAC files of a chosen folder.
- **Export and import of the config in the browser**: `GET /api/config/export` and `POST /api/config/import`, same file format as the desktop app, the 8 credentials blanked, the user and password removed from every URL (proxy, Jellyfin, custom endpoints), and the server token never included.
- **Live logs**: log entries reach the Terminal as they are written, in the browser through `/ws` and in the desktop app through the `log` event, which was only sent for a few messages before. The desktop app sends every event to the window through one queue, where repeated progress updates of a download or of the FFmpeg install are merged into the latest one. A log line is dropped from the live view only if that queue is full (it stays in the log history). The browser reloads the history after a dropped connection.
- **Discography, artist images and FFmpeg install in the browser**: `POST /api/discography/expand`, `/api/discography/queue`, `/api/artists/assets` and `/api/ffmpeg/install`, sharing their code with the desktop app. FFmpeg progress comes through `/ws` and a second install at the same time is refused.
- The drop zone buttons work in the browser. The buttons that open the local file manager and the in-app update are hidden there.
- Needs FLACidal-Core v0.31.0.

### Changed
- Importing a config no longer erases the credentials already saved when the file has them blank (desktop app and browser), as long as the file sends them to the same hosts: the Qobuz credentials need the same Qobuz endpoints and proxy, the Jellyfin key the same Jellyfin URL and proxy. Otherwise they are not carried over, so a shared file cannot send them to another server. A credential present in the file still replaces the saved one.
- A race in the `/ws` client counter is fixed.

### New features
- **Test endpoints**: a button in Settings > Status sends one reference request to every endpoint (Tidal HiFi, Qobuz proxies, Amazon proxies, self-hosted ones included) and shows the result. It runs in the background, so the interface stays responsive and a download in progress is not slowed down. Every source is probed in parallel; endpoints that share a host are probed one after the other.
- **Three reference tracks per source** instead of a single one. The next reference is tried only when the previous one is not found on that endpoint. If none is found, the row shows "reference track not found" in grey rather than a failure.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ The server reads from the same `~/.flacidal/config.json` as the desktop app. It'

**File confinement.** In headless mode, file routes (delete, rename, convert, lyrics, analyzer by path) only accept paths under the download folder and the `externalLibraryPaths` entries. Symlinks that lead outside are refused.

**Same tools as the desktop app.** In the browser, file and folder pickers open a server-side file browser. Tool inputs and outputs stay under the download folder and library paths; choosing a download folder or library can go anywhere on the server (folders only). Config export and import, live logs in the Terminal, discography, artist images and the FFmpeg install all work. Drag and drop, "open the folder in the file manager" and in-app updates exist only in the desktop app.

Note that `GET /api/config` still returns the Qobuz and Soulseek credentials to any authenticated client.

Running `go run ./cmd/server` before the frontend is built works fine: the server still comes up and the API works on its own, though requests to `/` return a 503 nudging you to run `npm run build` first.
Expand Down
235 changes: 235 additions & 0 deletions frontend/e2e-http/06-file-browser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { createRequire } from 'node:module'
import { test, expect } from '@playwright/test'
import { openTool, openView, pickCurrentFolder, pickFiles, pickFolderAt, seedFlac, setFolder } from './helpers'

const axePath = createRequire(import.meta.url).resolve('axe-core/axe.min.js')
const NAMES = ['alpha.flac', 'beta.flac', 'gamma.flac']

test.describe('Server file browser in the tools', () => {
let dir: string

test.beforeEach(async ({ request }) => {
dir = seedFlac(NAMES)
await setFolder(request, dir)
})

test.afterEach(() => {
fs.rmSync(dir, { recursive: true, force: true })
})

test('Audio Quality Analyzer: files, then a whole folder', async ({ page }) => {
await page.goto('/')
await openTool(page, 'Audio Quality Analyzer')
await page.getByRole('button', { name: 'Select Files' }).click()
await pickFiles(page, 'alpha.flac', 'beta.flac')
await expect(page.locator('.table-row')).toHaveCount(2)

await page.getByRole('button', { name: 'Analyze More' }).click()
await page.getByRole('button', { name: 'Select Folder' }).click()
await pickCurrentFolder(page)
await expect(page.locator('.table-row')).toHaveCount(3)
})

test('Audio Converter: files and an output folder', async ({ page }) => {
await page.goto('/')
await openTool(page, 'Audio Converter')
await page.getByRole('button', { name: 'Select Files' }).click()
await pickFiles(page, 'alpha.flac', 'gamma.flac')
await expect(page.getByText('alpha.flac')).toBeVisible()
await expect(page.getByText('gamma.flac')).toBeVisible()

await page.locator('.btn.btn-accent', { hasText: /Browse/i }).first().click()
await pickCurrentFolder(page)
await expect(page.getByRole('textbox', { name: 'Output Folder' })).toHaveValue(dir)
})

test('Audio Resampler: files and an output folder', async ({ page }) => {
await page.goto('/')
await openTool(page, 'Audio Resampler')
await page.getByRole('button', { name: 'Select Files' }).click()
await pickFiles(page, 'beta.flac')
await expect(page.getByText('1 file selected')).toBeVisible()

await expect(page.getByText('Not selected')).toBeVisible()
await page.getByRole('button', { name: 'Browse' }).first().click()
await pickCurrentFolder(page)
await expect(page.getByText('Not selected')).toHaveCount(0)
})

test('Lyrics Manager: files', async ({ page }) => {
await page.goto('/')
await openTool(page, 'Lyrics Manager')
await page.getByRole('button', { name: 'Select Files' }).click()
await pickFiles(page, 'alpha.flac', 'beta.flac', 'gamma.flac')
for (const n of NAMES) await expect(page.getByText(n)).toBeVisible()
})

test('File Manager: a folder fills the list', async ({ page }) => {
await page.goto('/')
await openTool(page, 'File Manager')
// The File Manager picks its folder anywhere on the server, not only inside the allowed ones.
await page.locator('.folder-bar .btn-accent').click()
await pickFolderAt(page, dir)
await expect(page.locator('.folder-bar input')).toHaveValue(dir)
await expect(page.getByText('3 files')).toBeVisible()
})

test('works from the keyboard alone and gives the focus back', async ({ page }) => {
await page.goto('/')
await openTool(page, 'Lyrics Manager')
const opener = page.getByRole('button', { name: 'Select Files' })
await opener.focus()
await page.keyboard.press('Enter')

const dialog = page.locator('[role="dialog"]')
await expect(dialog).toBeVisible()
await expect(dialog.getByLabel('alpha.flac')).toBeVisible()
// Focus stays inside the dialog however many times Tab is pressed.
for (let i = 0; i < 12; i++) {
await page.keyboard.press('Tab')
expect(await dialog.evaluate((d) => d.contains(document.activeElement))).toBe(true)
}
await dialog.getByLabel('beta.flac').focus()
await page.keyboard.press('Space')
await dialog.getByRole('button', { name: 'Select', exact: true }).focus()
await page.keyboard.press('Enter')
await expect(dialog).toHaveCount(0)
await expect(page.getByText('beta.flac')).toBeVisible()

await opener.or(page.getByRole('button', { name: 'Add More' })).first().focus()
await page.keyboard.press('Enter')
await expect(dialog).toBeVisible()
await page.keyboard.press('Escape')
await expect(dialog).toHaveCount(0)
await expect(page.getByRole('button', { name: 'Add More' })).toBeFocused()
})

for (const theme of ['dark', 'light'] as const) {
test(`passes axe in the ${theme} theme`, async ({ page }) => {
await page.goto('/')
await page.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
await openTool(page, 'Lyrics Manager')
await page.getByRole('button', { name: 'Select Files' }).click()
await expect(page.locator('[role="dialog"]').getByLabel('alpha.flac')).toBeVisible()
await page.addScriptTag({ path: axePath })
const violations = await page.evaluate(async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const r = await (window as any).axe.run(document.querySelector('[role="dialog"]'))
return r.violations.map((v: { id: string; nodes: { target: unknown[] }[] }) => `${v.id}: ${v.nodes.map((n) => n.target.join(' ')).join(' | ')}`)
})
expect(violations).toEqual([])
})
}
})

test.describe('Browse routes on the real server', () => {
let dir: string
let outside: string

test.beforeEach(async ({ request }) => {
dir = seedFlac(NAMES)
outside = fs.mkdtempSync(path.join(os.tmpdir(), 'flacidal-e2e-outside-'))
fs.symlinkSync(outside, path.join(dir, 'escape'))
await setFolder(request, dir)
})

test.afterEach(() => {
fs.rmSync(dir, { recursive: true, force: true })
fs.rmSync(outside, { recursive: true, force: true })
})

test('tools scope refuses paths outside the allowed folders', async ({ request }) => {
const get = (p: string) => request.get(`/api/browse?scope=tools&path=${encodeURIComponent(p)}`)
expect((await get('/etc')).status()).toBe(403)
expect((await get(`${dir}/../..`)).status()).toBe(403)
expect((await get(path.join(dir, 'escape'))).status()).toBe(403)
})

test('tools scope hides outgoing symlinks and lists only FLAC files when asked', async ({ request }) => {
const res = await request.get(`/api/browse?scope=tools&files=1&path=${encodeURIComponent(dir)}`)
expect(res.ok()).toBe(true)
const names = (await res.json()).entries.map((e: { name: string }) => e.name)
expect(names).toEqual(NAMES)
})

test('folders scope lists folders anywhere and never files', async ({ request }) => {
fs.mkdirSync(path.join(outside, 'sub'))
fs.writeFileSync(path.join(outside, 'x.flac'), 'x')
const res = await request.get(`/api/browse?scope=folders&files=1&path=${encodeURIComponent(outside)}`)
expect(res.ok()).toBe(true)
const names = (await res.json()).entries.map((e: { name: string }) => e.name)
expect(names).toEqual(['sub'])
})

test('/api/browse/flac is recursive and confined', async ({ request }) => {
fs.mkdirSync(path.join(dir, 'deep'))
fs.copyFileSync(path.join(dir, 'alpha.flac'), path.join(dir, 'deep', 'delta.flac'))
const ok = await request.get(`/api/browse/flac?path=${encodeURIComponent(dir)}`)
expect((await ok.json()).paths).toHaveLength(4)
expect((await request.get(`/api/browse/flac?path=${encodeURIComponent(outside)}`)).status()).toBe(403)
})

test('browse needs the token on the protected server', async ({ playwright }) => {
const { TOKEN_URL } = await import('./servers')
const anon = await playwright.request.newContext({ baseURL: TOKEN_URL })
expect((await anon.get('/api/browse?scope=folders&path=/tmp')).status()).toBe(401)
expect((await anon.get('/api/browse/flac?path=/tmp')).status()).toBe(401)
await anon.dispose()
})
})

test.describe('Choosing a download folder anywhere', () => {
let tmp: string
let start: string

test.beforeEach(async ({ request }) => {
tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'flacidal-e2e-pick-'))
start = seedFlac(NAMES)
await setFolder(request, start)
})

test.afterEach(() => {
fs.rmSync(tmp, { recursive: true, force: true })
fs.rmSync(start, { recursive: true, force: true })
})

test('a folder outside the old one can be chosen and saved, with no file in the list', async ({ page, request }) => {
const target = path.join(tmp, 'new-music')
fs.mkdirSync(target)
fs.writeFileSync(path.join(target, 'song.flac'), 'x')

await page.goto('/')
await openView(page, 'Settings')
await page.locator('.browse-btn').first().click()
const dialog = page.locator('[role="dialog"]')
await expect(dialog).toBeVisible()
await dialog.getByLabel('Folder path').fill(target)
await dialog.getByLabel('Folder path').press('Enter')
await expect(dialog.getByLabel('Folder path')).toHaveValue(target)
await expect(dialog.locator('input[type="checkbox"]')).toHaveCount(0)
await expect(dialog.getByText('song.flac')).toHaveCount(0)
await dialog.getByRole('button', { name: 'Choose this folder' }).click()

await expect(page.locator('#download-folder')).toHaveValue(target)
const cfg = await (await request.get('/api/config')).json()
expect(cfg.downloadFolder).toBe(target)
})

test('the root folder is refused when saving', async ({ page, request }) => {
await page.goto('/')
await openView(page, 'Settings')
await page.locator('.browse-btn').first().click()
const dialog = page.locator('[role="dialog"]')
await dialog.getByLabel('Folder path').fill('/')
await dialog.getByLabel('Folder path').press('Enter')
await expect(dialog.getByLabel('Folder path')).toHaveValue('/')
await dialog.getByRole('button', { name: 'Choose this folder' }).click()

await expect(page.locator('.toast').first()).toBeVisible()
const cfg = await (await request.get('/api/config')).json()
expect(cfg.downloadFolder).toBe(start)
})
})
Loading
Loading