gpt4 book ai didi

javascript - 如何使用 Meteor Cloudinary 显示另一个用户的个人资料图像项目

转载 作者:行者123 更新时间:2023-12-03 04:35:20 25 4
gpt4 key购买 nike

有 2 个问题。

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

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

更新:Rooms 集合的结构如下:每个房间将包含所有者、接收者、人员:[所有者、接收者] 和 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

publish.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

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;
}
}
});


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

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 });
}
});

最佳答案

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

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

但是您的订阅未传递参数:

self.subscribe('user');

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

此外,您不需要在此处使用 publishComposite,因为您只有一个父级。相反,您可以返回游标数组:

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 参数发布该信息并包括在您的订阅中。在这种特殊情况下,您仍然不需要发布复合。

服务器:

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;
}

关于javascript - 如何使用 Meteor Cloudinary 显示另一个用户的个人资料图像项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43328237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com