feat(transcode): add 3D asset support and turntable viewer

This commit is contained in:
yiling
2026-10-08 23:12:09 +08:00
parent 4b1b64fe2b
commit 06ea4eed78
50 changed files with 3645 additions and 25 deletions
+110
View File
@@ -52,6 +52,14 @@ vi.mock('@shumai/core/src/auditLog/auditLog', () => ({
},
}))
vi.mock('@shumai/core/src/turntable/turntable', () => ({
turntableService: {
getSettings: vi.fn(),
updateSettings: vi.fn(),
testConnection: vi.fn(),
},
}))
describe('team api', () => {
const app = new Hono().use('*', authMiddleware).route('/', teamRoute)
let mockCreateTeam: any // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -638,5 +646,107 @@ describe('team api', () => {
}),
)
})
it('GET /teams/:teamId/turntable-settings returns turntable settings', async () => {
const { turntableService } = await import('@shumai/core/src/turntable/turntable')
vi.mocked(turntableService.getSettings).mockResolvedValue({
url: 'http://localhost:3001',
username: 'user',
hasPassword: true,
isEnvConfigured: false,
})
const res = await app.request('/teams/t1/turntable-settings')
expect(res.status).toBe(200)
const data = await res.json()
expect(data).toEqual({
url: 'http://localhost:3001',
username: 'user',
hasPassword: true,
isEnvConfigured: false,
})
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
permission: Permission.Read,
type: ResourceType.Team,
id: 't1',
}),
)
})
it('PUT /teams/:teamId/turntable-settings updates settings when not env configured', async () => {
const { turntableService } = await import('@shumai/core/src/turntable/turntable')
vi.mocked(turntableService.updateSettings).mockResolvedValue({
url: 'http://custom:3001',
username: 'newuser',
hasPassword: true,
isEnvConfigured: false,
})
const res = await app.request('/teams/t1/turntable-settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'http://custom:3001',
username: 'newuser',
password: 'secretpassword',
}),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.url).toBe('http://custom:3001')
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
permission: Permission.Admin,
type: ResourceType.Team,
id: 't1',
}),
)
})
it('PUT /teams/:teamId/turntable-settings returns 400 when env configured', async () => {
const { turntableService } = await import('@shumai/core/src/turntable/turntable')
vi.mocked(turntableService.updateSettings).mockRejectedValue(
new Error(
'Turntable settings are configured via environment variables and cannot be edited',
),
)
const res = await app.request('/teams/t1/turntable-settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'http://custom:3001',
}),
})
expect(res.status).toBe(400)
const data = await res.json()
expect(data.message).toContain('configured via environment variables')
})
it('POST /teams/:teamId/turntable-settings/test tests connection', async () => {
const { turntableService } = await import('@shumai/core/src/turntable/turntable')
vi.mocked(turntableService.testConnection).mockResolvedValue({
ok: true,
version: '1.0.0',
blender: '5.2.0',
})
const res = await app.request('/teams/t1/turntable-settings/test', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'http://custom:3001',
}),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.ok).toBe(true)
expect(data.blender).toBe('5.2.0')
})
})
})
+59
View File
@@ -10,6 +10,7 @@ import {
updateTeamSettingsRequestSchema,
listMembersQuerySchema,
updateSandboxSettingsRequestSchema,
updateTurntableSettingsRequestSchema,
updateMeRequestSchema,
updateTeamMemberRoleRequestSchema,
createApiTokenRequestSchema,
@@ -23,6 +24,7 @@ import {
import { apiTokenService } from '@shumai/core/src/user/api-token'
import { aiUsageService } from '@shumai/core/src/ai-usage/ai-usage'
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
import { turntableService } from '@shumai/core/src/turntable/turntable'
import { NotificationType } from '@shumai/db'
import type { Prisma } from '@shumai/db'
@@ -265,6 +267,63 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.json(sandbox)
},
)
.get('/teams/:teamId/turntable-settings', async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Team,
id: teamId,
})
const settings = await turntableService.getSettings(teamId)
return c.json(settings)
})
.put(
'/teams/:teamId/turntable-settings',
zValidator('json', updateTurntableSettingsRequestSchema),
async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
try {
const settings = await turntableService.updateSettings(teamId, req)
return c.json(settings)
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
return c.json({ message }, 400)
}
},
)
.post(
'/teams/:teamId/turntable-settings/test',
zValidator('json', updateTurntableSettingsRequestSchema.partial()),
async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
const res = await turntableService.testConnection(req, teamId)
return c.json(res)
},
)
.get('/teams/:teamId/user-metadata', async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')