Skip to content

Commit

Permalink
refactor: simplify basemap downloads directly from s3
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jan 8, 2024
1 parent e9ede9b commit 8562168
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 48 deletions.
14 changes: 1 addition & 13 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,19 +1062,7 @@ async def download_tiles(tile_id: int, db: Session = Depends(database.get_db)):
.first()
)
log.info(f"User requested download for tiles: {tiles_path.path}")

project_id = tiles_path.project_id
project = await project_crud.get_project(db, project_id)
project_name = project.project_name_prefix
filename = Path(tiles_path.path).name.replace(
f"{project_id}_", f"{project_name.replace(' ', '_')}_"
)
log.debug(f"Sending tile archive to user: {filename}")

return FileResponse(
tiles_path.path,
headers={"Content-Disposition": f'attachment; filename="{filename}"'},
)
return RedirectResponse(tiles_path.path)


@router.get("/boundary_in_osm/{project_id}/")
Expand Down
28 changes: 0 additions & 28 deletions src/frontend/src/api/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,34 +160,6 @@ export const GenerateProjectTiles = (url, payload) => {
};
};

export const DownloadTile = (url, payload) => {
return async (dispatch) => {
dispatch(ProjectActions.SetDownloadTileLoading({ type: payload, loading: true }));

const getDownloadTile = async (url, payload) => {
try {
const response = await CoreModules.axios.get(url, {
responseType: 'blob',
});

// Get filename from content-disposition header
const filename = response.headers['content-disposition'].split('filename=')[1];

var a = document.createElement('a');
a.href = window.URL.createObjectURL(response.data);
a.download = filename;
a.click();
dispatch(ProjectActions.SetDownloadTileLoading({ type: payload, loading: false }));
} catch (error) {
dispatch(ProjectActions.SetDownloadTileLoading({ type: payload, loading: false }));
} finally {
dispatch(ProjectActions.SetDownloadTileLoading({ type: payload, loading: false }));
}
};
await getDownloadTile(url, payload);
};
};

export const GetProjectDashboard = (url) => {
return async (dispatch) => {
const getProjectDashboard = async (url) => {
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/components/GenerateBasemap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import CoreModules from '../shared/CoreModules';
import AssetModules from '../shared/AssetModules';
import environment from '../environment';
import { DownloadTile, GenerateProjectTiles, GetTilesList } from '../api/Project';
import { GenerateProjectTiles, GetTilesList } from '../api/Project';

const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectInfo }) => {
const dispatch = CoreModules.useAppDispatch();
Expand All @@ -25,8 +25,8 @@ const GenerateBasemap = ({ setToggleGenerateModal, toggleGenerateModal, projectI
padding: '16px 32px 24px 32px',
maxWidth: '1000px',
});
const downloadBasemap = (tileId) => {
dispatch(DownloadTile(`${import.meta.env.VITE_API_URL}/projects/download_tiles/?tile_id=${tileId}`, projectInfo));
const downloadBasemap = async (tileId) => {
window.open(`${import.meta.env.VITE_API_URL}/projects/download_tiles/?tile_id=${tileId}`, '_blank');
};

const getTilesList = () => {
Expand Down
4 changes: 0 additions & 4 deletions src/frontend/src/store/slices/ProjectSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const ProjectSlice = createSlice({
generateProjectTilesLoading: false,
tilesList: [],
tilesListLoading: false,
downloadTilesLoading: false,
downloadDataExtractLoading: false,
taskModalStatus: false,
mobileFooterSelection: 'explore',
Expand Down Expand Up @@ -66,9 +65,6 @@ const ProjectSlice = createSlice({
SetTilesListLoading(state, action) {
state.tilesListLoading = action.payload;
},
SetDownloadTileLoading(state, action) {
state.downloadTilesLoading = action.payload;
},
SetDownloadDataExtractLoading(state, action) {
state.downloadDataExtractLoading = action.payload;
},
Expand Down

0 comments on commit 8562168

Please sign in to comment.