Skip to content

Commit 0f71a0f

Browse files
committed
tests work
1 parent ed655f9 commit 0f71a0f

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

invenio_records_resources/services/files/results.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from ..base import ServiceListResult
1313
from ..records.results import RecordItem
14+
from ...proxies import current_transfer_registry
1415

1516

1617
class FileItem(RecordItem):
@@ -92,8 +93,22 @@ def entries(self):
9293
identity=self._identity,
9394
),
9495
)
96+
97+
# create links
9598
if self._links_item_tpl:
96-
projection["links"] = self._links_item_tpl.expand(self._identity, entry)
99+
links = self._links_item_tpl.expand(self._identity, entry)
100+
else:
101+
links = {}
102+
103+
# add transfer links
104+
transfer = current_transfer_registry.get_transfer(file_record=entry)
105+
for k, v in transfer.expand_links(self._identity, entry).items():
106+
if v is not None:
107+
links[k] = v
108+
else:
109+
links.pop(k, None)
110+
111+
projection["links"] = links
97112

98113
yield projection
99114

invenio_records_resources/services/files/schema.py

+3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class Meta:
113113

114114
@post_dump(pass_many=False, pass_original=True)
115115
def _dump_transfer_data(self, data, original_data, **kwargs):
116+
"""
117+
Enriches the dumped data with the transfer data.
118+
"""
116119
transfer = current_transfer_registry.get_transfer(file_record=original_data)
117120
data |= transfer.transfer_data
118121
return data

invenio_records_resources/services/files/transfer/base.py

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ def transfer_data(self):
9494
'status': self.status,
9595
}
9696

97+
def expand_links(self, identity, file_record):
98+
"""Expand links."""
99+
return {}
100+
97101
# @abstractmethod
98102
# def read_file_content(self, record, file_metadata):
99103
# """Read a file content."""

invenio_records_resources/services/files/transfer/registry.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from typing import Dict, Type
22

3-
from invenio_records_resources.services.files.transfer.base import BaseTransfer
3+
from .base import BaseTransfer
4+
from .types import LOCAL_TRANSFER_TYPE
45

56

67
class TransferRegistry:
78
"""
89
A registry for transfer providers.
910
"""
1011

11-
DEFAULT_TRANSFER_TYPE = "L"
12+
DEFAULT_TRANSFER_TYPE = LOCAL_TRANSFER_TYPE
1213
"""
1314
Default transfer type if no storage class is provided in file upload initiation.
1415
"""
@@ -34,7 +35,6 @@ def get_transfer(self, *, transfer_type=None, file_record=None, **kwargs):
3435
if transfer_type is None:
3536
if file_record is not None and file_record.file is not None:
3637
transfer_type = file_record.file.storage_class
37-
else:
38-
transfer_type = self.DEFAULT_TRANSFER_TYPE
3938

40-
return self._transfers[transfer_type](file_record=file_record, **kwargs)
39+
return self._transfers[transfer_type or self.DEFAULT_TRANSFER_TYPE](
40+
file_record=file_record, **kwargs)

0 commit comments

Comments
 (0)