How to use leancloud-storage - 10 common examples

To help you get started, we’ve selected a few leancloud-storage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zry656565 / Hit-Kounter-LC / jobs / calc-site-views.js View on Github external
'use strict'

const AV = require('leancloud-storage')
const schedule = require('node-schedule')

const APP_ID = 'yzbpXQpXf1rWVRfAAM8Durgh-gzGzoHsz'
const APP_KEY = '020bjTvbiVinVQ21YtWAJ9t8'

AV.init({
  appId: APP_ID,
  appKey: APP_KEY
})

const Site = AV.Object.extend('Site')

let j = schedule.scheduleJob('* */4 * * *', calc); // every 4 hours

function calc() {
  let counter = {}

  let query = new AV.Query('Page')
  query.each((page) => {
    let d = page.get('domain')
    if (counter[d]) counter[d] += page.get('count')
    else counter[d] = page.get('count')
  }).then(() => {
    console.log('Collect all pages.')
    for (let domain in counter) {
      if (counter.hasOwnProperty(domain)) {
        let siteView = counter[domain]
github ant-design / ant-design-landing / site / shared / leancloud.js View on Github external
import AV from 'leancloud-storage';

export const appId = 'ogaJShC9qJERt8LqGO80z2pO-gzGzoHsz';
export const appKey = '8e5H5xBF86hI9vItQI1pt4kP';

AV.init({
  appId,
  appKey,
  // serverURLs: 'https://avoscloud.com',
  serverURLs: 'https://ogajshc9.lc-cn-n1-shared.com',
});

export default AV;
github leancloud / leanmessage-demo / src / index.js View on Github external
import runBlock from './index.run.js';

import reverseInfiniteListDirective from './app/components/reverse-infinite-list/reverse-infinite-list.directive.js';
import messageDirective from './app/components/message/message.directive.js';

import userService from './app/components/user/user.service.js';
import loginController from './app/login/login.controller.js';
import loggingController from './app/login/logging.controller.js';
import convController from './app/conversation/conversation.controller.js';
import convMsgController from './app/conversation/conversationMessage/conversation.message.controller.js';

export const app = 'leanMessage';
const appId = 'm7baukzusy3l5coew0b3em5uf4df5i2krky0ypbmee358yon';
const appKey = '2e46velw0mqrq3hl2a047yjtpxn32frm0m253k258xo63ft9';

AV.init({appId, appKey});

angular
  .module(app, ['ui.router', 'ngMaterial'])
  .config(routesConfig)
  .config($mdThemingProvider => {
    'ngInject';
    $mdThemingProvider.theme('default')
      .primaryPalette('blue')
      .accentPalette('blue-grey');
  })
  .factory('LeanRT', () => {
    const LeanRT = {};
    const realtime = new Realtime({
      appId,
      appKey,
      // server: 'rtm51',
github jirengu-inc / jrg-project-5 / step-5 / app.js View on Github external
saveTodos: function(){
      let dataString = JSON.stringify(this.todoList)
      var AVTodos = AV.Object.extend('AllTodos');
      var avTodos = new AVTodos();
      var acl = new AV.ACL()
      acl.setReadAccess(AV.User.current(),true) // 只有这个 user 能读
      acl.setWriteAccess(AV.User.current(),true) // 只有这个 user 能写

      avTodos.set('content', dataString);
      avTodos.setACL(acl) // 设置访问控制
      avTodos.save().then((todo) =>{
        this.todoList.id = todo.id  // 一定要记得把 id 挂到 this.todoList 上,否则下次就不会调用 updateTodos 了
        console.log('保存成功');
      }, function (error) {
        alert('保存失败');
      });
    },
    saveOrUpdateTodos: function(){
github liangtongzhuo / vscodechina / src / js / login / index.js View on Github external
_clicRegister(e) {
    if (!this.state.buttonLogin) {
      this._snackBarOpen('请在本页面填写「账号」与「密码」再点击注册啦~', 5000)
      return
    }
    this.setState({ progressShow: true })
    const mail = this.state.mail
    const password = this.state.password
    const user = new AV.User()
    user.setUsername(mail)
    user.setEmail(mail)
    user.setPassword(password)
    user.set('name', mail.split('@')[0])
    user.signUp().then(loginedUser => {
      this.props.history.push('/')
    }).catch(error => {
      this.setState({ progressShow: false })
      if (error.code === 203)
        return this._snackBarOpen('邮箱已被注册,是不是你忘记密码了?')
      if (error.code === 125)
        return this._snackBarOpen('电子邮箱地址无效,不要骗我')
      return this._snackBarOpen('网络有些问题~')
    })
  }
  // 切换找回密码与登陆界面
github liangtongzhuo / vscodechina / src / js / component / message / index.js View on Github external
this._snackBarOpen('哎~,你忘记登陆了耶')
      return
    }

    const messages = this.state.messages
    const bool = messages[index].likeBool
    const like = messages[index].get('like')
    messages[index].likeBool = !bool
    if (bool) {
      messages[index].set('like', like - 1);
    } else {
      messages[index].set('like', like + 1);
    }
    this.setState({ messages })
    const id = this.state.messages[index].id
    AV.Cloud.run('messageLike', { id }).then(result => {
    }).catch(err => {
      this._snackBarOpen('讨厌,网络错误了')
      console.log(err)
    })
  }
  // 回复
github liangtongzhuo / vscodechina / src / js / oauth / index.js View on Github external
_oauth() {
    const { code, state } = this.state
      if (!code) return window.location.href='/'      
    // 传送 code,换取登陆信息。
    AV.Cloud.run('gitHubOauth', {
      code,
      state
    }).then(result => {
      // 登陆
      return AV.User.signUpOrlogInWithAuthData({
        'uid': result.uid + '',
        'access_token': result.access_token,
      }, 'github')
    }).then(_ => {
      this.setState({ progressShow: false })        
      window.location.href='/'      
  
    }).catch(err => {
      this.setState({ progressShow: false, error: true })
      this._snackBarOpen('好奇怪耶~,获取不到你的 GitHub 交友信息~', 5000)
      console.log(err)
github zxj963577494 / OverWatchTeams / src / services / leanclound / teams.js View on Github external
export function getHomeTeamDetail(payload) {
  const { objectId } = payload
  const query = new AV.Query('Teams')
  return query.get(objectId).then(function(result) {
    return result.toJSON()
  })
  // const { objectId } = payload
  // const team = AV.Object.createWithoutData('Teams', objectId)
  // const query = new AV.Query('UserTeamMap')
  // query.equalTo('team', team)
  // query.descending('createdAt')
  // query.include('team')
  // query.include('user')
  // query.include('user.userinfo')
  // return query.first().then(function(UserTeamMap) {
  //   let teaminfo = UserTeamMap[0].get('team').toJSON()
  //   teaminfo = { ...teaminfo, members: members }
  //   UserTeamMap.forEach(function(item, i, a) {
  //     const userid = item.get('user').id
github zxj963577494 / OverWatchTeams-React-Native-Expo / src / services / leanclound / teams.js View on Github external
export function cerateTeam(payload, currentUser) {
  const teams = new AV.Object('Teams')
  for (let key of Object.keys(payload)) {
    teams.set(key, payload[key])
  }
  // 默认不置顶
  teams.set('stick', 0)
  teams.set('show', 1)
  if (!payload['avatar']) {
    teams.set('avatar', config.BASE_PIC_URL + '/logo.png')
  }

  const userTeamMap = new AV.Object('UserTeamMap')
  userTeamMap.set('user', currentUser)
  userTeamMap.set('team', teams)
  userTeamMap.set('leader', true)

  var acl = new AV.ACL()
  acl.setPublicReadAccess(true)
  acl.setWriteAccess(AV.User.currentAsync(), true)

  userTeamMap.setACL(acl)

  return userTeamMap.save().then(function(result) {
    return result.get('team').toJSON()
  })
}
github zxj963577494 / OverWatchTeams / src / services / leanclound / teams.js View on Github external
export function cerateTeam(payload) {
  const teams = new AV.Object('Teams')
  for (let key of Object.keys(payload)) {
    teams.set(key, payload[key])
  }
  // 默认不置顶
  teams.set('stick', 0)
  teams.set('show', 1)
  if (!payload['avatar']) {
    teams.set('avatar', config.BASE_PIC_URL + '/logo.png')
  }

  const user = getCurrentUser()

  const userTeamMap = new AV.Object('UserTeamMap')
  userTeamMap.set('user', user)
  userTeamMap.set('team', teams)
  userTeamMap.set('leader', true)

  var acl = new AV.ACL()
  acl.setPublicReadAccess(true)
  acl.setWriteAccess(AV.User.current(), true)

  userTeamMap.setACL(acl)

  return userTeamMap.save().then(function(result) {
    return result.get('team').toJSON()
  })
}