Skip to content

Commit a86667f

Browse files
committed
rewrite some osf provider urls
* File urls of the form osf.io/<guid>/ used to redirect to a download url if <guid> pointed to a file. They no longer do. Now if MFR sees a url matching that pattern, it will add a /download/ path segment before the guid that *will* redirect.
1 parent 93a90ac commit a86667f

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

mfr/providers/osf/provider.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,21 @@ async def _fetch_download_url(self):
172172
self.download_url = self.url
173173
self.metrics.add('download_url.orig_type', 'wb_v1')
174174
else:
175-
self.metrics.add('download_url.orig_type', 'osf')
175+
yum_url = None
176+
import re
177+
if re.compile(r'^/[a-z0-9]{5}/[^/]*', re.IGNORECASE).match(path):
178+
self.metrics.add('download_url.orig_type', 'osf-preangular')
179+
berch_url = furl.furl(self.url)
180+
berch_url.path.segments = ['download'] + berch_url.path.segments
181+
yum_url = berch_url.url
182+
else:
183+
self.metrics.add('download_url.orig_type', 'osf')
184+
yum_url = self.url
185+
176186
# make request to osf, don't follow, store waterbutler download url
177187
request = await self._make_request(
178188
'GET',
179-
self.url,
189+
yum_url,
180190
allow_redirects=False,
181191
headers={
182192
'Content-Type': 'application/json'
@@ -188,7 +198,7 @@ async def _fetch_download_url(self):
188198
if request.status != 302:
189199
raise exceptions.MetadataError(
190200
request.reason,
191-
metadata_url=self.url,
201+
metadata_url=yum_url,
192202
provider=self.NAME,
193203
code=request.status,
194204
)

0 commit comments

Comments
 (0)