Commit 3a9c1a1b authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Merge branch 'develop'

parents 3648634f 154821e1
node_modules/
*.log
package-lock.json
image: node:7
before_script:
- node --version
- npm --version
- npm install --silent
cache:
paths:
- node_modules/
test:
script:
- npm run test
......@@ -2,7 +2,7 @@
## Read-me
At start, [Pic4Carto](http://projets.pavie.info/pic4carto) is a website for browsing open-licensed, geolocated street pictures. From this website was extracted the core functionnality of retrieving pictures from several providers (Mapillary, OpenStreetCam, Flickr, WikiCommons...) as a JavaScript library called [Pic4Carto.js](https://framagit.org/PanierAvide/Pic4Carto.js), which can be integrated in various web applications.
At start, [Pic4Carto](http://projets.pavie.info/pic4carto) is a website for browsing open-licensed, geolocated street pictures. From this website was extracted the core functionnality of retrieving pictures from several providers (Mapillary, OpenStreetCam, Flickr, WikiCommons...) as a JavaScript library called [Pic4Carto.js](https://framagit.org/Pic4Carto/Pic4Carto.js), which can be integrated in various web applications.
To make reuse of pictures in various applications even easier, **P4CaaS** (Pic4Carto as a Service) was created here. It is a Rest API which can be called over HTTP requests for searching street pictures over all managed providers.
......@@ -37,7 +37,7 @@ Before installing P4CaaS, you need to install some dependencies:
To launch your own Pic4Carto API, run the following commands:
```
git clone https://framagit.org/PanierAvide/P4CaaS.git
git clone https://framagit.org/Pic4Carto/P4CaaS.git
cd P4CaaS/
npm install
npm run start
......@@ -60,8 +60,8 @@ For several query examples, you can have a look on unit tests, available in the
## Contributing
P4CaaS, as all over projects around Pic4Carto, is open source. Contributions are welcome, and here is how you can help for this project:
* Report bugs or discuss new functionalities in the [Issues tracker](https://framagit.org/PanierAvide/P4CaaS/issues).
* Write code (and tests) and create a [merge request](https://framagit.org/PanierAvide/P4CaaS/merge_requests). As this project is using [Git Flow branching model](http://nvie.com/posts/a-successful-git-branching-model/), please create requests on __develop__ or __feature/*__ branches.
* Report bugs or discuss new functionalities in the [Issues tracker](https://framagit.org/Pic4Carto/P4CaaS/issues).
* Write code (and tests) and create a [merge request](https://framagit.org/Pic4Carto/P4CaaS/merge_requests). As this project is using [Git Flow branching model](http://nvie.com/posts/a-successful-git-branching-model/), please create requests on __develop__ or __feature/*__ branches.
## License
......
......@@ -40,7 +40,7 @@ exports.default = function(req, res) {
* @apiParam {String} [ignore] The list of fetchers to ignore (comma-separated)
*
* @apiSuccess {String} status The response status (OK)
* @apiSuccess {Array} pictures The retrieved pictures, see <a href="https://framagit.org/PanierAvide/Pic4Carto.js/blob/master/doc/API.md#picture">details about the Picture object</a>.
* @apiSuccess {Array} pictures The retrieved pictures, see <a href="https://framagit.org/Pic4Carto/Pic4Carto.js/blob/master/doc/API.md#picture">details about the Picture object</a>.
*/
exports.searchAround = function(req, res) {
/*console.log("[SEARCH] "
......@@ -53,11 +53,6 @@ exports.searchAround = function(req, res) {
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);
});
......@@ -73,7 +68,13 @@ exports.searchAround = function(req, res) {
usefetchers: req.query.use ? req.query.use.split(',') : undefined,
ignorefetchers: req.query.ignore ? req.query.ignore.split(',') : undefined
}
);
)
.then(pictures => {
res.json({ "status": "OK", "pictures": pictures });
})
.catch(e => {
throw e;
});
}
catch(e) {
res.status(500).send({ "status": "NOTOK", "error": e.toString() });
......@@ -96,7 +97,7 @@ exports.searchAround = function(req, res) {
* @apiParam {String} [ignore] The list of fetchers to ignore (comma-separated)
*
* @apiSuccess {String} status The response status (OK)
* @apiSuccess {Array} pictures The retrieved pictures, see <a href="https://framagit.org/PanierAvide/Pic4Carto.js/blob/master/doc/API.md#picture">details about the Picture object</a>.
* @apiSuccess {Array} pictures The retrieved pictures, see <a href="https://framagit.org/Pic4Carto/Pic4Carto.js/blob/master/doc/API.md#picture">details about the Picture object</a>.
*/
exports.searchBbox = function(req, res) {
/*console.log("[SEARCH] BBox "
......@@ -107,11 +108,6 @@ exports.searchBbox = function(req, res) {
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);
});
......@@ -126,7 +122,13 @@ exports.searchBbox = function(req, res) {
usefetchers: req.query.use ? req.query.use.split(',') : undefined,
ignorefetchers: req.query.ignore ? req.query.ignore.split(',') : undefined
}
);
)
.then(pictures => {
res.json({ "status": "OK", "pictures": pictures });
})
.catch(e => {
throw e;
});
}
catch(e) {
res.status(500).send({ "status": "NOTOK", "error": e.toString() });
......@@ -173,11 +175,6 @@ exports.summaryBbox = function(req, res) {
const picManager = new P4C.PicturesManager({ fetcherCredentials: CREDENTIALS });
//Prepare event for when summary is ready
picManager.on("summaryready", function(summary) {
res.json({ "status": "OK", "summary": summary });
});
picManager.on("fetcherfailed", function(fetcherId) {
console.log("[SUMMARY] Failed on fetcher "+fetcherId);
});
......@@ -190,7 +187,13 @@ exports.summaryBbox = function(req, res) {
mindate: req.query.mindate ? parseInt(req.query.mindate) : undefined,
maxdate: req.query.maxdate ? parseInt(req.query.maxdate) : undefined
}
);
)
.then(summary => {
res.json({ "status": "OK", "summary": summary });
})
.catch(e => {
throw e;
});
}
catch(e) {
res.status(500).send({ "status": "NOTOK", "error": e.toString() });
......
......@@ -107,7 +107,7 @@ define({ "api": [
"type": "Array",
"optional": false,
"field": "pictures",
"description": "<p>The retrieved pictures, see <a href=\"https://framagit.org/PanierAvide/Pic4Carto.js/blob/master/doc/API.md#picture\">details about the Picture object</a>.</p>"
"description": "<p>The retrieved pictures, see <a href=\"https://framagit.org/Pic4Carto/Pic4Carto.js/blob/master/doc/API.md#picture\">details about the Picture object</a>.</p>"
}
]
}
......@@ -200,7 +200,7 @@ define({ "api": [
"type": "Array",
"optional": false,
"field": "pictures",
"description": "<p>The retrieved pictures, see <a href=\"https://framagit.org/PanierAvide/Pic4Carto.js/blob/master/doc/API.md#picture\">details about the Picture object</a>.</p>"
"description": "<p>The retrieved pictures, see <a href=\"https://framagit.org/Pic4Carto/Pic4Carto.js/blob/master/doc/API.md#picture\">details about the Picture object</a>.</p>"
}
]
}
......
......@@ -107,7 +107,7 @@
"type": "Array",
"optional": false,
"field": "pictures",
"description": "<p>The retrieved pictures, see <a href=\"https://framagit.org/PanierAvide/Pic4Carto.js/blob/master/doc/API.md#picture\">details about the Picture object</a>.</p>"
"description": "<p>The retrieved pictures, see <a href=\"https://framagit.org/Pic4Carto/Pic4Carto.js/blob/master/doc/API.md#picture\">details about the Picture object</a>.</p>"
}
]
}
......@@ -200,7 +200,7 @@
"type": "Array",
"optional": false,
"field": "pictures",
"description": "<p>The retrieved pictures, see <a href=\"https://framagit.org/PanierAvide/Pic4Carto.js/blob/master/doc/API.md#picture\">details about the Picture object</a>.</p>"
"description": "<p>The retrieved pictures, see <a href=\"https://framagit.org/Pic4Carto/Pic4Carto.js/blob/master/doc/API.md#picture\">details about the Picture object</a>.</p>"
}
]
}
......
......@@ -8,7 +8,7 @@ define({
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2017-07-04T08:43:06.007Z",
"time": "2017-10-20T18:20:13.809Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
......
......@@ -8,7 +8,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2017-07-04T08:43:06.007Z",
"time": "2017-10-20T18:20:13.809Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
......
......@@ -2,7 +2,7 @@
"name": "p4caas",
"version": "0.1.1",
"description": "API for retrieving all open-licensed geolocated pictures (Pic4Carto as a Service)",
"main": "index.js",
"main": "server.js",
"scripts": {
"start": "nodemon server.js",
"doc": "apidoc -i api/ -o doc/",
......@@ -32,8 +32,9 @@
},
"dependencies": {
"body-parser": "^1.17.2",
"cors": "^2.8.4",
"express": "^4.15.3",
"pic4carto": "^1.2.3",
"pic4carto": "^2.0.1",
"use-strict": "^1.0.1",
"xmlhttprequest": "^1.8.0"
},
......
......@@ -23,9 +23,13 @@ global.XMLHttpRequest.DONE = 4;
const express = require('express'),
bodyParser = require('body-parser'),
cors = require('cors'),
app = express(),
port = process.env.PORT || 28111;
app.use(cors());
app.options('*', cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/doc', express.static(__dirname+'/doc'));
......
......@@ -98,14 +98,14 @@ describe('Server routes', function() {
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.equal(res.body.pictures.length, 31);
assert.equal(res.body.pictures[0].pictureUrl, "https://d1cuyjsrcm0gby.cloudfront.net/eJMBmO6ndsHysDHsSHdhuQ/thumb-2048.jpg");
assert.equal(res.body.pictures.length, 30);
assert.equal(res.body.pictures[0].pictureUrl, "https://d1cuyjsrcm0gby.cloudfront.net/vtsgTa39W_TuXTOrFBgD8A/thumb-2048.jpg");
assert.ok(res.body.pictures[0].date > 0);
assert.ok(res.body.pictures[0].coordinates !== undefined);
assert.equal(res.body.pictures[0].provider, "Mapillary");
assert.equal(res.body.pictures[0].author, "panieravide");
assert.equal(res.body.pictures[0].license, "CC By-SA 4.0");
assert.equal(res.body.pictures[0].detailsUrl, "https://www.mapillary.com/app/?pKey=eJMBmO6ndsHysDHsSHdhuQ&lat=48.127471560000004&lng=-1.6850350500000104&focus=photo");
assert.equal(res.body.pictures[0].detailsUrl, "https://www.mapillary.com/app/?pKey=vtsgTa39W_TuXTOrFBgD8A&lat=48.12742294999998&lng=-1.685248060000049&focus=photo");
done();
});
}).timeout(15000);
......@@ -144,7 +144,7 @@ describe('Server routes', function() {
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.equal(res.body.pictures.length, 20);
assert.equal(res.body.pictures.length, 19);
for(const p of res.body.pictures) {
assert.equal(p.provider, "OpenStreetCam");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment