This reverts commit 01b0e41610
.
This commit is contained in:
Родитель
01b0e41610
Коммит
158eb63a0e
18
docs/API.md
18
docs/API.md
|
@ -84,7 +84,7 @@ curl -v \
|
|||
{
|
||||
"uid": "6d940dd41e636cc156074109b8092f96",
|
||||
"email": "user@example.domain",
|
||||
"avatar": "https://firefoxusercontent.com/a9bff302615cd015692a099f691205cc"
|
||||
"avatar": "https://secure.gravatar.com/avatar/6d940dd41e636cc156074109b8092f96"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -166,27 +166,15 @@ curl -v \
|
|||
"https://profile.accounts.firefox.com/v1/avatar"
|
||||
```
|
||||
|
||||
|
||||
#### Response
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "a9bff302615cd015692a099f691205cc",
|
||||
"avatar": "https://firefoxusercontent.com/a9bff302615cd015692a099f691205cc"
|
||||
"id": "81625c14128d46c2b600e74a017fa4a8",
|
||||
"url": "https://secure.gravatar.com/avatar/6d940dd41e636cc156074109b8092f96"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### Response (no avatar set)
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "00000000000000000000000000000000",
|
||||
"avatar": "https://firefoxusercontent.com/00000000000000000000000000000000"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### POST /v1/avatar/upload
|
||||
|
||||
- scope: `profile:avatar:write`
|
||||
|
|
Двоичные данные
lib/assets/default-profile.png
Двоичные данные
lib/assets/default-profile.png
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 2.5 KiB |
Двоичные данные
lib/assets/default-profile_large.png
Двоичные данные
lib/assets/default-profile_large.png
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 8.0 KiB |
Двоичные данные
lib/assets/default-profile_small.png
Двоичные данные
lib/assets/default-profile_small.png
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 1.3 KiB |
|
@ -133,12 +133,6 @@ const conf = convict({
|
|||
doc: 'Pattern to generate FxA avatar URLs. {id} will be replaced.',
|
||||
default: 'http://127.0.0.1:1112/a/{id}',
|
||||
env: 'IMG_URL'
|
||||
},
|
||||
defaultAvatarId: {
|
||||
default: '00000000000000000000000000000000',
|
||||
doc: 'Default avatar id',
|
||||
env: 'DEFAULT_AVATAR_ID',
|
||||
format: String
|
||||
}
|
||||
},
|
||||
logging: {
|
||||
|
|
|
@ -1,15 +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 config = require('../../config');
|
||||
|
||||
const FXA_URL_TEMPLATE = config.get('img.url');
|
||||
|
||||
function fxaUrl(id) {
|
||||
return FXA_URL_TEMPLATE.replace('{id}', id);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fxaUrl: fxaUrl
|
||||
};
|
|
@ -5,25 +5,19 @@
|
|||
const Joi = require('joi');
|
||||
|
||||
const db = require('../../db');
|
||||
const config = require('../../config');
|
||||
const hex = require('buf').to.hex;
|
||||
const validate = require('../../validate');
|
||||
const logger = require('../../logging')('routes.avatar.get');
|
||||
const avatarShared = require('./_shared');
|
||||
|
||||
const DEFAULT_AVATAR = {
|
||||
avatar: avatarShared.fxaUrl(config.get('img.defaultAvatarId')),
|
||||
id: config.get('img.defaultAvatarId')
|
||||
};
|
||||
|
||||
function avatarOrDefault(avatar) {
|
||||
const EMPTY = Object.create(null);
|
||||
function avatarOrEmpty(avatar) {
|
||||
if (avatar) {
|
||||
return {
|
||||
id: hex(avatar.id),
|
||||
avatar: avatar.url
|
||||
};
|
||||
}
|
||||
return DEFAULT_AVATAR;
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -42,7 +36,7 @@ module.exports = {
|
|||
handler: function avatar(req, reply) {
|
||||
var uid = req.auth.credentials.user;
|
||||
db.getSelectedAvatar(uid)
|
||||
.then(avatarOrDefault)
|
||||
.then(avatarOrEmpty)
|
||||
.done(function (result) {
|
||||
var rep = reply(result);
|
||||
if (result.id) {
|
||||
|
|
|
@ -13,14 +13,15 @@ const img = require('../../img');
|
|||
const notifyProfileUpdated = require('../../updates-queue');
|
||||
const validate = require('../../validate');
|
||||
const workers = require('../../img-workers');
|
||||
const avatarShared = require('./_shared');
|
||||
|
||||
const FXA_PROVIDER = 'fxa';
|
||||
const FXA_URL_TEMPLATE = config.get('img.url');
|
||||
assert(FXA_URL_TEMPLATE.indexOf('{id}') !== -1,
|
||||
'img.url must contain the string "{id}"');
|
||||
const DEFAULT_AVATAR_ID = config.get('img.defaultAvatarId');
|
||||
assert(DEFAULT_AVATAR_ID.length === 32, 'img.default');
|
||||
|
||||
function fxaUrl(id) {
|
||||
return FXA_URL_TEMPLATE.replace('{id}', id);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
auth: {
|
||||
|
@ -49,9 +50,7 @@ module.exports = {
|
|||
handler: function upload(req, reply) {
|
||||
req.server.methods.batch.cache.drop(req, function() {
|
||||
var id = img.id();
|
||||
// precaution to avoid the default id from being overwritten
|
||||
assert(id !== DEFAULT_AVATAR_ID);
|
||||
var url = avatarShared.fxaUrl(id);
|
||||
var url = fxaUrl(id);
|
||||
var uid = req.auth.credentials.user;
|
||||
workers.upload(id, req.payload, req.headers)
|
||||
.then(function save() {
|
||||
|
|
|
@ -3,19 +3,11 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const Hapi = require('hapi');
|
||||
const Boom = require('boom');
|
||||
const path = require('path');
|
||||
const Inert = require('inert');
|
||||
|
||||
const config = require('../config').getProperties();
|
||||
const logger = require('../logging')('server.static');
|
||||
|
||||
const DEFAULT_AVATAR_DIR = path.resolve(__dirname, '..', 'assets');
|
||||
const DEFAULT_AVATAR_ID = config.img.defaultAvatarId;
|
||||
const DEFAULT_AVATAR = path.resolve(DEFAULT_AVATAR_DIR, 'default-profile.png');
|
||||
const DEFAULT_AVATAR_LARGE = path.resolve(DEFAULT_AVATAR_DIR, 'default-profile_large.png');
|
||||
const DEFAULT_AVATAR_SMALL = path.resolve(DEFAULT_AVATAR_DIR, 'default-profile_small.png');
|
||||
|
||||
exports.create = function() {
|
||||
var server = new Hapi.Server({
|
||||
debug: false
|
||||
|
@ -28,26 +20,6 @@ exports.create = function() {
|
|||
port: config.server.port + 1
|
||||
});
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/a/' + DEFAULT_AVATAR_ID + '{type?}',
|
||||
handler: function (request, reply) {
|
||||
switch (request.params.type) {
|
||||
case '':
|
||||
reply.file(DEFAULT_AVATAR);
|
||||
break;
|
||||
case '_small':
|
||||
reply.file(DEFAULT_AVATAR_SMALL);
|
||||
break;
|
||||
case '_large':
|
||||
reply.file(DEFAULT_AVATAR_LARGE);
|
||||
break;
|
||||
default:
|
||||
reply(Boom.notFound());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/a/{id}',
|
||||
|
|
|
@ -13,12 +13,8 @@ const checksum = require('checksum');
|
|||
|
||||
const assert = require('insist');
|
||||
const P = require('../lib/promise');
|
||||
const config = require('../lib/config');
|
||||
const avatarShared = require('../lib/routes/avatar/_shared');
|
||||
const assertSecurityHeaders = require('./lib/util').assertSecurityHeaders;
|
||||
|
||||
const DEFAULT_AVATAR_ID = config.get('img.defaultAvatarId');
|
||||
|
||||
function randomHex(bytes) {
|
||||
return crypto.randomBytes(bytes).toString('hex');
|
||||
}
|
||||
|
@ -77,7 +73,7 @@ describe('/profile', function() {
|
|||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(res.result.uid, USERID);
|
||||
assert.equal(res.result.email, 'user@example.domain');
|
||||
assert.equal(res.result.avatar, avatarShared.fxaUrl(DEFAULT_AVATAR_ID), 'return default avatar');
|
||||
assert.equal(res.result.avatar, null);
|
||||
assertSecurityHeaders(res);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,20 +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 assert = require('insist');
|
||||
const avatarShared = require('../../../lib/routes/avatar/_shared');
|
||||
const config = require('../../../lib/config').getProperties();
|
||||
|
||||
/*global describe,it,beforeEach*/
|
||||
describe('routes/avatar/_shared', function () {
|
||||
|
||||
describe('fxaUrl', function () {
|
||||
|
||||
it('creates a proper avatarUrl', function () {
|
||||
const id = 'foo';
|
||||
assert.equal(avatarShared.fxaUrl(id), config.img.url.replace('{id}', id));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Загрузка…
Ссылка в новой задаче