remove code related to avatars

This commit is contained in:
Sean McArthur 2014-06-04 11:17:28 -07:00
Родитель f990db63e6
Коммит 13083deaf3
5 изменённых файлов: 5 добавлений и 203 удалений

Просмотреть файл

@ -14,13 +14,13 @@ const conf = convict({
default: 1
}
},
db: {
/*db: {
driver: {
env: 'DB',
format: ['mysql', 'memory'],
default: 'memory'
}
},
},*/
env: {
arg: 'node-env',
doc: 'The current node.js environment',
@ -71,7 +71,7 @@ const conf = convict({
default: __dirname
}
},
mysql: {
/*mysql: {
createSchema: {
env: 'CREATE_MYSQL_SCHEMA',
default: true
@ -96,7 +96,7 @@ const conf = convict({
default: '3306',
env: 'MYSQL_PORT'
}
},
},*/
oauth: {
url: {
doc: 'URL of fxa-oauth-server',
@ -119,20 +119,6 @@ const conf = convict({
format: 'port',
default: 1111
}
},
uploads: {
dir: {
doc: 'Directory to store user uploads in.', //eek!
default: path.join(__dirname, '..', 'uploads')
},
url: {
doc: 'Domain to serve uploaded avatars from',
default: ''
},
route: {
doc: 'Path to download an uploaded avatar',
default: '/a'
}
}
});
@ -141,10 +127,6 @@ var files = (envConfig + ',' + process.env.CONFIG_FILES)
.split(',').filter(fs.existsSync);
conf.loadFile(files);
if (conf.get('uploads.url') === conf.default('uploads.url')) {
conf.set('uploads.url', conf.get('publicUrl'));
}
conf.validate();
module.exports = conf;

Просмотреть файл

@ -1,4 +0,0 @@
CREATE TABLE IF NOT EXISTS profiles (
uid BINARY(16) PRIMARY KEY,
avatar VARCHAR(255)
) ENGINE=InnoDB;

Просмотреть файл

@ -1,29 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const Joi = require('joi');
const db = require('../db');
const URL_REGEX = /^https?:\/\/.+/;
module.exports = {
auth: {
strategy: 'oauth',
scope: ['profile', 'profile:avatar']
},
validate: {
payload: {
url: Joi.string().regex(URL_REGEX).required()
}
},
handler: function avatarPost(req, reply) {
var id = req.auth.credentials.user;
db.getOrCreateProfile(id).then(function() {
return db.setAvatar(id, req.payload.url);
}).done(function() {
reply({});
}, reply);
}
};

Просмотреть файл

@ -1,74 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const config = require('../config');
const logger = require('../logging').getLogger('fxa.routes.upload');
const P = require('../promise');
const db = require('../db');
function unique() {
return [
Date.now(),
process.pid,
crypto.randomBytes(8).toString('hex')
].join('-');
}
function stream(readable) {
var d = P.defer();
var uploads = config.get('uploads.dir');
var temp = path.join(uploads, unique());
var hash = crypto.createHash('sha1');
var dest = fs.createWriteStream(temp);
logger.debug('uploading to %s', temp);
readable.pipe(hash);
readable.pipe(dest);
readable.on('end', function() {
var digest = hash.read().toString('hex') + '.png';
dest = path.join(uploads, digest);
logger.debug('upload digest, dest [%s, %s]', digest, dest);
fs.rename(temp, dest, function(err) {
if (err) {
return d.reject(err);
}
d.resolve(digest);
});
});
return d.promise;
}
module.exports = {
auth: {
strategy: 'oauth',
scope: ['profile', 'profile:avatar']
},
payload: {
allow: 'image/png', // other types later. this a POC
output: 'stream',
parse: false
},
handler: function avatarPost(req, reply) {
// save image in uploads dir
// generate hash to be used as url fragment
// update db with url
P.all([
stream(req.payload),
db.getOrCreateProfile(req.auth.credentials)
]).spread(function(hash, profile) {
return db.setAvatar(profile.uid, hash);
}).done(function() {
reply({});
}, reply);
}
};

Просмотреть файл

@ -9,10 +9,9 @@ const assert = require('insist');
const nock = require('nock');
const config = require('../lib/config');
const db = require('../lib/db');
const Server = require('./lib/server');
/*global describe,before,it*/
/*global describe,it*/
const USERID = crypto.randomBytes(16).toString('hex');
const TOKEN_GOOD = JSON.stringify({
@ -20,7 +19,6 @@ const TOKEN_GOOD = JSON.stringify({
scope: ['profile'],
email: 'user@example.domain'
});
var avatarUrl = 'http://example.domain/path/img.png';
function token() {
return crypto.randomBytes(32).toString('hex');
@ -31,67 +29,8 @@ function mockToken() {
return nock(parts.protocol + '//' + parts.host).post(parts.path + '/verify');
}
describe.skip('/avatar', function() {
it('should require authentication', function() {
var imageData = { url: avatarUrl };
return Server.api.get({
url: '/avatar',
payload: JSON.stringify(imageData)
}).then(function(res) {
assert.equal(res.statusCode, 401);
});
});
it('should be able to post a url', function() {
mockToken().reply(200, TOKEN_GOOD);
var tok = token();
var imageData = { url: avatarUrl };
return Server.api.get({
url: '/avatar',
payload: JSON.stringify(imageData),
headers: {
authorization: 'Bearer ' + tok
}
}).then(function(res) {
assert.equal(res.statusCode, 200);
return db.getProfile(USERID);
}).then(function(profile) {
assert.equal(profile.avatar, avatarUrl);
});
});
it('should fail if is not a url', function() {
var uid = token();
mockToken().reply(200, TOKEN_GOOD);
var imageData = { url: 'blah' };
return Server.api.get({
url: '/avatar',
payload: JSON.stringify(imageData),
headers: {
authorization: 'Bearer ' + uid
}
}).then(function(res) {
assert.equal(res.statusCode, 400);
});
});
});
describe.skip('/avatar/upload', function() {
});
describe('/profile', function() {
var uid = token();
before(function() {
return db.createProfile({
uid: uid,
avatar: avatarUrl
});
});
it('should return all of a profile', function() {
mockToken().reply(200, TOKEN_GOOD);
@ -125,12 +64,6 @@ describe('/profile', function() {
describe('/email', function() {
var uid = token();
before(function() {
return db.createProfile({
uid: uid,
avatar: avatarUrl
});
});
it('should return an email', function() {
mockToken().reply(200, TOKEN_GOOD);
@ -163,12 +96,6 @@ describe('/email', function() {
describe('/uid', function() {
var uid = token();
before(function() {
return db.createProfile({
uid: uid,
avatar: avatarUrl
});
});
it('should return an uid', function() {
mockToken().reply(200, TOKEN_GOOD);