yusuketk 5 лет назад
Родитель
Сommit
9b130abd47
2 измененных файлов с 13 добавлено и 10 удалено
  1. 12 9
      src/server/models/user.js
  2. 1 1
      src/server/service/passport.js

+ 12 - 9
src/server/models/user.js

@@ -225,6 +225,7 @@ module.exports = function(crowi) {
 
   userSchema.methods.updateImage = async function(attachment) {
     this.imageAttachment = attachment;
+    this.imageUrlCached = await this.generateImageUrlCached();
     return this.save();
   };
 
@@ -240,6 +241,12 @@ module.exports = function(crowi) {
     }
 
     this.imageAttachment = undefined;
+    this.imageUrlCached = await this.generateImageUrlCached();
+    return this.save();
+  };
+
+  userSchema.methods.updateImageUrlCached = async function() {
+    this.imageUrlCached = await this.generateImageUrlCached();
     return this.save();
   };
 
@@ -249,19 +256,15 @@ module.exports = function(crowi) {
       const hash = md5(email.trim().toLowerCase());
       this.imageUrlCached = `https://gravatar.com/avatar/${hash}`;
     }
-    else if (this.image) {
-      this.imageUrlCached = this.image;
+    if (this.image) {
+      return this.image;
     }
-    else if (this.imageAttachment) {
+    if (this.imageAttachment) {
       const Attachment = crowi.model('Attachment');
       const imageAttachment = await Attachment.findById(this.imageAttachment);
-      this.imageUrlCached = imageAttachment.filePathProxied;
-    }
-    else {
-      this.imageUrlCached = '/images/icons/user.svg';
+      return imageAttachment.filePathProxied;
     }
-
-    return this.save();
+    return '/images/icons/user.svg';
   };
 
   userSchema.methods.updateGoogleId = function(googleId, callback) {

+ 1 - 1
src/server/service/passport.js

@@ -855,7 +855,7 @@ class PassportService {
           throw new Error('user not found');
         }
         if (!user.imageUrlCached) {
-          await user.generateImageUrlCached();
+          await user.updateImageUrlCached();
         }
         done(null, user);
       }