backend: auth bug fix

This commit is contained in:
muerwre 2018-11-30 15:15:52 +07:00
parent d932fcb287
commit c92f84c24f
7 changed files with 12 additions and 81 deletions

View file

@ -2,7 +2,6 @@ export const SERVER = 'http://alpha-map.vault48.org';
export const TEST = 'http://localhost:3000';
export const API = {
COMPOSE: `${SERVER}/engine/composerOrchid.php`,
GET_GUEST: `${TEST}/auth`,
CHECK_TOKEN: `${TEST}/auth`,
GET_MAP: `${TEST}/route`,

View file

@ -3,7 +3,6 @@ import { Poly } from '$modules/Poly';
import { MODES } from '$constants/modes';
import { Stickers } from '$modules/Stickers';
import { Router } from '$modules/Router';
import { Shotter } from '$modules/Shotter';
import { DEFAULT_LOGO } from '$constants/logos';
import { parseStickerAngle, parseStickerStyle } from '$utils/import';
@ -42,7 +41,7 @@ export class Editor {
this.router = new Router({
map, lockMapClicks, setRouterPoints: this.setRouterPoints, changeMode, pushPolyPoints
});
this.shotter = new Shotter({ map });
// this.shotter = new Shotter({ map });
this.switches = {
[MODES.POLY]: {
@ -54,9 +53,6 @@ export class Editor {
toggle: this.clearMode,
start: this.routerSetStart,
},
[MODES.SHOTTER]: {
start: this.shotter.makeShot,
},
[MODES.STICKERS]: {
toggle: this.clearSticker,
},

View file

@ -1,62 +0,0 @@
import axios from 'axios';
import { getMergedImage } from '$utils/api';
export class Shotter {
constructor({ map }) {
this.tiles = [];
this.tilesLoaded = 0;
this.map = map;
}
latLngToTile = latlng => {
const z = this.map.getZoom();
const x = parseInt(Math.floor(((latlng.lng + 180) / 360) * (1 << z)), 10);
const y = parseInt(Math.floor((1 - (Math.log(Math.tan((latlng.lat * Math.PI) / 180)
+ 1 / Math.cos((latlng.lat * Math.PI) / 180)) / Math.PI)) / 2 * (1 << z)), 10);
return { x, y, z };
};
tileToLatLng = point => {
const z = this.map.getZoom();
const lng = (((point.x / (2 ** z)) * 360) - 180);
const n = Math.PI - ((2 * Math.PI * point.y) / (2 ** z));
const lat = (180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))));
return { lat, lng };
};
getTilePlacement() {
const { innerHeight, innerWidth } = window;
const { _southWest, _northEast } = this.map.getBounds();
const sw = this.latLngToTile(_southWest);
const ne = this.latLngToTile(_northEast);
const zsw = this.tileToLatLng(sw);
const zne = this.tileToLatLng(ne);
const rsw = this.map.latLngToContainerPoint(zsw);
const msw = this.map.latLngToContainerPoint(_southWest);
return {
min_x: sw.x,
min_y: ne.y,
max_x: ne.x,
max_y: sw.y,
sh_x: (rsw.x - msw.x),
sh_y: ((innerHeight + rsw.y) - msw.y),
size: 256,
width: innerWidth,
height: innerHeight,
zoom: this.map.getZoom(),
provider: 'dgis',
};
}
makeShot = () => {
const placement = this.getTilePlacement();
getMergedImage(placement);
}
}

View file

@ -2,22 +2,12 @@ import axios from 'axios/index';
import { API } from '$constants/api';
const report = console.warn;
export const checkUserToken = ({ id, token }) => axios.get(API.CHECK_TOKEN, {
params: { id, token }
}).then(result => (result && result.data && { ...result.data, id, token }));
export const getGuestToken = () => axios.get(API.GET_GUEST).then(result => (result && result.data));
export const getMergedImage = ({ placement, callback }) => (
axios.get(API.COMPOSE, {
params: { placement }
})
.then(callback)
.catch(report)
);
export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, {
params: { name }
}).then(result => (result && result.data));