Skip to content

Commit

Permalink
Merge 2a3edc7 into 0b426df
Browse files Browse the repository at this point in the history
  • Loading branch information
danactive committed Jan 8, 2017
2 parents 0b426df + 2a3edc7 commit 7fa0a76
Show file tree
Hide file tree
Showing 24 changed files with 212 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ plugins/album/public/assets
plugins/editAlbum/public/assets
coverage.lcov
.nyc_output
yarn-error.log
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ const config = require('./config.json');
const libAdmin = require('./plugins/admin/lib/index');
const viewAlbum = require('./plugins/album/lib/index');
const editAlbum = require('./plugins/editAlbum/lib/index');
const libGeojson = require('./plugins/geojson/lib/index');
const libHome = require('./plugins/home/lib/index');
const libRename = require('./plugins/rename/lib/index');
const libResize = require('./plugins/resize/lib/index');
const libRoutes = require('./src/js/route.js');
const libVideo = require('./plugins/video/lib/index');
const logMod = require('./plugins/log/lib');
const logMod = require('./plugins/log/lib/log');
const pkg = require('./package');

require('babel-core/register')({
Expand All @@ -38,6 +39,7 @@ server.register([
{ register: libAdmin, routes: { prefix: '/admin' } },
{ register: viewAlbum, routes: { prefix: '/view' } },
{ register: editAlbum, routes: { prefix: '/edit' } },
{ register: libGeojson, routes: { prefix: '/geojson' } },
{ register: libHome },
{ register: libRename, routes: { prefix: '/admin' } },
{ register: libResize, routes: { prefix: '/admin' } },
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"clone": "^2.0.0",
"dot-prop": "^4.0.0",
"extend": "^3.0.0",
"geojson": "^0.4.0",
"glob": "^7.0.0",
"gm": "^1.23.0",
"hapi": "^16.0.0",
Expand All @@ -52,6 +53,7 @@
"xml2js": "^0.4.17"
},
"devDependencies": {
"@mapbox/geojsonhint": "^1.2.1",
"babel-preset-stage-0": "^6.16.0",
"babel-tape-runner": "^2.0.1",
"calipers": "^2.0.0",
Expand Down
4 changes: 1 addition & 3 deletions plugins/album/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const handler = (request, reply) => {
const raw = request.query.raw;

json.getAlbum(gallery, albumStem)
.then(response => (raw ? reply(response) : reply.view('plugins/album/views/page.jsx', response)))
.then(albumData => (raw ? reply(albumData) : reply.view('plugins/album/views/page.jsx', albumData)))
.catch(error => reply(error));
};

Expand All @@ -34,7 +34,6 @@ exports.register = (server, options, next) => {
path: '/album/static/{path*}',
config: {
description: 'Static assets like JS, CSS, images files',
tags: ['v0'],
handler: {
directory: {
path: 'plugins/album/public',
Expand All @@ -51,7 +50,6 @@ exports.register = (server, options, next) => {
path: '/album/static/utils.js',
config: {
description: 'Utility script',
tags: ['v0'],
handler: {
file: 'plugins/utils/public/utils.js',
},
Expand Down
7 changes: 6 additions & 1 deletion plugins/album/lib/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ function templatePrepare(result = {}) {
const thumbPath = getThumbPath(item, gallery);
const photoPath = utils.file.photoPath(thumbPath);
const videoPath = getVideoPath(item, gallery);
// todo workaround for nested https://github.com/caseypt/GeoJSON.js/issues/27
const geo_lat = (item.geo && item.geo.lat) || 0; // eslint-disable-line camelcase
const geo_lon = (item.geo && item.geo.lon) || 0; // eslint-disable-line camelcase
const enhancements = {
thumbCaption: caption(item),
title: title(item),
thumbPath,
mediaPath: (item.type === 'video') ? videoPath : photoPath,
geo_lat,
geo_lon,
};

return Object.assign(item, enhancements);
Expand Down Expand Up @@ -131,7 +136,7 @@ module.exports.getAlbum = (gallery, albumStem) => new Promise((resolve, reject)
'../../../',
ensureSafePath('gallery', gallery, reject),
'xml',
ensureSafePath('albumStem', albumStem, reject),
ensureSafePath('albumStem', albumStem, reject) // eslint-disable-line comma-dangle
);

fs.readFile(xmlPath, (readError, fileData) => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/editAlbum/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global __dirname, require */
const joi = require('joi');

const gallery = require('../../gallery/lib');
const gallery = require('../../gallery/lib/gallery');

const handler = (request, reply) => {
const raw = request.query.raw;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const tape = require('tape-catch');
tape('Index', { skip: false }, (describe) => {
const path = require('path');

const lib = require('../lib');
const lib = require('../lib/exists');

describe.test('* Real relative file exists', (assert) => {
const testPath = './plugins/exists/test/fixtures/exists.txt';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const tape = require('tape-catch');

tape('Gallery', { skip: false }, (describe) => {
const lib = require('../lib');
const lib = require('../lib/gallery');

describe.test('* Get Galleries', { skip: false }, (assert) => {
lib.getGalleries()
Expand Down
37 changes: 37 additions & 0 deletions plugins/geojson/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* global __dirname, require */
const json = require('./json');
const validation = require('../../../lib/validation');

const handler = (request, reply) => {
const albumStem = request.query.album_stem;
const gallery = request.query.gallery;

json.dataToGeojson(gallery, albumStem)
.then(geojsonData => reply(geojsonData))
.catch(error => reply(error));
};

exports.register = (server, options, next) => {
server.route({
method: 'GET',
path: '/',
config: {
description: 'GeoJSON for any album in any gallery',
handler,
tags: ['api', 'plugin'],
validate: {
query: {
album_stem: validation.albumStem,
gallery: validation.gallery,
},
},
},
});

next();
};

exports.register.attributes = {
name: 'history-geojson',
version: '0.1.0',
};
12 changes: 12 additions & 0 deletions plugins/geojson/lib/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const convertor = require('geojson');

const viewAlbum = require('../../album/lib/json');

module.exports.dataToGeojson = (gallery, albumStem) => new Promise((resolve, reject) => {
viewAlbum.getAlbum(gallery, albumStem)
.then((albumData) => {
const jsonData = convertor.parse(albumData.album.items, { Point: ['geo_lat', 'geo_lon'] });
resolve(jsonData);
})
.catch(error => reject(error));
});
8 changes: 8 additions & 0 deletions plugins/geojson/test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "airbnb",
"rules": {
"max-len": [2, 150, 4],
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"global-require": 0
}
}
39 changes: 39 additions & 0 deletions plugins/geojson/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const tape = require('tape-catch');

tape('GeoJSON Index', { skip: false }, (describe) => {
const geojsonhint = require('@mapbox/geojsonhint');
const hapi = require('hapi');

const lib = require('../lib');
const utils = require('../../utils/lib');

const plugins = [lib];
const port = utils.config.get('port');

describe.test('* Validate GeoJSON', (assert) => {
const server = new hapi.Server();
server.connection({ port });
server.register(plugins, (pluginError) => {
if (pluginError) {
assert.fail(pluginError);
return;
}

const request = {
method: 'GET',
url: '/?gallery=demo&album_stem=sample',
};

server.inject(request, (result) => {
assert.ok(geojsonhint.hint({}).length > 0, 'Error expected');

assert.equal(result.statusCode, 200);
const response = result.result;
const error = geojsonhint.hint(response);

assert.equal(error.length, 0, 'Validation passes');
assert.end();
});
});
});
});
20 changes: 20 additions & 0 deletions plugins/geojson/test/json.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const tape = require('tape-catch');

tape('GeoJSON JSON', { skip: false }, (describe) => {
const geojsonhint = require('@mapbox/geojsonhint');
const lib = require('../lib/json');

describe.test('* Validate GeoJSON', (assert) => {
const expectedError = geojsonhint.hint({});

assert.ok(expectedError.length > 0, 'Error expected');

lib.dataToGeojson('demo', 'sample')
.then((json) => {
const error = geojsonhint.hint(json);

assert.equal(error.length, 0, 'Validation passes');
assert.end();
});
});
});
2 changes: 1 addition & 1 deletion plugins/home/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global __dirname, require */

const gallery = require('../../gallery/lib');
const gallery = require('../../gallery/lib/gallery');

const handler = (request, reply) => {
gallery.getGalleries().then(galleries => reply.view('plugins/home/views/page.jsx', { galleries }));
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const tape = require('tape-catch');

tape('Log', { skip: false }, (describe) => {
const lib = require('../lib');
const lib = require('../lib/log');

const moduleName = 'test';

Expand Down
4 changes: 2 additions & 2 deletions plugins/rename/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
const boom = require('boom');
const joi = require('joi');

const existsMod = require('../../exists/lib');
const existsMod = require('../../exists/lib/exists');
const filenamesMod = require('./filenames');
// const logMod = require('../../log/lib');
// const logMod = require('../../log/lib/log');
const renameMod = require('./rename');

const handler = (request, reply) => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/rename/lib/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const boom = require('boom');
const fs = require('fs');
const path = require('path');

const exists = require('../../exists/lib');
const exists = require('../../exists/lib/exists');
const utils = require('../../utils/lib');

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/rename/test/rename.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tape('Verify rename library', { skip: false }, (describe) => {
const appRoot = require('app-root-path');
const path = require('path');

const exist = require('../../exists/lib/');
const exist = require('../../exists/lib/exists');
const plugin = require('../lib/rename');

/*
Expand Down
2 changes: 1 addition & 1 deletion plugins/resize/lib/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const boom = require('boom');
const gm = require('gm');
const path = require('path');

const existsMod = require('../../exists/lib');
const existsMod = require('../../exists/lib/exists');
const utils = require('../../utils/lib');

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/utils/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const mime = require('mime-types');
const path = require('path');

const configJson = require('../../../config.json');
// const logMod = require('../../log/lib');
// const logMod = require('../../log/lib/log');
const pkg = require('../../../package.json');

// const log = logMod('util');
Expand Down
Loading

0 comments on commit 7fa0a76

Please sign in to comment.