如何使用Meteor Cloudinary显示其他用户的个人资料图像项目 [英] How to show another user's profile image item with Meteor Cloudinary

查看:107
本文介绍了如何使用Meteor Cloudinary显示其他用户的个人资料图像项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Theres 2问题。

Theres 2 issues.

首先:一个房间开始后,其中有2个人,所有者和接收者。我无法在房间列表中显示其他人的个人资料图片。我可以看到我自己的图像是通过Cloudinary上传的,保存在profile - > profilepicId下作为Id,然后生成一个图像。

Firstly: Once a room is started, theres 2 people in it, owner and receiver. I am unable to display the other person's profile image in the list of rooms. I can see my own image thats is uploaded via Cloudinary, saved under profile --> profilepicId as an Id which then generates an image.

其次:当我转到用户页面时,我无法检索用户的帖子。服务器抛出id匹配错误。有时它也会挂起,当我转到我的个人资料页面时,我将无法查看自己的帖子。

Secondly: I cannot retrieve posts of a user when I go to user's page. Server throws a id match error. Sometimes it also hangs and I will not be able to view my own posts when i go to my profile page.

更新:Rooms集合的结构如下:每个房间将包含所有者,接收者,人员:[所有者,接收者]和roomId。

Update: The Rooms collection are structure as follows: Each room will contain owner, receiver, people:[ owner , receiver ] and roomId.

服务器错误


> Exception from sub user id JS9gKeT4sXNDCwip6 Error: Match error:
> Expected string, got undefined I20170410-23:28:59.972(8)?     at
> exports.check (packages/check/match.js:34:1)
> I20170410-23:28:59.972(8)?     at Subscription.<anonymous>
> (server/server.js:88:2) I20170410-23:28:59.973(8)?     at
> (packages/reywood_publish-composite/packages/reywood_publish-composite.js:440:1)
> I20170410-23:28:59.973(8)? at Subscription._handler
> (packages/reywood_publish-composite/packages/reywood_publish-composite.js:408:1)
> at Object.exports.Match._failIfArgumentsAreNotAllChecked


发布。 js

Meteor.publish('userDetails', function() {
   var fields = { username: 1, emails   : 1, profile : 1, md5hash : 1 };
   return Meteor.users.find( {}, { fields: fields });
});
Meteor.publishComposite('user', function (_id) {
  check(_id, String);
  //if (!_id) return this.ready(); doesnt help remove error
  return {
     find: function() {
        return Meteor.users.find({ _id: _id }, { 
          fields: { username: 1, emails: 1, profile : 1, md5hash: 1}
        });
     }, children: [....]
    };
 });

roomCollection.js - 即时通讯使用dburles:collection-helpers

roomCollection.js - im using dburles:collection-helpers

Rooms.helpers({ 
   chatPerson: function(){
      if( this.owner === Meteor.userId() ) {
         return Meteor.users.findOne({ _id: this.receiver }).username; 
      } else {
         return Meteor.users.findOne({ _id: this.owner }).username;
      }
   }
});



我可以看到用户的个人资料图片,但不能看到特定的帖子用户+服务器匹配错误。


I can see the user's profile image but not the posts of a specific user + server match error.

user.html

{{#with user}}
    {{#if profile.profilepicId}}  
      <img src="....."> <!-- can see profile pic --> 
    {{/if}}
    {{#each posts}}     <!-- cannot see posts + server match error --> 
       {{> postItem}}
    {{/each}}
{{/with}}

user.js

Template.usersShow.onCreated(function(){
   var self = this;
   self.autorun(function(){
      self.subscribe('rooms');
      self.subscribe('user', Router.current().params._id);
   });
});
Template.usersShow.helpers({
   posts: function () {
      return Posts.find({ userId: Router.current().params._id });
   }
});


推荐答案

您的出版物需要一个参数:

Your publication expects a parameter:

Meteor.publishComposite('user', function (_id) { ... })

但您的订阅未通过参数:

But your subscription is not passing a param:

self.subscribe('user');

现在,应该从不传递当前用户的 _id 来自客户端,因为它不受信任 - 它可能是一个欺骗的值,无论如何它都可以在服务器上使用。

Now, one should never pass the current user's _id from the client as it is not trusted - it could be a spoofed value and it's available on the server anyway.

你也不要这里需要使用 publishComposite 因为你只有一个父母。相反,你可以返回一个游标数组:

Also you don't need to use publishComposite here because you only ever have one parent. Instead you can return an array of cursors:

Meteor.publish('me', () => {   
  if (!this.userId) this.ready(); // since the rest is pointless
  else return [
     Meteor.users.find(this.userId, { 
       fields: { username: 1, emails: 1, profile : 1, md5hash: 1}
     }), 
     Posts.find({ userId: this.userId })
  ];
 });

如果您需要在客户端上查看其他用户的详细信息然后你需要发布一个 _id 参数在你的订阅中包含它。在这种特殊情况下,您仍然不需要发布复合。

If you need to see the details of a different user on the client then you need to publish that with an _id parameter and include that in your subscription. You still don't need publish-composite in this particular case.

服务器:

Meteor.publish('otherUser', (_id) => {   
  if (!this.userId) this.ready();
  else {
    check(_id,String);
    return [
      Meteor.users.find(_id, { 
        fields: { username: 1, emails: 1, profile : 1, md5hash: 1}
      }), 
      Posts.find({ userId: _id })
    ];
   }
 });

客户:

self.subscribe('otherUser',otherUserId); // you must pass a param

你也可以简化:

chatPersonId: function(){
  if( this.owner === Meteor.userId() ) {
     return Meteor.users.findOne({ _id: this.receiver })._id;
  } else {
     return Meteor.users.findOne({ _id: this.owner })._id;
  }
},

下至:

chatPersonId() {
  return this.owner === Meteor.userId() ? this.receiver : this.owner;
}

这篇关于如何使用Meteor Cloudinary显示其他用户的个人资料图像项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆