Public shares: any valid Immich link opens through the proxy and is recorded in /admin, with a per-share sign-in-only switch; comments stay recipient-only
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import { mkdtempSync, rmSync } from 'fs'
|
||||
import { tmpdir } from 'os'
|
||||
import { join } from 'path'
|
||||
import { DatabaseSync } from 'node:sqlite'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { Store } from '../src/magic/store'
|
||||
import { hashToken, safeNextPath } from '../src/magic/tokens'
|
||||
@@ -155,3 +159,51 @@ describe('safeNextPath', () => {
|
||||
expect(safeNextPath(['/a'])).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('public shares', () => {
|
||||
it('a share added by the admin requires sign-in unless marked public', () => {
|
||||
expect(store.upsertShare({ key: 'k1', slug: null, title: 'A', password: null }, T0).public).toBe(false)
|
||||
expect(store.upsertShare({ key: 'k2', slug: null, title: 'B', password: null, public: true }, T0).public).toBe(true)
|
||||
})
|
||||
|
||||
it('saving a share again keeps its setting unless one is given', () => {
|
||||
store.upsertShare({ key: 'k1', slug: null, title: 'A', password: null, public: true }, T0)
|
||||
expect(store.upsertShare({ key: 'k1', slug: null, title: 'A2', password: null }, T1).public).toBe(true)
|
||||
expect(store.upsertShare({ key: 'k1', slug: null, title: 'A2', password: null, public: false }, T1).public).toBe(false)
|
||||
store.setSharePublic('k1', true)
|
||||
expect(store.getShare('k1')?.public).toBe(true)
|
||||
})
|
||||
|
||||
it('a discovered share starts public, and never overwrites one on file', () => {
|
||||
expect(store.addDiscoveredShare({ key: 'k1', slug: 'one', title: 'Found' }, T0)).toMatchObject({ public: true, password: null })
|
||||
store.upsertShare({ key: 'k2', slug: null, title: 'Mine', password: 'pw' }, T0)
|
||||
expect(store.addDiscoveredShare({ key: 'k2', slug: null, title: 'Other' }, T1)).toMatchObject({ title: 'Mine', password: 'pw', public: false })
|
||||
})
|
||||
|
||||
it('finds a share by key or slug, and lists the setting', () => {
|
||||
store.addDiscoveredShare({ key: 'k1', slug: 'one', title: 'Found' }, T0)
|
||||
expect(store.findShare('k1')?.key).toBe('k1')
|
||||
expect(store.findShare('one')?.key).toBe('k1')
|
||||
expect(store.findShare('nope')).toBeUndefined()
|
||||
expect(store.listShares()[0].public).toBe(true)
|
||||
})
|
||||
|
||||
it('upgrades a database from before the setting, keeping its shares sign-in only', () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'imp-store-'))
|
||||
try {
|
||||
const path = join(dir, 'magic.db')
|
||||
const old = new DatabaseSync(path)
|
||||
old.exec(`CREATE TABLE shares (key TEXT PRIMARY KEY, slug TEXT, title TEXT NOT NULL DEFAULT '', password TEXT,
|
||||
last_scanned_at TEXT, created_at TEXT NOT NULL)`)
|
||||
old.prepare('INSERT INTO shares (key, slug, title, password, created_at) VALUES (?, ?, ?, ?, ?)').run('old', null, 'Old', null, T0)
|
||||
old.close()
|
||||
const upgraded = new Store(path)
|
||||
expect(upgraded.getShare('old')?.public).toBe(false)
|
||||
upgraded.close()
|
||||
// Opening it again doesn't try to add the column twice
|
||||
new Store(path).close()
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user