Skip to content

Commit

Permalink
Merge pull request #27 from catalogueglobal/fix-download-merged-feed
Browse files Browse the repository at this point in the history
fix(fix download merged project feed to use job monitoring)
  • Loading branch information
abyrd committed Sep 21, 2017
2 parents 4223eba + df48059 commit becbe92
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
58 changes: 41 additions & 17 deletions lib/manager/actions/projects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { secureFetch } from '../../common/actions'
import { getConfigProperty } from '../../common/util/config'
import { fetchProjectFeeds } from './feeds'
import { updateGtfsFilter } from '../../gtfs/actions/filter'
import { downloadS3Key } from '../../manager/actions/versions'
import { setErrorMessage, startJobMonitor } from './status'
import { fetchProjectFeeds } from './feeds'
import {getActiveProject} from '../selectors'
// Bulk Project Actions

Expand Down Expand Up @@ -267,21 +269,43 @@ export function saveProject (props) {

export function downloadFeedForProject (project) {
return function (dispatch, getState) {
const url = `/api/manager/public/project/${project.id}/download`
window.location.assign(url)
// return dispatch(secureFetch(url))
// .then(response => {
// console.log(response.body)
// return response.body
// })
// .then(result => {
// // window.location.assign(`/api/manager/downloadfeed/${result.id}`)
// console.log(result)
// var zipName = 'download.zip';
// var a = document.createElement('a');
// a.href = "data:application/zip;base64," + result;
// a.download = zipName;
// a.click();
// })
const url = `/api/manager/secure/project/${project.id}/download`
// window.location.assign(url)
return dispatch(secureFetch(url))
.then(res => {
if (res.status >= 400) {
dispatch(setErrorMessage('Error merging project feeds'))
} else {
dispatch(startJobMonitor())
}
return res.json()
})
.then(result => {
// window.location.assign(`/api/manager/downloadfeed/${result.id}`)
console.log(result)
// var zipName = 'download.zip';
// var a = document.createElement('a');
// a.href = "data:application/zip;base64," + result;
// a.download = zipName;
// a.click();
})
}
}

// Download a GTFS file for a FeedVersion
export function downloadMergedFeedViaToken (project, isPublic, prefix) {
return function (dispatch, getState) {
const route = isPublic ? 'public' : 'secure'
const url = `/api/manager/${route}/project/${project.id}/downloadtoken`
dispatch(secureFetch(url))
.then(response => response.json())
.then(credentials => {
if (getConfigProperty('application.data.use_s3_storage')) {
dispatch(downloadS3Key(credentials, `${project.id}.zip`, 'project'))
} else {
// use token to download feed
window.location.assign(`/api/manager/downloadprojectfeed/${credentials.id}`)
}
})
}
}
10 changes: 7 additions & 3 deletions lib/manager/actions/status.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { secureFetch } from '../../common/actions'
import { fetchFeedSource } from './feeds'
import { fetchSnapshots } from '../../editor/actions/snapshots'
import {secureFetch} from '../../common/actions'
import {fetchFeedSource} from './feeds'
import {downloadMergedFeedViaToken} from './projects'
import {fetchSnapshots} from '../../editor/actions/snapshots'

export function setErrorMessage (message, action) {
return {
Expand Down Expand Up @@ -147,6 +148,9 @@ export function handleFinishedJob (job) {
case 'CREATE_FEEDVERSION_FROM_SNAPSHOT':
dispatch(fetchFeedSource(job.feedVersion.feedSource.id, true, true))
break
case 'MERGE_PROJECT_FEEDS':
dispatch(downloadMergedFeedViaToken(job.project, false, 'project'))
break
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/manager/actions/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ export function fetchFeedVersionIsochrones (feedVersion, fromLat, fromLon, toLat
}

// Download a GTFS file for a FeedVersion
export function downloadFeedViaToken (feedVersion, isPublic) {
export function downloadFeedViaToken (feedVersion, isPublic, prefix = 'gtfs') {
return function (dispatch, getState) {
const route = isPublic ? 'public' : 'secure'
const url = `/api/manager/${route}/feedversion/${feedVersion.id}/downloadtoken`
dispatch(secureFetch(url))
.then(response => response.json())
.then(credentials => {
if (getConfigProperty('application.data.use_s3_storage')) {
dispatch(downloadS3Key(credentials, `${feedVersion.id}`, 'gtfs'))
dispatch(downloadS3Key(credentials, `${feedVersion.id}`, prefix))
} else {
// use token to download feed
window.location.assign(`/api/manager/downloadfeed/${credentials.id}`)
Expand Down

0 comments on commit becbe92

Please sign in to comment.