Added Fires page, collection and fire comments

This commit is contained in:
vjrj 2018-01-17 18:23:32 +01:00
parent 3bf21c8caf
commit 40aedbfdfb
19 changed files with 290 additions and 66 deletions

View file

@ -7,6 +7,7 @@ const firesCommonSchema = {
ourid: LocationSchema,
lat: Number,
lon: Number,
address: { type: String, optional: true },
scan: Number,
type: String,
when: Date,

View file

@ -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));