Skip to content

Commit

Permalink
+ ReCaptch ativo
Browse files Browse the repository at this point in the history
+ Menssagens de upload
  • Loading branch information
JamesCodesUFG committed Feb 3, 2025
1 parent af90aa3 commit 12e34dc
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 99 deletions.
72 changes: 5 additions & 67 deletions client/src/app/@core/components/ol-map/ol-map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
* Angular imports.
*/
import { Component, AfterViewInit } from '@angular/core';
import { ElementRef, ChangeDetectorRef } from '@angular/core';
import { ElementRef } from '@angular/core';

/**
* OpenLayers imports.
*/
import Map from 'ol/Map';
import View from 'ol/View';
import * as Proj from 'ol/proj';
import { defaults as defaultInteractions } from 'ol/interaction';
import { defaults as defaultControls, FullScreen } from 'ol/control';
import { MousePosition, ScaleLine, Zoom } from 'ol/control';
import { Coordinate, createStringXY } from 'ol/coordinate';
import BaseLayer from 'ol/layer/Base';
import { FullScreen } from 'ol/control';
import { ScaleLine, Zoom } from 'ol/control';
import { MapService } from '@core/services/map.service';
import { MapEvent } from 'ol';

export const DEFAULT_HEIGHT = '100vh';
export const DEFAULT_WIDTH = '100%';
Expand All @@ -33,19 +26,18 @@ export const ZOOM_LEVEL = 4.6;
styleUrls: ['./ol-map.component.scss'],
})
export class OlMapComponent implements AfterViewInit {
private layersToFilter: string[] = ['layertype', 'swipe-layer'];

constructor(
private mapService: MapService,
private elementRef: ElementRef,
private cdRef: ChangeDetectorRef
) {}

ngAfterViewInit(): void {
const self = this;

this.setSize();

console.log(this.mapService.map)

this.mapService.map.setTarget('map')

this.setControlls();
Expand All @@ -68,50 +60,6 @@ export class OlMapComponent implements AfterViewInit {
this.mapService.map.addControl(new Zoom());
}

private setOnMoveEvent(): void {
const self = this;

this.mapService.map.on('moveend', function (event: MapEvent) {
self.mapService.map.getLayers().forEach((layer: any) => {
let descriptorType = layer.getProperties().descriptorType;

if (descriptorType === null) return;

if (
self.layersToFilter.includes(layer.get('type')) &&
layer.getVisible() === true &&
typeof descriptorType.download !== 'undefined'
) {
if (typeof descriptorType.download.layerTypeName !== 'undefined') {
let complexLayer = descriptorType.download.layerTypeName;
let singleLayer = descriptorType.valueType;

let soucer = layer.getSource();
let urls = soucer.urls;
let urlNow = new URLSearchParams(urls[0].split('?')[1]).get(
'layers'
);

if (self.mapService.isZoomOnLimit() && complexLayer !== urlNow) {
let newUrl = urls.map((url: any) => {
return url.replace(singleLayer, complexLayer);
});
soucer.setUrls(newUrl);
soucer.refresh();
} else if (!self.mapService.isZoomOnLimit() && singleLayer !== urlNow) {
let newUrl = urls.map((url: any) => {
return url.replace(complexLayer, singleLayer);
});

soucer.setUrls(newUrl);
soucer.refresh();
}
}
}
});
});
}

private setSize() {
let mapHTMLElement: HTMLElement =
this.elementRef.nativeElement.querySelector('#map');
Expand All @@ -123,17 +71,7 @@ export class OlMapComponent implements AfterViewInit {
}
}

public updateLayer(): void {}

public setMarker(vector: any) {
this.mapService.map.addLayer(vector);
this.cdRef.detectChanges();
}

public setControl(control: any) {
this.mapService.map.addControl(control);
}

private formataCoordenada: (coordinate: Coordinate) => string =
createStringXY(4);
}
20 changes: 12 additions & 8 deletions client/src/app/@core/services/analysis.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { Observable, of, throwError } from 'rxjs';
import { catchError, switchMap } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { environment } from '../../../environments/environment';
Expand Down Expand Up @@ -34,8 +34,8 @@ export class AnalysisService {

// TODO: Verificação do recaptcha.
public saveGeojson(
user: UserInfo,
geoJson: any,
user: UserInfo,
recaptcha: string
): Observable<any> {
return this.httpClient
Expand All @@ -59,23 +59,27 @@ export class AnalysisService {
map((response: any) => {
if (response == null) throw new Error('Erro');

console.log(response);

return response;
return {
status: 200,
};
})
);
}

// TODO: Verificação do recaptcha.
public saveFile(file, user: UserInfo, recaptcha: string) {
public saveFile(file: File, user: UserInfo, recaptcha: string) {
const formData = new FormData();

formData.append('files', file, file.name);
formData.append('name', encodeURIComponent(user.name));
formData.append('email', encodeURIComponent(user.email));

return this.httpClient
.post<any>(`${this.apiURL}/savefile`, formData)
.post<any>(`${this.apiURL}/savefile`, formData, {
headers: new HttpHeaders({
'Recaptcha-Token': recaptcha,
}),
})
.pipe(
map((response: any) => {
return {
Expand Down
6 changes: 0 additions & 6 deletions client/src/app/@core/services/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export { MapService, ZOOM_LIMIT }
providedIn: 'root',
})
class MapService {
private highResolution: boolean = false;

private _map: OlMap = new OlMap({
view: new View({
center: Proj.fromLonLat([DEFAULT_LON, DEFAULT_LAT]),
Expand Down Expand Up @@ -148,7 +146,3 @@ class MapService {
});
}
}

interface LayerStorage {

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import * as Proj from 'ol/proj';
})
export class AnalysisComponent implements OnInit, AfterViewInit {
private map: OlMap = new OlMap({
target: 'map',
layers: [
new TileLayer({
source: new OSM(),
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/hotsite/pages/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Team } from '@core/interfaces';
@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.css'],
styleUrls: ['./about.component.scss'],
})
export class AboutCompenent implements OnInit {
public team: Team[] = [];
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/hotsite/pages/help/help.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class AjudaService {

constructor(private httpClient: HttpClient) { }

saveContact(contact: Contact, recaptcha: string): Observable<any> {
public saveContact(contact: Contact, recaptcha: string): Observable<any> {
return this.httpClient.post<any>(this.apiURL + `/create`, {contact},
{
headers: new HttpHeaders({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class DrawAreaComponent implements OnInit, OnDestroy {
geoJson.features[0].properties = { id: 0 };

this.analysisService
.saveGeojson(userInfo, geoJson, recaptcha)
.saveGeojson(geoJson, userInfo, recaptcha)
.subscribe({
next: (response) => {
this.dialog.message(response.status)
Expand Down
14 changes: 3 additions & 11 deletions server/controllers/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,12 @@ module.exports = function (app) {
}
)
.then((taskResponse) => {
if (taskResponse.status === 200) {
fs.unlinkSync(request.file.path);

response.status(201).send({ token: taskResponse.data.task_id });
} else {
console.error("Falha ao enviar o GeoJSON.", taskResponse);
}
response.status(200).send({ token: taskResponse.data.task_id });
})
.catch((error) => {
console.error(error);

response.status(error.repsonse.data.status_code).send({ message: error });
}).finally(() => {
fs.unlinkSync(request.file.path);

response.status(500).send({ message: error });
});
};

Expand Down
6 changes: 3 additions & 3 deletions server/routes/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module.exports = function (app) {

const controller = app.controllers.upload;
const keyclock = app.middleware.keyclock;
//const reCaptcha = app.middleware.reCaptcha;
const reCaptcha = app.middleware.reCaptcha;

app.post('/service/upload/savegeom', keyclock, controller.saveDrawedGeom);
app.post('/service/upload/savefile', upload.single('files'), keyclock, controller.saveUploadedFile);
app.post('/service/upload/savegeom', reCaptcha, keyclock, controller.saveDrawedGeom);
app.post('/service/upload/savefile', upload.single('files'), reCaptcha, keyclock, controller.saveUploadedFile);
}

0 comments on commit 12e34dc

Please sign in to comment.