用户管理与数据操作
This commit is contained in:
1 parent
ed0f20b754
commit
51d3acfbb5
14 files changed
+256
-33
No files matched your search
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { validateImageKey } from './image-key'
|
||||
import { insertActivityLog, insertUser } from './db'
|
||||
import { getMediaStats, insertImageIndex } from './image-index'
|
||||
import { ensureDefaultBackends } from './storage-backends'
|
||||
|
||||
describe('image index key validation', () => {
|
||||
it('accepts standard image keys used in index', () => {
|
||||
@@ -16,3 +19,62 @@ describe('image index key validation', () => {
|
||||
expect(validateImageKey('blog/abc.webp')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('image stats isolation', () => {
|
||||
it('scopes upload source counts to the selected user', () => {
|
||||
ensureDefaultBackends()
|
||||
const now = new Date().toISOString()
|
||||
const userA = insertUser({
|
||||
username: 'stats-user-a',
|
||||
passwordHash: 'hash-a',
|
||||
role: 'user',
|
||||
createdAt: now
|
||||
})
|
||||
const userB = insertUser({
|
||||
username: 'stats-user-b',
|
||||
passwordHash: 'hash-b',
|
||||
role: 'user',
|
||||
createdAt: now
|
||||
})
|
||||
|
||||
insertImageIndex({
|
||||
key: 'images/2026/10/stats-a.webp',
|
||||
backendId: 'local',
|
||||
userId: userA,
|
||||
originalName: 'stats-a.webp',
|
||||
contentType: 'image/webp',
|
||||
size: 1,
|
||||
uploadedAt: now
|
||||
})
|
||||
insertImageIndex({
|
||||
key: 'images/2026/10/stats-b.webp',
|
||||
backendId: 'local',
|
||||
userId: userB,
|
||||
originalName: 'stats-b.webp',
|
||||
contentType: 'image/webp',
|
||||
size: 1,
|
||||
uploadedAt: now
|
||||
})
|
||||
insertActivityLog({
|
||||
action: 'upload',
|
||||
key: 'images/2026/10/stats-a.webp',
|
||||
originalName: 'stats-a.webp',
|
||||
size: 1,
|
||||
contentType: 'image/webp',
|
||||
source: 'web',
|
||||
userId: userA
|
||||
})
|
||||
insertActivityLog({
|
||||
action: 'upload',
|
||||
key: 'images/2026/10/stats-b.webp',
|
||||
originalName: 'stats-b.webp',
|
||||
size: 1,
|
||||
contentType: 'image/webp',
|
||||
source: 'api',
|
||||
userId: userB
|
||||
})
|
||||
|
||||
expect(getMediaStats('image', userA).bySource).toEqual({ web: 1, api: 0 })
|
||||
expect(getMediaStats('image', userB).bySource).toEqual({ web: 0, api: 1 })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user