mirror of
https://github.com/sstent/node.git
synced 2026-01-27 23:51:45 +00:00
updated app
This commit is contained in:
100
node_modules/derby-examples/gallery/lib/server/flickr.js
generated
vendored
Normal file
100
node_modules/derby-examples/gallery/lib/server/flickr.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
// Generated by CoffeeScript 1.3.1
|
||||
var FLICKR_API, Flickr, request;
|
||||
|
||||
request = require('request');
|
||||
|
||||
FLICKR_API = 'http://api.flickr.com/services/rest/';
|
||||
|
||||
exports.setup = function(store, options) {
|
||||
var flickr;
|
||||
flickr = new Flickr(options);
|
||||
store.route('get', 'flickr.user.id_*.photos.pages.*', function(username, page, done) {
|
||||
return flickr.userPublicPhotos(username, page, done);
|
||||
});
|
||||
return store.route('get', 'flickr.photoset.id_*.photos.pages.*', function(id, page, done) {
|
||||
return flickr.setPhotos(id, page, done);
|
||||
});
|
||||
};
|
||||
|
||||
Flickr = function(options) {
|
||||
this.key = options.key;
|
||||
this.userIds = {};
|
||||
};
|
||||
|
||||
Flickr.prototype = {
|
||||
get: function(qs, callback) {
|
||||
qs.format = 'json';
|
||||
qs.api_key = this.key;
|
||||
qs.per_page = 20;
|
||||
qs.extras = 'o_dims';
|
||||
return request({
|
||||
url: FLICKR_API,
|
||||
qs: qs
|
||||
}, function(err, res, body) {
|
||||
var data, match;
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (!((match = /jsonFlickrApi\((.*)\)/.exec(body)) && (body = match[1]))) {
|
||||
return callback(new Erorr('Unknown Flickr response'));
|
||||
}
|
||||
data = JSON.parse(body);
|
||||
if (data.stat !== 'ok') {
|
||||
return callback(new Error(data.message));
|
||||
}
|
||||
return callback(null, data);
|
||||
});
|
||||
},
|
||||
userId: function(username, callback) {
|
||||
var id, qs,
|
||||
_this = this;
|
||||
if (id = this.userIds[username]) {
|
||||
return callback(null, id);
|
||||
}
|
||||
qs = {
|
||||
method: 'flickr.people.findByUsername',
|
||||
username: username
|
||||
};
|
||||
return this.get(qs, function(err, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
id = _this.userIds[username] = body.user.id;
|
||||
return callback(null, id);
|
||||
});
|
||||
},
|
||||
userPublicPhotos: function(username, page, callback) {
|
||||
var _this = this;
|
||||
return this.userId(username, function(err, user_id) {
|
||||
var qs;
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
qs = {
|
||||
method: 'flickr.people.getPublicPhotos',
|
||||
user_id: user_id,
|
||||
page: +page + 1
|
||||
};
|
||||
return _this.get(qs, function(err, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, body.photos.photo, -1);
|
||||
});
|
||||
});
|
||||
},
|
||||
setPhotos: function(photoset_id, page, callback) {
|
||||
var qs;
|
||||
qs = {
|
||||
method: 'flickr.photosets.getPhotos',
|
||||
photoset_id: photoset_id,
|
||||
page: +page + 1
|
||||
};
|
||||
return this.get(qs, function(err, body) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, body.photoset.photo, -1);
|
||||
});
|
||||
}
|
||||
};
|
||||
42
node_modules/derby-examples/gallery/lib/server/index.js
generated
vendored
Normal file
42
node_modules/derby-examples/gallery/lib/server/index.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// Generated by CoffeeScript 1.3.1
|
||||
var ONE_YEAR, app, derby, express, expressApp, flickr, gzippo, http, path, publicPath, root, server, serverError, store;
|
||||
|
||||
http = require('http');
|
||||
|
||||
path = require('path');
|
||||
|
||||
express = require('express');
|
||||
|
||||
gzippo = require('gzippo');
|
||||
|
||||
derby = require('derby');
|
||||
|
||||
app = require('../app');
|
||||
|
||||
flickr = require('./flickr');
|
||||
|
||||
serverError = require('./serverError');
|
||||
|
||||
ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
|
||||
|
||||
root = path.dirname(path.dirname(__dirname));
|
||||
|
||||
publicPath = path.join(root, 'public');
|
||||
|
||||
(expressApp = express()).use(express.favicon()).use(gzippo.staticGzip(publicPath, {
|
||||
maxAge: ONE_YEAR
|
||||
})).use(express.compress()).use(app.router()).use(expressApp.router).use(serverError(root));
|
||||
|
||||
module.exports = server = http.createServer(expressApp);
|
||||
|
||||
expressApp.all('*', function(req) {
|
||||
throw "404: " + req.url;
|
||||
});
|
||||
|
||||
store = app.createStore({
|
||||
listen: server
|
||||
});
|
||||
|
||||
flickr.setup(store, {
|
||||
key: '86958e03c183fcb1b7fddfeb19f3a423'
|
||||
});
|
||||
27
node_modules/derby-examples/gallery/lib/server/serverError.js
generated
vendored
Normal file
27
node_modules/derby-examples/gallery/lib/server/serverError.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Generated by CoffeeScript 1.3.1
|
||||
var derby, isProduction;
|
||||
|
||||
derby = require('derby');
|
||||
|
||||
isProduction = derby.util.isProduction;
|
||||
|
||||
module.exports = function(root) {
|
||||
var staticPages;
|
||||
staticPages = derby.createStatic(root);
|
||||
return function(err, req, res, next) {
|
||||
var message, status;
|
||||
if (err == null) {
|
||||
return next();
|
||||
}
|
||||
console.log(err.stack ? err.stack : err);
|
||||
message = err.message || err.toString();
|
||||
status = parseInt(message);
|
||||
if (status === 404) {
|
||||
return staticPages.render('404', res, {
|
||||
url: req.url
|
||||
}, 404);
|
||||
} else {
|
||||
return res.send((400 <= status && status < 600) ? status : 500);
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user