From ce405fc4f6cc773e73ac83a651594d61f2ff9f71 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 28 Jul 2018 07:52:48 +0900 Subject: [PATCH] Fix #2007 --- src/models/user.ts | 21 ++++++++++----------- src/server/api/endpoints/i/update.ts | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/models/user.ts b/src/models/user.ts index 8681b5b0c..fdbb245fa 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -50,6 +50,7 @@ type IUserBase = { avatarUrl?: string; bannerUrl?: string; wallpaperId: mongo.ObjectID; + wallpaperUrl?: string; data: any; description: string; pinnedNoteId: mongo.ObjectID; @@ -400,21 +401,19 @@ export const pack = ( } if (_user.avatarUrl == null) { - _user.avatarUrl = _user.avatarId != null - ? `${config.drive_url}/${_user.avatarId}` - : `${config.drive_url}/default-avatar.jpg`; + _user.avatarUrl = `${config.drive_url}/default-avatar.jpg`; + + // 互換性のため + if (_user.avatarId) { + _user.avatarUrl = `${config.drive_url}/${_user.avatarId}`; + } } - if (_user.bannerUrl == null) { - _user.bannerUrl = _user.bannerId != null - ? `${config.drive_url}/${_user.bannerId}` - : null; + // 互換性のため + if (_user.bannerId && _user.bannerUrl == null) { + _user.bannerUrl = `${config.drive_url}/${_user.bannerId}`; } - _user.wallpaperUrl = _user.wallpaperId != null - ? `${config.drive_url}/${_user.wallpaperId}` - : null; - if (!meId || !meId.equals(_user.id) || !opts.detail) { delete _user.avatarId; delete _user.bannerId; diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index 4002bcdc3..019c8281a 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -4,6 +4,7 @@ import event from '../../../../stream'; import DriveFile from '../../../../models/drive-file'; import acceptAllFollowRequests from '../../../../services/following/requests/accept-all'; import { IApp } from '../../../../models/app'; +import config from '../../../../config'; export const meta = { desc: { @@ -81,7 +82,11 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a _id: avatarId }); - if (avatar != null && avatar.metadata.properties.avgColor) { + if (avatar == null) return rej('avatar not found'); + + updates.avatarUrl = avatar.metadata.url || `${config.drive_url}/${avatar._id}`; + + if (avatar.metadata.properties.avgColor) { updates.avatarColor = avatar.metadata.properties.avgColor; } } @@ -91,7 +96,11 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a _id: bannerId }); - if (banner != null && banner.metadata.properties.avgColor) { + if (banner == null) return rej('banner not found'); + + updates.bannerUrl = banner.metadata.url || `${config.drive_url}/${banner._id}`; + + if (banner.metadata.properties.avgColor) { updates.bannerColor = banner.metadata.properties.avgColor; } } @@ -101,7 +110,11 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a _id: wallpaperId }); - if (wallpaper != null && wallpaper.metadata.properties.avgColor) { + if (wallpaper == null) return rej('wallpaper not found'); + + updates.wallpaperUrl = wallpaper.metadata.url || `${config.drive_url}/${wallpaper._id}`; + + if (wallpaper.metadata.properties.avgColor) { updates.wallpaperColor = wallpaper.metadata.properties.avgColor; } }