DatabaseDownload no longer uses .inspect(), refs #420

This commit is contained in:
Simon Willison 2019-03-31 19:04:17 -07:00
commit 468c6fd953
3 changed files with 29 additions and 5 deletions

View file

@ -43,7 +43,14 @@ class DatabaseDownload(BaseView):
async def view_get(self, request, database, hash, correct_hash_present, **kwargs):
if not self.ds.config("allow_download"):
raise DatasetteError("Database download is forbidden", status=403)
filepath = self.ds.inspect()[database]["file"]
if database not in self.ds.databases:
raise DatasetteError("Invalid database", status=404)
db = self.ds.databases[database]
if db.is_memory:
raise DatasetteError("Cannot download :memory: database", status=404)
if not db.path:
raise DatasetteError("Cannot download database", status=404)
filepath = db.path
return await response.file_stream(
filepath,
filename=os.path.basename(filepath),