Skip to content

Commit f34a1b8

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 f34a1b8

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

mfr/providers/osf/provider.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import json
34
import hashlib
45
import logging
@@ -172,11 +173,23 @@ async def _fetch_download_url(self):
172173
self.download_url = self.url
173174
self.metrics.add('download_url.orig_type', 'wb_v1')
174175
else:
175-
self.metrics.add('download_url.orig_type', 'osf')
176+
normalized_url = None
177+
if re.compile(r'^/[a-z0-9]{5}/[^/]*', re.IGNORECASE).match(path):
178+
# In the past the OSF would redirect urls of the form https://osf.io/<file_guid>/ to
179+
# https://osf.io/download/<file_guid>/. It no longer does this, so MFR must detect
180+
# such urls and manually prepend /download/ to the path.
181+
self.metrics.add('download_url.orig_type', 'osf-preangular')
182+
temp_url = furl.furl(self.url)
183+
temp_url.path.segments = ['download'] + temp_url.path.segments
184+
normalized_url = temp_url.url
185+
else:
186+
self.metrics.add('download_url.orig_type', 'osf')
187+
normalized_url = self.url
188+
176189
# make request to osf, don't follow, store waterbutler download url
177190
request = await self._make_request(
178191
'GET',
179-
self.url,
192+
normalized_url,
180193
allow_redirects=False,
181194
headers={
182195
'Content-Type': 'application/json'
@@ -188,7 +201,7 @@ async def _fetch_download_url(self):
188201
if request.status != 302:
189202
raise exceptions.MetadataError(
190203
request.reason,
191-
metadata_url=self.url,
204+
metadata_url=normalized_url,
192205
provider=self.NAME,
193206
code=request.status,
194207
)

0 commit comments

Comments
 (0)