feat: implement S3 attachments and presigned uploads
This commit is contained in:
+20
-6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user