leancloud / javascript-sdk Goto Github PK
View Code? Open in Web Editor NEWLeanCloud JavaScript SDK
Home Page: https://docs.leancloud.cn/sdk/storage/guide/js/
License: MIT License
LeanCloud JavaScript SDK
Home Page: https://docs.leancloud.cn/sdk/storage/guide/js/
License: MIT License
保持各个SDK调用云函数一致,有参数req.params.user
同时可以把underscore、Promise等模块从代码库中移除,直接使用第三方模块
这个函数的verify单词错了
对请求频度做限制,每个用户(根据 session 或者 IP 做判断)一个小时内,最多可以请求五次;
用于多字段排序。
ticket=AV.Object.createWithoutData("Ticket", "123");
ticket.fetch().then(function (ticket) {
if (ticket) {
ticket = transformTicket(ticket);
mlog.log('ticket found '+ticket.id);
会打印"ticket found 123"
但get(key)内容为undefined.
在 main.js定义方法
AV.Cloud.define("help", function (request, response) {
console.log('----------', request.params);
response.success("helping~~~!");
});
在app.js的路由方法使用自定义的方法help
app.get('/hello', function(req, res) {
AV.Cloud.run('help', {}, {
success: function (data) {
res.render('hello', { message: 'Congrats, you just set up your app!---' + data });
},
error: function (err) {
res.send(200, 'err' + err.message)
}
})
});
在目录下不带直接任何option运行
avoscloud
访问 localhost:3000/hello, 返回错误
Cloud code not find function named 'help' for app 'my-app-id' on 'production'.
In current SDK there is AV.Query.or but no AV.Query.and. However, in iOS SDK, there is [AVQuery andQueryWithSubqueries:]
当调用AV.Cloud.run()执行云函数时,采用的时POST方法到https://cn.avoscloud.com,导致跨域从而导致调用失败,如图是chrome记录的发包:
如下是我完整的代码:
AV.Cloud.run('saveWechatImageToUsedBook', {
serverId: wechatServerId,
objectId: avosUsedBook.objectId
}, null).done(function () {
alert('AVOS下载图片成功');
}).fail(function (error) {
alert(error.message);
})
用的js-sdk版本是 root.AV.VERSION = "js0.5.1";
你好,我想使用gulp来构建我的前端,但是发现在本地可以全局安装gulp后,运行gulp命令来使gulpfile.js里的东西运行。但是到了线上环境,我不知道该如何使用gulp命令,一路找到这里,说这里可以使用gulp。
但是我想知道我想使用gulp,就一定要使用javascript-sdk 么?
还有其他方式么?
理论上 javascript 的处理方式才是正确的,不过因为目前 API 返回就是错的,只能将错就错。
有用户反馈升级 0.5.0 后有些数据结构发生了变化。
用户代码:
// 是事件流的查询
var query = AV.Status.inboxQuery(AV.User.createWithoutData('_User',userId));
query.include('dynamicNews');
query.include('source');
query.include('dynamicNews.user_id');
query.find().then(function(statuses){
console.dir(statuses[0]);
0.4.7 版本得到的数据结构:
{ data:
{ messageSignature: '44a98c47b02961c95b6347b3975420b0',
messageType: 'newPost',
dynamicNews:
{ tags: [Object],
updatedAt: '2015-03-03T13:12:16.635Z',
clan_ids: [Object],
content: '今天是个好日子。',
objectId: '54f5b330e4b0e5cabd32f386',
createdAt: '2015-03-03T13:12:16.537Z',
type: 2,
duration: 0,
className: 'DynamicNews',
share_url: 'https://hoopeng.avosapps.com/dynamic/54f5b330e4b0e5cabd32f386',
status: 1,
__type: 'Pointer',
user_id: [Object],
position: [Object],
area: '上海市浦东新区张江路368号',
thumbs: [Object] },
inboxType: 'default',
source:
{ __type: 'Pointer',
className: '_User',
objectId: '54b601e1e4b06e1f629b1ddd' },
message: '发布了新的动态' },
inboxType: 'default',
query: null,
id: '54f5b330e4b077bf83981b2a',
createdAt: Tue Mar 03 2015 21:12:16 GMT+0800 (CST),
updatedAt: Tue Mar 03 2015 21:12:16 GMT+0800 (CST),
messageId: 1 }
0.5.0 版得到的数据结构:
{ data:
{ messageSignature: '44a98c47b02961c95b6347b3975420b0',
messageType: 'newPost',
dynamicNews:
{ _serverData: [Object],
_opSetQueue: [Object],
attributes: [Object],
_hashedJSON: [Object],
_escapedAttributes: {},
cid: 'c162',
changed: {},
_silent: {},
_pending: {},
_hasData: true,
_previousAttributes: {},
id: '54f5b330e4b0e5cabd32f386',
createdAt: Tue Mar 03 2015 21:12:16 GMT+0800 (CST),
updatedAt: Tue Mar 03 2015 21:12:16 GMT+0800 (CST) },
inboxType: 'default',
source:
{ _serverData: {},
_opSetQueue: [Object],
attributes: {},
_hashedJSON: {},
_escapedAttributes: {},
cid: 'c164',
changed: {},
_silent: {},
_pending: {},
_hasData: false,
_previousAttributes: {},
id: '54b601e1e4b06e1f629b1ddd' },
message: '发布了新的动态' },
inboxType: 'default',
query: null,
id: '54f5b330e4b077bf83981b2a',
createdAt: Tue Mar 03 2015 21:12:16 GMT+0800 (CST),
updatedAt: Tue Mar 03 2015 21:12:16 GMT+0800 (CST),
messageId: 1 }
我觉得后者应该是正确的,不知道 0.4.7 版本的结果是怎么弄出来的,我自己测试 AV.Query 貌似不能重现,是 AV.Status.inboxQuery
的问题吗?
在JS SDK 的客户端,好像现在只能调用生产环境的
网址是: https://cn.avoscloud.com/docs/js_guide.html
在运行到 alert(monster.strength()); // Displays 200.
这句时,自己试了一些,无论是在html中还是使用node都会报错,
/Users/tsq/my/avos-note/app.js:22
console.log(version.strength());
^
TypeError: Object [object Object] has no method 'strength'
at Object.<anonymous> (/Users/tsq/my/avos-note/app.js:22:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
不过,也确实会这样,monster对象只有一个实例方法hasSuperHumanStrength
和一个属性strength
,
而demo中却把strength
当成了方法去调用, 试了一下,要想成功访问strength
属性需要通过monster.attributes.strength
来访问。
保持和其他 sdk 一致。
ReferenceError: status is not defined
at Object.AV.Status.send (/usr/local/lib/node_modules/avoscloud-code/node_modules/avoscloud-sdk/lib/av.js:8986:24)
at AV.Cloud.define.dataPhotos (cloud/main.js:38:12)
at runFunc (/usr/local/lib/node_modules/avoscloud-code/lib/cloud_code.js:124:24)
at processRequest0 (/usr/local/lib/node_modules/avoscloud-code/lib/cloud_code.js:505:4)
at user.fetch.then.res.send.code (/usr/local/lib/node_modules/avoscloud-code/lib/cloud_code.js:516:5)
at wrappedResolvedCallback (/usr/local/lib/node_modules/avoscloud-code/node_modules/avoscloud-sdk/lib/av.js:3664:38)
at /usr/local/lib/node_modules/avoscloud-code/node_modules/avoscloud-sdk/lib/av.js:3615:26
at Array.forEach (native)
at Object._.each._.forEach [as _arrayEach] (/usr/local/lib/node_modules/avoscloud-code/node_modules/avoscloud-sdk/lib/av.js:95:11)
at _.extend.resolve (/usr/local/lib/node_modules/avoscloud-code/node_modules/avoscloud-sdk/lib/av.js:3614:10)
修改接口,强制要求传入参数 mobilePhoneNumber ,也就是接收到这条校验短信的手机号码
说验证邮箱会回调这个方法,不知道是文档错,还是代码错
https://cn.avoscloud.com/docs/js_guide.html#验证-email
AV.Cloud.define的函数中的res 有success方法但是没有send方法
express js的则相反,两者应该要一样
由用户反馈,比如说这样
query.get(uid, {
udata:obj, //每次get的时候这里是不同的,比如在for循环中给不同的控件赋值的时候放控件引用
success:function(object){
UserLoaded(this.udata) //然后这里用this引用,但是实际上是不行的,有没有等价的办法
}
});
像iOS和android里的curl日志。
就是 find()
只处理结果中第一个元素的版本,对于作者知道最多只有一个结果的情况比较方便,很多类似的库里都有这个函数。
有什么方法更好地来调试,找到问题处吗?
或者提供扩展模块,基于 cookie
版本:0.4.5,0.4.6 都能重现,其他没有尝试
浏览器端使用
重现方式:
创建一个简单测试页面:
<html>
<head>
<script src="av.js"></script>
<script>
AV.initialize("8y5ria0dtbvz7qp6alzy00p9nggky304fafdusfo79fba5sk", "nfkx5k3p7otysvhr2fp84mxl8ggmehu7swyi18auvmrg7kd4");
</script>
</head>
<body>
</body>
</html>
打开页面,并在浏览器控制台 console 进行用户登录操作:
AV.User.logIn('abc', 'abc');
然后刷新页面
然后查看 currentUser,会发现一切 OK
AV.User.current()
但是如果这个时候 更新数据:
AV.User.current().set('foo', 'bar')
AV.User.current().save(null, {})
然后再查看 currentUser 数据就只有 set 进去的属性,而其他属性都没了
AV.User.current()
如果刷新页面更新对象保存是没问题的。
用户反馈
webview 中使用 SDK 的文档,主要补充内容:
1、Android webview 需要开启的设置项目;
2、webview 与 Native 之间的通信方式;
3、开发方式指导;
参考 ticket https://ticket.avosapps.com/tickets/5493e67ae4b036d7cf7978c9/threads?
var assignee=AV.Object.createWithoutData('Admin',assigneeId);
assignee.fetch().then(function(){
里面有个pointer ,assignee有字段client,指向Client表,不知怎样在fetch的时候include上这个字段,获得数据。
现在只能再fetch一次
var client=assignee.get('client');
client.fetch().then(function(){
用户反馈,override 这个方法无效。
findAdmins().then(function(admins){
_.each(admins,function(admin){
admin.set('nickname',admin.get('username'));
});
return AV.Object.saveAll(admins);
});
管理台的数据没有任何更改
是否可以通过服务器端直接取出除重的数据?
1、所有数据接口,只接受用户自定义白名单域的请求,其他来源请求直接拒绝;
2、用户验证相关都只存在 cookie 中,并且 httpOnly;
注,以前不会。
function saveFileThen(req, f){
var attachmentFile = req.files.attachment;
if(attachmentFile && attachmentFile.name!=''){
fs.readFile(attachmentFile.path, function(err, data){
if(err)
return f();
var base64Data = data.toString('base64');
var theFile = new AV.File(attachmentFile.name, {base64: base64Data});
theFile.save().then(function(theFile){
f(theFile);
}, function(err){
f();
});
});
}else{
f();
}
}
Mon, 18 Aug 2014 03:06:57 GMT uncaughtException: URI malformed
URIError: URI malformed
at decodeURIComponent (native)
at decodeBase64 (/usr/local/lib/node_modules/avoscloud-code/node_modules/avoscloud-sdk/lib/av.js:3865:12)
at Object.AV.File (/usr/local/lib/node_modules/avoscloud-code/node_modules/avoscloud-sdk/lib/av.js:4150:29)
at /home/lzw/clojure/avoscloud-ticket/cloud/app.js:108:21
at fs.js:268:14
at /usr/local/lib/node_modules/avoscloud-code/node_modules/fstream/node_modules/graceful-fs/graceful-fs.js:104:5
at Object.oncomplete (fs.js:107:15)
AVFile 增加 ACL 属性,并且在创建七牛 token 的时候传入 ACL属性。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.