Skip to content

Commit

Permalink
give user signed url for activities geojson and client fetch gzipped …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
micheal-w-wells committed Oct 31, 2023
1 parent 064aea5 commit 8306286
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions api/src/models/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class ActivitySearchCriteria {
species_negative: string[];
species_treated: string[];
form_status: string[];
s3SignedUrlRequest?: boolean

jurisdiction: string[];

Expand All @@ -162,6 +163,7 @@ export class ActivitySearchCriteria {
//csv export stuff:
this.isCSV = (obj && obj.isCSV) || false;
this.CSVType = (obj && obj.CSVType) || null;
this.s3SignedUrlRequest = (obj && obj.s3SignedUrlRequest) || false;

this.page = (obj && obj.page && this.setPage(obj.page)) || 0;
this.limit = (obj && obj.limit && this.setLimit(obj.limit)) || SEARCH_LIMIT_MAX;
Expand Down
6 changes: 6 additions & 0 deletions api/src/paths/activities-lean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ActivitySearchCriteria } from '../models/activity';
import geoJSON_Feature_Schema from '../openapi/geojson-feature-doc.json';
import { getActivitiesSQL, deleteActivitiesSQL } from '../queries/activity-queries';
import { getLogger } from '../utils/logger';
import { getS3SignedURL } from '../utils/file-utils';

const defaultLog = getLogger('activity');

Expand Down Expand Up @@ -242,6 +243,11 @@ function getActivitiesBySearchFilterCriteria(): RequestHandler {
}

try {
if(sanitizedSearchCriteria.s3SignedUrlRequest)
{
const signedURL = await getS3SignedURL('activities_private_geojson.json')
return res.status(200).json({ signedURL: signedURL });
}
const sqlStatement: SQLStatement = getActivitiesSQL(sanitizedSearchCriteria, true, isAuth);

// Check for sql and role:
Expand Down
35 changes: 33 additions & 2 deletions app/src/state/sagas/map/online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,45 @@ const checkForErrors = (response: any, status?: any, url?: any) => {

//
export function* handle_ACTIVITIES_GEOJSON_GET_ONLINE(action) {

//get a signed url to the zipped file on s3:



const networkReturn = yield InvasivesAPI_Call(
'POST',
`/api/activities-lean/`,
action.payload.activitiesFilterCriteria
{...action.payload.activitiesFilterCriteria, s3SignedUrlRequest: true}
);

console.dir(networkReturn)
const signedURL = networkReturn.data.signedURL

//get the zipped file from the signed url:

let networkReturn2

try {

networkReturn2 = yield Http.request({
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip'
},
url: signedURL
});

}
catch(e) {
console.dir(e)
}

console.dir(networkReturn2)

let featureCollection = {
type: 'FeatureCollection',
features: networkReturn.data.result.rows.map((row) => {
features: networkReturn2.data.result.rows.map((row) => {
return row.geojson ? row.geojson : row;
})
};
Expand Down

0 comments on commit 8306286

Please sign in to comment.