Exemplo n.º 1
0
    def get(self, typ, vid):
        video = Video.all().filter('typ =', typ).filter('vid =', vid).get()
        if not video:
            video = Video(typ=typ, vid=vid)
            if video:
                video.put()
            else:
                self.error(404)

        cmts = memcache.get(str(video.key().id_or_name()))
        if not cmts:
            cmts = video.comment_set
            memcache.set(str(video.key().id_or_name()), cmts)

        tmpvars = {'comments': cmts}
        self.render('comment.xml', tmpvars)
Exemplo n.º 2
0
  def get(self,typ,vid):
    video = Video.all().filter('typ =',typ).filter('vid =',vid).get()
    if not video:
      video = Video(typ = typ,
                    vid = vid)
      if video:
        video.put()
      else:
        self.error(404)

    cmts = memcache.get(str(video.key().id_or_name()))
    if not cmts:
      cmts = video.comment_set
      memcache.set(str(video.key().id_or_name()),cmts)

    tmpvars = {'comments':cmts}
    self.render('comment.xml',tmpvars)
Exemplo n.º 3
0
def upload():
    try:
        f = request.files["file"]

        key = upload_to_cloud(f)
        video = Video()
        video.key = key
        video.user_id = request.user_id
        video.filename = f.filename

        db.session.add(video)
        db.session.commit()

        video_with_url = {**(video.to_dict()), "url": build_url(video.key)}

        return response(status=constants.SUCCESS,
                        message=constants.UPLOAD_SUCCESS,
                        video=video_with_url)
    except Exception:
        return response(status=constants.ERROR,
                        message=constants.SOMETHING_WENT_WRONG,
                        status_code=422)
Exemplo n.º 4
0
    def post(self, typ, vid):
        now = datetime.now() + timedelta(hours=+8)
        #date check
        date = self.request.get('date')
        try:
            date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
            postdelta = abs(now - date)
        except:  #拒绝不合法的时间格式
            self.response.out.write('busy,code:1')
            return

        #self.response.out.write(str(abs(postdelta.seconds))+'\r\n')#不能给用户看到

        if DELAYCHECK and (postdelta.days != 0 or postdelta.seconds > DELAYMAX
                           ):  #时间有效性检验,如果与服务器间隔大于60s,就为非法
            self.response.out.write('busy,code:2')
            return

        #post interval limitation
        ipstr = self.request.remote_addr
        ip = Ip.all().filter('ip =', ipstr).get()
        if ip:
            delta = now - ip.lastpostdate
            if delta.days == 0 and abs(delta.seconds) < POSTINTERVAL:
                self.response.out.write('busy,code:3')
                return
            else:
                ip.lastpostdate = now
                ip.put()
        else:
            ip = Ip(ip=ipstr, lastpostdate=now)
            ip.put()

        video = Video.all().filter('typ =', typ).filter('vid =', vid).get()
        if not video:
            video = Video(typ=typ, vid=vid)
            if video:
                video.put()
            else:
                self.error(404)

        text = unicode(self.request.get('message')).strip()
        stime = float(self.request.get('playTime'))
        mode = int(self.request.get('mode'))
        fontsize = int(self.request.get('fontsize'))
        color = int(self.request.get('color'))

        cmt = Comment(author_ip=ipstr,
                      text=text,
                      stime=stime,
                      mode=mode,
                      fontsize=fontsize,
                      color=color,
                      cid=video,
                      postdate=(datetime.now() + timedelta(hours=+8)))

        if cmt:
            cmt.put()
            memcache.delete(str(video.key().id_or_name()))
            self.response.out.write('OK')
        else:
            self.response.out.write('Failed')
Exemplo n.º 5
0
  def post(self,typ,vid):
    now = datetime.now() + timedelta(hours=+8)
    #date check
    date = self.request.get('date')
    try:
      date = datetime.strptime(date,'%Y-%m-%d %H:%M:%S')
      postdelta = abs(now - date)
    except:#拒绝不合法的时间格式
      self.response.out.write('busy,code:1')
      return

    #self.response.out.write(str(abs(postdelta.seconds))+'\r\n')#不能给用户看到

    if DELAYCHECK and (postdelta.days != 0 or postdelta.seconds > DELAYMAX):#时间有效性检验,如果与服务器间隔大于60s,就为非法
      self.response.out.write('busy,code:2')
      return


    #post interval limitation
    ipstr = self.request.remote_addr
    ip = Ip.all().filter('ip =',ipstr).get()
    if ip:
      delta = now - ip.lastpostdate
      if delta.days == 0 and abs(delta.seconds) < POSTINTERVAL:
        self.response.out.write('busy,code:3')
        return
      else:
        ip.lastpostdate = now
        ip.put()
    else:
      ip = Ip(ip=ipstr,lastpostdate = now)
      ip.put()
        


    video = Video.all().filter('typ =',typ).filter('vid =',vid).get()
    if not video:
      video = Video(typ = typ,
                    vid = vid)
      if video:
        video.put()
      else:
        self.error(404)

    text = unicode(self.request.get('message')).strip()
    stime = float(self.request.get('playTime'))
    mode = int(self.request.get('mode'))
    fontsize = int(self.request.get('fontsize'))
    color = int(self.request.get('color'))

    cmt = Comment(author_ip=ipstr,
                  text=text,
                  stime=stime,
                  mode=mode,
                  fontsize=fontsize,
                  color=color,
                  cid=video,
                  postdate=(datetime.now() + timedelta(hours=+8))
                  )

    if cmt:
      cmt.put()
      memcache.delete(str(video.key().id_or_name()))
      self.response.out.write('OK')
    else:
      self.response.out.write('Failed')