nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

etomesto.js (1123B)


      1 import urlViaCorsProxy from '~/lib/CORSProxy';
      2 import BaseService from './baseService';
      3 import parseGpx from '../parsers/gpx';
      4 
      5 class Etomesto extends BaseService {
      6     urlRe = /^https?:\/\/(?:www\.)?etomesto\.ru\/track([a-z0-9]+)/u;
      7 
      8     getTrackId() {
      9         const m = this.urlRe.exec(this.origUrl);
     10         return m[1];
     11     }
     12 
     13     isOurUrl() {
     14         return this.urlRe.test(this.origUrl);
     15     }
     16 
     17     requestOptions() {
     18         const trackId = this.getTrackId();
     19         return [{
     20             url: urlViaCorsProxy(`http://www.etomesto.ru/save/${trackId}.gpx`),
     21             options: {
     22                 responseType: 'binarystring',
     23                 isResponseSuccess: (xhr) => (
     24                     xhr.status === 200 &&
     25                     !xhr.responseBinaryText.startsWith('ERROR'))
     26             }
     27         }];
     28     }
     29 
     30     parseResponse(responses) {
     31         const trackId = this.getTrackId();
     32         const response = responses[0];
     33         const name = `Etomesto track ${trackId}`;
     34         return parseGpx(response.responseBinaryText, name, true) || [{name: name, error: 'UNSUPPORTED'}];
     35     }
     36 }
     37 
     38 export default Etomesto;