feat: implement S3 attachments and presigned uploads

This commit is contained in:
sinveria
2026-11-10 12:08:50 +03:00
parent aaa834e412
commit d96d4a2836
50 changed files with 3138 additions and 72 deletions
+20 -6
View File
@@ -182,13 +182,27 @@ class Client:
headers = {'Idempotency-Key':key or uuid.uuid4().hex} if LAB>=3 else {}
return self.call('POST','/api/v1/chats/'+chat['id']+'/messages',201,actor=actor,body=body,headers=headers,schema='Message')
def attachment(self, actor, chat):
def attachment(self, actor, chat, include_instance=False):
content = (ROOT / 'tests/fixtures/sample.png').read_bytes()
att = self.call('POST','/api/v1/chats/'+chat['id']+'/attachments?filename=sample.png',201 if LAB==4 else 202,actor=actor,raw=content,headers={'Content-Type':'image/png'},schema='Attachment')['json']
check(att['status']==('ready' if LAB==4 else 'queued'),'incorrect upload status')
check(att['chat_id']==chat['id'] and att['owner_id']==actor['id'],'attachment ownership mismatch')
check(att['sha256']==hashlib.sha256(content).hexdigest() and att['size_bytes']==len(content),'original checksum/size mismatch')
return att,content
response = self.call(
'POST',
'/api/v1/chats/' + chat['id'] + '/attachments?filename=sample.png',
201 if LAB == 4 else 202,
actor=actor,
raw=content,
headers={'Content-Type': 'image/png'},
schema='Attachment'
)
att = response['json']
check(att['status'] == ('ready' if LAB == 4 else 'queued'), 'incorrect upload status')
check(att['chat_id'] == chat['id'] and att['owner_id'] == actor['id'], 'attachment ownership mismatch')
check(
att['sha256'] == hashlib.sha256(content).hexdigest()
and att['size_bytes'] == len(content),
'original checksum/size mismatch'
)
instance_id = response['headers'].get('X-Instance-Id', '')
return (att, content, instance_id) if include_instance else (att, content)
def wait_ready(self, actor, att, wait_seconds=60):
deadline = time.monotonic()+wait_seconds