mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-18 16:52:11 +00:00
Immich : un portrait déposé à la main remplace aussi le lien Immich
POST /trees/:id/persons/:personId/avatar lit immichPersonId de la personne et le remet à null quand une association existe ; l'entrée d'audit person_avatar_updated trace le retrait via payloadJson immichLinkRemoved. Sans cela, l'association survivait invisible en base après remplacement du portrait par un fichier. Test : l'envoi d'un fichier sur un portrait Immich efface l'association (échouait avant ce fix : immichPersonId absent de l'update) ; sans association, le champ n'est pas touché. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
1 parent
8803463ce4
commit
cf946be617
2 files changed
+71
No files matched your search
@@ -494,6 +494,7 @@ export const mediaRoutes: FastifyPluginAsync = async (app) => {
|
||||
select: {
|
||||
id: true,
|
||||
avatarPath: true,
|
||||
immichPersonId: true,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -554,6 +555,10 @@ export const mediaRoutes: FastifyPluginAsync = async (app) => {
|
||||
avatarPath: relativePath,
|
||||
avatarMimeType: prepared.mimeType,
|
||||
updatedBy: request.actor.userId,
|
||||
// Un portrait déposé à la main remplace aussi le lien Immich : sans cela, l'association
|
||||
// survivrait invisible en base (le graphe ne publie que l'origine du portrait) et ne
|
||||
// pourrait plus être retirée depuis l'interface.
|
||||
...(person.immichPersonId ? { immichPersonId: null } : {}),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -568,6 +573,7 @@ export const mediaRoutes: FastifyPluginAsync = async (app) => {
|
||||
action: 'person_avatar_updated',
|
||||
entityType: 'person',
|
||||
entityId: params.data.personId,
|
||||
...(person.immichPersonId ? { payloadJson: { immichLinkRemoved: true } } : {}),
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ const { prismaMock } = vi.hoisted(() => ({
|
||||
person: {
|
||||
findFirst: vi.fn(),
|
||||
update: vi.fn(),
|
||||
updateMany: vi.fn(),
|
||||
},
|
||||
treeMembership: {
|
||||
findUnique: vi.fn(),
|
||||
@@ -157,6 +158,7 @@ beforeEach(async () => {
|
||||
|
||||
prismaMock.person.findFirst.mockResolvedValue(null)
|
||||
prismaMock.person.update.mockResolvedValue({ id: 'person-1' })
|
||||
prismaMock.person.updateMany.mockResolvedValue({ count: 1 })
|
||||
prismaMock.auditLog.create.mockResolvedValue({ id: 'audit-1' })
|
||||
prismaMock.mediaItem.aggregate.mockResolvedValue({ _sum: { sizeBytes: 0 } })
|
||||
|
||||
@@ -787,3 +789,66 @@ describe('Immich integration: unassign', () => {
|
||||
await app.close()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Immich integration: manual avatar replacing an Immich portrait', () => {
|
||||
it('clears the association when a manual file overwrites the Immich portrait', async () => {
|
||||
const app = createApp()
|
||||
const token = await createUserToken(app)
|
||||
|
||||
const oldAvatarRelative = `tree-1/person-1/immich-${randomUUID()}.jpg`
|
||||
await writeFile(await absStoragePath(oldAvatarRelative), jpegBytes)
|
||||
prismaMock.person.findFirst.mockResolvedValue({ id: 'person-1', avatarPath: oldAvatarRelative, immichPersonId })
|
||||
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/trees/tree-1/persons/person-1/avatar',
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
payload: {
|
||||
fileName: 'portrait.jpg',
|
||||
mimeType: 'image/jpeg',
|
||||
sizeBytes: jpegBytes.length,
|
||||
dataBase64: jpegBytes.toString('base64'),
|
||||
},
|
||||
})
|
||||
|
||||
expect(response.statusCode).toBe(201)
|
||||
expect(response.json()).toEqual({ ok: true })
|
||||
|
||||
// Le portrait manuel remplace le fichier Immich et son association : sinon l'association
|
||||
// survivrait invisible en base, sans qu'aucune interface ne puisse la retirer.
|
||||
const updateData = prismaMock.person.updateMany.mock.calls[0][0].data
|
||||
expect(updateData.immichPersonId).toBe(null)
|
||||
expect(updateData.avatarPath).toEqual(expect.any(String))
|
||||
expect(updateData.avatarPath).not.toContain('immich-')
|
||||
|
||||
// Le retrait du lien apparaît dans le journal d'audit de l'envoi.
|
||||
const auditData = prismaMock.auditLog.create.mock.calls[0][0].data
|
||||
expect(auditData.action).toBe('person_avatar_updated')
|
||||
expect(auditData.payloadJson).toEqual({ immichLinkRemoved: true })
|
||||
await app.close()
|
||||
})
|
||||
|
||||
it('does not touch the association field when there is none', async () => {
|
||||
const app = createApp()
|
||||
const token = await createUserToken(app)
|
||||
|
||||
prismaMock.person.findFirst.mockResolvedValue({ id: 'person-1', avatarPath: null, immichPersonId: null })
|
||||
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/trees/tree-1/persons/person-1/avatar',
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
payload: {
|
||||
fileName: 'portrait.jpg',
|
||||
mimeType: 'image/jpeg',
|
||||
sizeBytes: jpegBytes.length,
|
||||
dataBase64: jpegBytes.toString('base64'),
|
||||
},
|
||||
})
|
||||
|
||||
expect(response.statusCode).toBe(201)
|
||||
const updateData = prismaMock.person.updateMany.mock.calls[0][0].data
|
||||
expect(updateData).not.toHaveProperty('immichPersonId')
|
||||
await app.close()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user