Added Fires page, collection and fire comments
This commit is contained in:
parent
3bf21c8caf
commit
40aedbfdfb
19 changed files with 290 additions and 66 deletions
|
|
@ -7,6 +7,7 @@ const firesCommonSchema = {
|
|||
ourid: LocationSchema,
|
||||
lat: Number,
|
||||
lon: Number,
|
||||
address: { type: String, optional: true },
|
||||
scan: Number,
|
||||
type: String,
|
||||
when: Date,
|
||||
|
|
|
|||
|
|
@ -6,23 +6,43 @@ import { check } from 'meteor/check';
|
|||
import urlEnc from '/imports/modules/url-encode';
|
||||
import { Promise } from 'meteor/promise';
|
||||
import FiresCollection from '../Fires';
|
||||
import NodeGeocoder from 'node-geocoder';
|
||||
import { gmapServerKey } from '/imports/startup/server/IPGeocoder';
|
||||
|
||||
function findFire(unsealed) {
|
||||
const fire = FiresCollection.find({ ourid: { type: 'Point', coordinates: [unsealed.lon, unsealed.lat] } });
|
||||
return fire;
|
||||
}
|
||||
|
||||
const options = {
|
||||
provider: 'google',
|
||||
// Optional depending on the providers
|
||||
httpAdapter: 'https', // Default
|
||||
apiKey: gmapServerKey, // for Mapquest, OpenCage, Google Premier
|
||||
formatter: null // 'gpx', 'string', ...
|
||||
};
|
||||
|
||||
const geocoder = NodeGeocoder(options);
|
||||
|
||||
Meteor.publish('fireFromHash', function fireFromHash(fireEnc) {
|
||||
check(fireEnc, String);
|
||||
try {
|
||||
// console.log(fireEnc);
|
||||
const unsealed = Promise.await(urlEnc.decrypt(fireEnc));
|
||||
const w = unsealed.when;
|
||||
// console.log(w);
|
||||
unsealed.when = new Date(w);
|
||||
// console.log(unsealed);
|
||||
FiresCollection.schema.validate(unsealed);
|
||||
const fire = findFire(unsealed);
|
||||
try {
|
||||
const rev = Promise.await(geocoder.reverse({ lat: unsealed.lat, lon: unsealed.lon }));
|
||||
if (rev[0]) {
|
||||
unsealed.address = rev[0].formattedAddress;
|
||||
}
|
||||
// console.log(unsealed.address);
|
||||
} catch (reve) {
|
||||
console.error(reve);
|
||||
}
|
||||
if (fire.count() === 0) {
|
||||
const result = FiresCollection.upsert({ ourid: unsealed.ourid }, { $set: unsealed }, { multi: false, upsert: true });
|
||||
console.log(JSON.stringify(result));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue