fix: the folders' download links last an hour, and one that ran out is fetched again quietly
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 7m49s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m8s
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 7m49s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m8s
The folders download a whole list of files one after another, from links made when the list was asked for, valid 5 minutes. With films of 10 m the last ones began after that and failed with "erro 403": a red error, a Sentry report, and only the next pass got new links. The folders' and hot folder's links now last an hour (customer downloads keep 5 minutes), and an expired link waits for the next pass like a dropped network. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -232,7 +232,7 @@ class ObjectStorage(Protocol):
|
||||
def part_url(self, key: str, upload_id: str, part: int, size: int) -> str: ...
|
||||
def complete(self, key: str, upload_id: str, parts: list): ...
|
||||
def size(self, key: str) -> int: ...
|
||||
def download(self, key: str, name: str) -> str: ...
|
||||
def download(self, key: str, name: str, expires: int = 300) -> str: ...
|
||||
def fetch(self, key: str, path: str): ...
|
||||
def store(self, key: str, path: str, content_type: str): ...
|
||||
def health(self): ...
|
||||
@@ -299,12 +299,12 @@ class LocalS3Storage:
|
||||
"""Upload a file the service generated itself, such as a print file."""
|
||||
self.patient.upload_file(path, self.bucket, key, ExtraArgs={'ContentType': content_type})
|
||||
|
||||
def download(self, key, name):
|
||||
def download(self, key, name, expires=300):
|
||||
from urllib.parse import quote
|
||||
return self.public.generate_presigned_url('get_object', Params={
|
||||
'Bucket': self.bucket, 'Key': key,
|
||||
'ResponseContentDisposition': "attachment; filename*=UTF-8''" + quote(name, safe=''),
|
||||
'ResponseContentType': 'application/octet-stream'}, ExpiresIn=300)
|
||||
'ResponseContentType': 'application/octet-stream'}, ExpiresIn=expires)
|
||||
|
||||
def view(self, key, content_type, expires=3600):
|
||||
"""A link to show an object in the page, not download it: the Kanban's
|
||||
|
||||
@@ -16,6 +16,10 @@ from ...scanning import require_clean
|
||||
from .common import FINAL_OK
|
||||
|
||||
router = APIRouter()
|
||||
# The folders download a whole list of files, one after another, from links
|
||||
# made when the list was asked for: with films of 10 m, 5 minutes ran out
|
||||
# before the last ones began (erro 403). Only the team's computers see them.
|
||||
FOLDER_LINK_SECONDS = 3600
|
||||
|
||||
def named_files(rows):
|
||||
"""Each file named after its order and item, so a folder of them stays
|
||||
@@ -39,7 +43,7 @@ def named_files(rows):
|
||||
names.add(name)
|
||||
files.append({'order': str(row['order_id']), 'state': row['state'], 'number': row['number'],
|
||||
'item': row['item_index'] + 1, 'name': name, 'upload_id': str(row['upload_id']),
|
||||
'url': storage.download(row['object_key'], name)})
|
||||
'url': storage.download(row['object_key'], name, FOLDER_LINK_SECONDS)})
|
||||
return files
|
||||
|
||||
|
||||
@@ -163,7 +167,7 @@ def queue_hot(user=Depends(can('print'))):
|
||||
watched = hotfolder.watched(c)
|
||||
return {'folder': hotfolder.PRINTING_FOLDER,
|
||||
'write': [{'id': r['id'], 'order': str(r['order_id']), 'folder': r['folder'], 'name': r['name'],
|
||||
'url': storage.download(keys[str(r['upload_id'])], r['name'])} for r in due],
|
||||
'url': storage.download(keys[str(r['upload_id'])], r['name'], FOLDER_LINK_SECONDS)} for r in due],
|
||||
'watch': [{'id': r['id'], 'order': str(r['order_id']), 'folder': r['folder'], 'name': r['name']}
|
||||
for r in watched if r['state'] == 'written'],
|
||||
'withdraw': [{'id': r['id'], 'order': str(r['order_id']), 'folder': r['folder'], 'name': r['name']}
|
||||
|
||||
@@ -155,6 +155,9 @@ def run():
|
||||
mine = [f for f in early['files'] if f['order'] == oid]
|
||||
assert [(f['upload_id'], f['state']) for f in mine] == [(str(row['upload_id']), 'rec')], early['files']
|
||||
assert mine[0]['name'].startswith('DTF-%d-item-1' % order['number']) and early['states'] == {oid: 'rec'}
|
||||
# The folders download a whole list one file after another: an hour's link,
|
||||
# not the 5 minutes that ran out before the last ones began.
|
||||
assert 'X-Amz-Expires=3600' in mine[0]['url'], mine[0]['url']
|
||||
late = client.call('/operator/queue/folder', {'early': False, 'held': []}, operator=True)
|
||||
assert not [f for f in late['files'] if f['order'] == oid] and late['states'] == {}
|
||||
client.call('/operator/queue/folder', {'early': True, 'held': []}, expected=401)
|
||||
|
||||
@@ -568,6 +568,9 @@ async function fetchFile(url,options){
|
||||
}
|
||||
async function fetchInto(dir,file,watched=false){
|
||||
const r=await fetchFile(file.url,{referrerPolicy:'no-referrer'});
|
||||
// A link that ran out while the files before it were downloading: the next
|
||||
// pass asks for a new one, as for a network that dropped.
|
||||
if(r.status===403){const e=new Error('o link de '+file.name+' venceu antes do download.');e.unreachable=true;throw e;}
|
||||
if(!r.ok||!r.body)throw new Error('não foi possível baixar '+file.name+' (erro '+r.status+').');
|
||||
await writeWhole(dir,file.name,r,watched);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user