Commit d245f596 authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Initial commit

parents
This diff is collapsed.
/*
* This file is part of P4CaaS.
*
* P4CaaS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* P4CaaS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with P4CaaS. If not, see <http://www.gnu.org/licenses/>.
*/
const P4C = require("pic4carto");
const CREDENTIALS = {
mapillary: { key: "eDhQTTdnRmZJNXdYZWUwRDQxc1NwdzphZDIyNWZjZTA3YWU3ODY1" },
flickr: { key: "1ba9e9ec7a22f9383ea5eb35a17fc853" }
};
exports.default = function(req, res) {
res.json({ "status": "OK" });
};
/**
* @api {get} /search/around
* @apiName SearchAround
* @apiGroup Search
*
* @apiParam {Number} lat The latitude (WGS84)
* @apiParam {Number} lng The longitude (WGS84)
* @apiParam {Number} radius The radius around the point, in meters
* @apiParam {Long} [mindate] The minimum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)
* @apiParam {Long} [maxdate] The maximum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)
* @apiParam {String} [use] The list of fetchers to use (comma-separated)
*/
exports.searchAround = function(req, res) {
console.log("[SEARCH] "
+req.query.radius
+" meters around "
+req.query.lat+", "+req.query.lng
+" between TS "
+req.query.mindate+" and "+req.query.maxdate
+" (use "+req.query.use+" | ignore "+req.query.ignore+")");
const picManager = new P4C.PicturesManager({ fetcherCredentials: CREDENTIALS });
//Prepare event for when pictures are downloaded
picManager.on("picsready", function(pictures) {
res.json({ "status": "OK", "pictures": pictures });
});
picManager.on("fetcherfailed", function(fetcherId) {
console.log("[SEARCH] Failed on fetcher "+fetcherId);
});
//Call for pictures download
try {
picManager.startPicsRetrievalAround(
new P4C.LatLng(req.query.lat, req.query.lng),
req.query.radius,
{
mindate: req.query.mindate,
maxdate: req.query.maxdate,
usefetchers: req.query.use ? req.query.use.split(',') : undefined,
ignorefetchers: req.query.ignore ? req.query.ignore.split(',') : undefined
}
);
}
catch(e) {
res.status(500).send({ "status": "NOTOK", "error": e });
}
};
exports.searchBbox = function(req, res) {
console.log("[SEARCH] BBox "
+req.query.south+", "+req.query.west+", "+req.query.north+", "+req.query.east
+" between TS "
+req.query.mindate+" and "+req.query.maxdate
+" (use "+req.query.use+" | ignore "+req.query.ignore+")");
const picManager = new P4C.PicturesManager({ fetcherCredentials: CREDENTIALS });
//Prepare event for when pictures are downloaded
picManager.on("picsready", function(pictures) {
res.json({ "status": "OK", "pictures": pictures });
});
picManager.on("fetcherfailed", function(fetcherId) {
console.log("[SEARCH] Failed on fetcher "+fetcherId);
});
//Call for pictures download
try {
picManager.startPicsRetrieval(
new P4C.LatLngBounds(new P4C.LatLng(req.query.south, req.query.west), new P4C.LatLng(req.query.north, req.query.east)),
{
mindate: req.query.mindate,
maxdate: req.query.maxdate,
usefetchers: req.query.use ? req.query.use.split(',') : undefined,
ignorefetchers: req.query.ignore ? req.query.ignore.split(',') : undefined
}
);
}
catch(e) {
res.status(500).send({ "status": "NOTOK", "error": e });
}
};
/*
* This file is part of P4CaaS.
*
* P4CaaS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* P4CaaS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with P4CaaS. If not, see <http://www.gnu.org/licenses/>.
*/
module.exports = function(app) {
const ctrl = require('../controllers/P4CaaSController');
app.route('/')
.get(ctrl.default);
app.route('/search')
.get(ctrl.default);
app.route('/search/around')
.get(ctrl.searchAround);
app.route('/search/bbox')
.get(ctrl.searchBbox);
};
define({ "api": [
{
"type": "get",
"url": "/search/around",
"title": "",
"name": "SearchAround",
"group": "Search",
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "lat",
"description": "<p>The latitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "lng",
"description": "<p>The longitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "radius",
"description": "<p>The radius around the point, in meters</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "mindate",
"description": "<p>The minimum timestamp for a given time range</p>"
}
]
}
},
"version": "0.0.0",
"filename": "api/controllers/P4CaaSController.js",
"groupTitle": "Search"
}
] });
[
{
"type": "get",
"url": "/search/around",
"title": "",
"name": "SearchAround",
"group": "Search",
"parameter": {
"fields": {
"Parameter": [
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "lat",
"description": "<p>The latitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "lng",
"description": "<p>The longitude (WGS84)</p>"
},
{
"group": "Parameter",
"type": "Number",
"optional": false,
"field": "radius",
"description": "<p>The radius around the point, in meters</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "mindate",
"description": "<p>The minimum timestamp for a given time range</p>"
}
]
}
},
"version": "0.0.0",
"filename": "api/controllers/P4CaaSController.js",
"groupTitle": "Search"
}
]
define({
"title": "Pic4Carto API Documentation",
"name": "p4caas",
"version": "0.0.1",
"description": "API for retrieving all open-licensed geolocated pictures (Pic4Carto as a Service)",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2017-06-08T17:29:49.562Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
});
{
"title": "Pic4Carto API Documentation",
"name": "p4caas",
"version": "0.0.1",
"description": "API for retrieving all open-licensed geolocated pictures (Pic4Carto as a Service)",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2017-06-08T17:29:49.562Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
}
/* ------------------------------------------------------------------------------------------
* Content
* ------------------------------------------------------------------------------------------ */
body {
min-width: 980px;
max-width: 1280px;
}
body, p, a, div, th, td {
font-family: "Source Sans Pro", sans-serif;
font-weight: 400;
font-size: 16px;
}
td.code {
font-size: 14px;
font-family: "Source Code Pro", monospace;
font-style: normal;
font-weight: 400;
}
#content {
padding-top: 16px;
z-Index: -1;
margin-left: 270px;
}
p {
color: #808080;
}
h1 {
font-family: "Source Sans Pro Semibold", sans-serif;
font-weight: normal;
font-size: 44px;
line-height: 50px;
margin: 0 0 10px 0;
padding: 0;
}
h2 {
font-family: "Source Sans Pro", sans-serif;
font-weight: normal;
font-size: 24px;
line-height: 40px;
margin: 0 0 20px 0;
padding: 0;
}
section {
border-top: 1px solid #ebebeb;
padding: 30px 0;
}
section h1 {
font-family: "Source Sans Pro", sans-serif;
font-weight: 700;
font-size: 32px;
line-height: 40px;
padding-bottom: 14px;
margin: 0 0 20px 0;
padding: 0;
}
article {
padding: 14px 0 30px 0;
}
article h1 {
font-family: "Source Sans Pro Bold", sans-serif;
font-weight: 600;
font-size: 24px;
line-height: 26px;
}
article h2 {
font-family: "Source Sans Pro", sans-serif;
font-weight: 600;
font-size: 18px;
line-height: 24px;
margin: 0 0 10px 0;
}
article h3 {
font-family: "Source Sans Pro", sans-serif;
font-weight: 600;
font-size: 16px;
line-height: 18px;
margin: 0 0 10px 0;
}
article h4 {
font-family: "Source Sans Pro", sans-serif;
font-weight: 600;
font-size: 14px;
line-height: 16px;
margin: 0 0 8px 0;
}
table {
border-collapse: collapse;
width: 100%;
margin: 0 0 20px 0;
}
th {
background-color: #f5f5f5;
text-align: left;
font-family: "Source Sans Pro", sans-serif;
font-weight: 700;
padding: 4px 8px;
border: #e0e0e0 1px solid;
}
td {
vertical-align: top;
padding: 10px 8px 0 8px;
border: #e0e0e0 1px solid;
}
#generator .content {
color: #b0b0b0;
border-top: 1px solid #ebebeb;
padding: 10px 0;
}
.label-optional {
float: right;
background-color: grey;
margin-top: 4px;
}
.open-left {
right: 0;
left: auto;
}
/* ------------------------------------------------------------------------------------------
* apidoc - intro
* ------------------------------------------------------------------------------------------ */
#apidoc .apidoc {
border-top: 1px solid #ebebeb;
padding: 30px 0;
}
#apidoc h1 {
font-family: "Source Sans Pro", sans-serif;
font-weight: 700;
font-size: 32px;
line-height: 40px;
padding-bottom: 14px;
margin: 0 0 20px 0;
padding: 0;
}
#apidoc h2 {
font-family: "Source Sans Pro Bold", sans-serif;
font-weight: 600;
font-size: 22px;
line-height: 26px;
padding-top: 14px;
}
/* ------------------------------------------------------------------------------------------
* pre / code
* ------------------------------------------------------------------------------------------ */
pre {
background-color: #292b36;
color: #ffffff;
padding: 10px;
border-radius: 6px;
position: relative;
margin: 10px 0 20px 0;
overflow-x: auto;
}
pre.prettyprint {
width: 100%;
}
code.language-text {
word-wrap: break-word;
}
pre.language-json {
overflow: auto;
}
pre.language-html {
margin: 0 0 20px 0;
}
.type {
font-family: "Source Sans Pro", sans-serif;
font-weight: 600;
font-size: 15px;
display: inline-block;
margin: 0 0 5px 0;
padding: 4px 5px;
border-radius: 6px;
text-transform: uppercase;
background-color: #3387CC;
color: #ffffff;
}
.type__get {
background-color: green;
}
.type__put {
background-color: #e5c500;
}
.type__post {
background-color: #4070ec;
}
.type__delete {
background-color: #ed0039;
}
pre.language-api .str {
color: #ffffff;
}
pre.language-api .pln,
pre.language-api .pun {
color: #65B042;
}
pre code {
display: block;
font-size: 14px;
font-family: "Source Code Pro", monospace;
font-style: normal;
font-weight: 400;
word-wrap: normal;
white-space: pre;
}
pre code.sample-request-response-json {
white-space: pre-wrap;
max-height: 500px;
overflow: auto;
}
/* ------------------------------------------------------------------------------------------
* Sidenav
* ------------------------------------------------------------------------------------------ */
.sidenav {
width: 228px;
margin: 0;
padding: 0 20px 20px 20px;
position: fixed;
top: 50px;
left: 0;
bottom: 0;
overflow-x: hidden;
overflow-y: auto;
background-color: #f5f5f5;
z-index: 10;
}
.sidenav > li > a {
display: block;
width: 192px;
margin: 0;
padding: 2px 11px;
border: 0;
border-left: transparent 4px solid;
border-right: transparent 4px solid;
font-family: "Source Sans Pro", sans-serif;
font-weight: 400;
font-size: 14px;
}
.sidenav > li.nav-header {
margin-top: 8px;
margin-bottom: 8px;
}
.sidenav > li.nav-header > a {
padding: 5px 15px;
border: 1px solid #e5e5e5;
width: 190px;
font-family: "Source Sans Pro", sans-serif;
font-weight: 700;
font-size: 16px;
background-color: #ffffff;
}
.sidenav > li.active > a {
position: relative;
z-index: 2;
background-color: #0088cc;
color: #ffffff;
}
.sidenav > li.has-modifications a {
border-right: #60d060 4px solid;
}
.sidenav > li.is-new a {
border-left: #e5e5e5 4px solid;
}
/* ------------------------------------------------------------------------------------------
* Side nav search
* ------------------------------------------------------------------------------------------ */
.sidenav-search {
width: 228px;
left: 0px;
position: fixed;
padding: 16px 20px 10px 20px;
background-color: #F5F5F5;
z-index: 11;
}
.sidenav-search .search {
height: 26px;
}
.search-reset {
position: absolute;
display: block;
cursor: pointer;
width: 20px;
height: 20px;
text-align: center;
right: 28px;
top: 17px;
background-color: #fff;
}
/* ------------------------------------------------------------------------------------------
* Compare
* ------------------------------------------------------------------------------------------ */
ins {
background: #60d060;
text-decoration: none;
color: #000000;
}
del {
background: #f05050;
color: #000000;