Beispiel #1
0
    def esure(self, req, oid, body=None):
        """
        这个接口由客户端调用
        """
        oid = int(oid)
        now = int(time.time() * 1000)
        otime = uuidutils.Gprimarykey.timeformat(oid)
        if (now - otime) > weiXinApi.overtime * 2 or otime > now:
            raise InvalidArgument('Order id error or overtime')

        session = endpoint_session(readonly=True)  # 注意主从不同步的可能
        query = model_query(session,
                            RechargeLog,
                            filter=RechargeLog.oid == oid)
        recharge = query.one_or_none()
        if recharge:
            return resultutils.results(result='esure orde success',
                                       data=[
                                           dict(oid=oid,
                                                coins=recharge.gift +
                                                recharge.coin,
                                                money=recharge.money)
                                       ])
        session = endpoint_session()
        query = model_query(session, Order, filter=Order.oid == oid)
        order = query.one()
        serial, extdata = weiXinApi.esure_order(order)
        self.record(session, order, serial, extdata)
        return resultutils.results(result='esure orde success',
                                   data=[
                                       dict(oid=oid,
                                            coins=order.gift + order.coin,
                                            money=order.money)
                                   ])
Beispiel #2
0
    def new(self, req, body=None):
        """发起订单"""
        body = body or {}
        if not isinstance(body, dict):
            raise InvalidArgument(
                'Http body not json or content type is not application/json')
        jsonutils.schema_validate(body, NEWPAYMENT)
        money = body.get('money')
        uid = body.get('uid')
        oid = int(body.get('oid'))
        cid = body.get('cid')
        chapter = body.get('chapter')
        cancel_url = body.get('url')

        now = int(time.time() * 1000)
        otime = uuidutils.Gprimarykey.timeformat(oid)
        if (now - otime) > 600000 or otime > now:
            LOG.debug('Oder time %d, now %d' % (otime, now))
            raise InvalidArgument('Order id error')

        serial = paypalApi.payment(money, cancel_url)
        session = endpoint_session()
        coins = self.order(session, paypalApi, serial, uid, oid, money, cid,
                           chapter)
        return resultutils.results(result='create paypal payment success',
                                   data=[
                                       dict(paypal=dict(paymentID=serial),
                                            oid=oid,
                                            coins=coins,
                                            money=money)
                                   ])
Beispiel #3
0
 def show(self, req, oid, body=None):
     """订单详情"""
     body = body or {}
     oid = int(oid)
     session = endpoint_session(readonly=True)
     query = model_query(session, Order, filter=Order.oid == oid)
     order = query.one()
     return resultutils.results(
         result='show order success',
         data=[
             dict(
                 oid=order.oid,
                 sandbox=order.sandbox,
                 uid=order.uid,
                 coins=order.coins,
                 gifts=order.gifts,
                 coin=order.coin,
                 gift=order.gift,
                 money=order.money,
                 platform=order.platform,
                 serial=order.serial,
                 time=order.time,
                 cid=order.cid,
                 chapter=order.chapter,
                 ext=jsonutils.loads_as_bytes(order.ext)
                 if order.ext else None,
             )
         ])
Beispiel #4
0
 def orders(self, req, uid, body=None):
     """用户订单查询"""
     uid = int(uid)
     session = endpoint_session(readonly=True)
     query = model_query(session, Order, filter=Order.uid == uid)
     query = query.order_by(Order.oid.desc())
     return resultutils.results(
         result='show order of user success',
         data=[
             dict(
                 oid=order.oid,
                 sandbox=order.sandbox,
                 uid=order.uid,
                 coins=order.coins,
                 gifts=order.gifts,
                 coin=order.coin,
                 gift=order.gift,
                 money=order.money,
                 platform=order.platform,
                 serial=order.serial,
                 time=order.time,
                 cid=order.cid,
                 chapter=order.chapter,
                 ext=jsonutils.loads_as_bytes(order.ext)
                 if order.ext else None,
             ) for order in query
         ])
Beispiel #5
0
    def index(self, req, body=None):
        """列出订单"""
        body = body or {}
        session = endpoint_session(readonly=True)
        sandbox = int(body.pop('sandbox', False))
        platform = body.pop('platform', None)
        oid = body.pop('oid', None)

        filters = [Order.sandbox == sandbox]
        if platform:
            filters.insert(0, Order.platform == platform)
        if oid:
            filters.insert(0, Order.oid < oid)
        filters = filters[0] if len(filters) == 1 else and_(*filters)

        ret_dict = resultutils.bulk_results(session,
                                            model=Order,
                                            columns=[
                                                Order.oid,
                                                Order.platform,
                                                Order.uid,
                                                Order.coin,
                                                Order.gift,
                                                Order.money,
                                                Order.platform,
                                                Order.time,
                                            ],
                                            counter=Order.oid,
                                            order=Order.oid,
                                            desc=True,
                                            filter=filters,
                                            limit=1000)
        return ret_dict
Beispiel #6
0
    def index(self, req, body=None):
        """列出漫画"""
        body = body or {}
        cid = body.get('cid')
        session = endpoint_session(readonly=True)
        filters = []
        if cid:
            filters.insert(0, Comic.cid < cid)
        filters = filters[0] if len(filters) == 1 else and_(*filters)

        ret_dict = resultutils.bulk_results(session,
                                            model=Comic,
                                            columns=[
                                                Comic.cid,
                                                Comic.name,
                                                Comic.author,
                                                Comic.type,
                                                Comic.region,
                                                Comic.point,
                                                Comic.last,
                                                Comic.ext,
                                                Comic.lastup,
                                            ],
                                            counter=Comic.cid,
                                            order=Comic.cid,
                                            desc=True,
                                            filter=filters,
                                            limit=1000)
        return ret_dict
Beispiel #7
0
 def recharges(self, req, uid, body=None):
     """用户订单列表"""
     body = body or {}
     uid = int(uid)
     session = endpoint_session(readonly=True)
     query = model_query(session,
                         RechargeLog,
                         filter=RechargeLog.uid == uid)
     query = query.order_by(RechargeLog.oid.desc())
     return resultutils.results(
         result='show user recharge log success',
         data=[
             dict(
                 oid=relog.oid,
                 sandbox=relog.sandbox,
                 uid=relog.uid,
                 coins=relog.coins,
                 gifts=relog.gifts,
                 coin=relog.coin,
                 gift=relog.gift,
                 money=relog.money,
                 platform=relog.platform,
                 serial=relog.serial,
                 time=relog.time,
                 cid=relog.cid,
                 chapter=relog.chapter,
                 ext=jsonutils.loads_as_bytes(relog.ext)
                 if relog.ext else None,
             ) for relog in query
         ])
Beispiel #8
0
 def show(self, req, uid, body=None):
     """列出用户信息"""
     uid = int(uid)
     session = endpoint_session(readonly=True)
     query = model_query(session, User, filter=User.uid == uid)
     joins = joinedload(User.books, innerjoin=False)
     query = query.options(joins)
     user = query.one()
     return resultutils.results(result='show user success',
                                data=[
                                    dict(
                                        name=user.name,
                                        uid=user.uid,
                                        offer=user.offer,
                                        coins=user.coins,
                                        gifts=user.gifts,
                                        status=user.status,
                                        regtime=user.regtime,
                                        books=[
                                            dict(cid=comic.cid,
                                                 name=comic.name,
                                                 author=comic.author,
                                                 time=comic.time)
                                            for comic in user.books
                                        ],
                                        owns=[
                                            dict(cid=own.cid,
                                                 chapter=own.chapter)
                                            for own in user.owns
                                        ],
                                    )
                                ])
Beispiel #9
0
 def create(self, req, body=None):
     """用户注册"""
     body = body or {}
     session = endpoint_session()
     name = body.get('name')
     passwd = body.get('passwd')
     salt = ''.join(random.sample(string.lowercase, 6))
     user = User(name=name,
                 salt=salt,
                 passwd=digestutils.strmd5(salt + passwd),
                 regtime=int(time.time()))
     session.add(user)
     try:
         session.flush()
     except DBDuplicateEntry:
         return resultutils.results(result='user name duplicate',
                                    resultcode=manager_common.RESULT_ERROR)
     token = TokenProvider.create(req, dict(uid=user.uid, name=user.name),
                                  3600)
     return resultutils.results(result='crate user success',
                                data=[
                                    dict(token=token,
                                         uid=user.uid,
                                         name=user.name,
                                         coins=(user.coins + user.gifts),
                                         platforms=Platforms,
                                         one=max(0, CF.one - user.offer))
                                ])
Beispiel #10
0
 def show(self, req, oid, body=None):
     """完成订单详情"""
     body = body or {}
     oid = int(oid)
     session = endpoint_session(readonly=True)
     query = model_query(session,
                         RechargeLog,
                         filter=RechargeLog.oid == oid)
     relog = query.one()
     return resultutils.results(
         result='show recharge log success',
         data=[
             dict(
                 oid=relog.oid,
                 sandbox=relog.sandbox,
                 uid=relog.uid,
                 coins=relog.coins,
                 gifts=relog.gifts,
                 coin=relog.coin,
                 gift=relog.gift,
                 money=relog.money,
                 platform=relog.platform,
                 serial=relog.serial,
                 time=relog.time,
                 cid=relog.cid,
                 chapter=relog.chapter,
                 ext=jsonutils.loads_as_bytes(relog.ext)
                 if relog.ext else None,
             )
         ])
Beispiel #11
0
 def show(self, req, mid, body=None):
     """列出用户信息"""
     mid = int(mid)
     session = endpoint_session(readonly=True)
     query = model_query(session, Manager, filter=Manager.uid == mid)
     manager = query.one()
     sopce = msgpack.unpackb(manager.sopce) if manager.sopce else []
     return resultutils.results(
         result='show manager success',
         data=[dict(name=manager.name, status=manager.status, sopce=sopce)])
Beispiel #12
0
    def cover(self, req, cid, body=None):
        """上传封面"""
        cid = int(cid)
        jsonutils.schema_validate(body, COVERUPLOAD)
        timeout = body.get('timeout', 20)
        fileinfo = body.get('fileinfo')

        comic_path = self.comic_path(cid)

        logfile = '%d.conver.%d.log' % (int(time.time()), cid)
        logfile = os.path.join(self.logdir, logfile)
        tmpfile = 'main.%d.pic' % int(time.time())
        fileinfo.update({'overwrite': tmpfile})
        tmpfile = os.path.join(comic_path, tmpfile)
        if os.path.exists(tmpfile):
            raise exceptions.ComicUploadError('Upload cover file fail')

        session = endpoint_session(readonly=True)
        query = model_query(session, Comic, filter=Comic.cid == cid)
        comic = query.one()
        rename = 'main.%s' % comic.ext

        port = max(WSPORTS)
        WSPORTS.remove(port)

        def _exitfunc():
            WSPORTS.add(port)
            if not os.path.exists(tmpfile):
                LOG.error('comic cover file %s not exist' % tmpfile)
            else:
                LOG.info('Call shell command convert')
                convert.convert_cover(tmpfile, rename=rename, logfile=logfile)
                LOG.info('Convert execute success')

        ws = LaunchRecverWebsocket(WEBSOCKETPROC)
        try:
            uri = ws.upload(user=CF.user,
                            group=CF.group,
                            ipaddr=CF.ipaddr,
                            port=port,
                            rootpath=comic_path,
                            fileinfo=fileinfo,
                            logfile=logfile,
                            timeout=timeout)
        except Exception:
            WSPORTS.add(port)
            return resultutils.results(
                result='upload cover get websocket uri fail',
                resultcode=manager_common.RESULT_ERROR)
        else:
            ws.asyncwait(exitfunc=_exitfunc)

        return resultutils.results(
            result='upload cover get websocket uri success', data=[uri])
Beispiel #13
0
 def coins(self, req, uid, body=None):
     """用户自查余额"""
     session = endpoint_session(readonly=True)
     query = model_query(session, User, filter=User.name == uid)
     user = query.one()
     return resultutils.results(result='login success',
                                data=[
                                    dict(name=user.name,
                                         uid=user.uid,
                                         coins=(user.coins + user.gifts))
                                ])
Beispiel #14
0
 def books(self, req, uid, body=None):
     """列出收藏的漫画"""
     uid = int(uid)
     session = endpoint_session(readonly=True)
     query = model_query(session, UserBook, filter=UserBook.uid == uid)
     return resultutils.results(result='get book success',
                                data=[
                                    dict(cid=book.cid,
                                         name=book.name,
                                         author=book.author,
                                         ext=book.ext) for book in query
                                ])
Beispiel #15
0
 def owns(self, req, uid, body=None):
     """列出已经购买的漫画"""
     uid = int(uid)
     session = endpoint_session(readonly=True)
     query = model_query(session, UserOwn, filter=UserOwn.uid == uid)
     return resultutils.results(result='get owns comics success',
                                data=[
                                    dict(cid=own.cid,
                                         ext=own.ext,
                                         uid=own.uid,
                                         chapter=own.chapter)
                                    for own in query
                                ])
Beispiel #16
0
    def notify(self, req, oid, body=None):
        body = body or {}
        if not isinstance(body, dict):
            raise InvalidArgument(
                'Http body not json or content type is not application/json')

        oid = int(oid)
        now = int(time.time() * 1000)
        otime = uuidutils.Gprimarykey.timeformat(oid)
        if (now - otime) > 600000 or otime > now:
            raise InvalidArgument('Order id error or more the 600s')

        jsonutils.schema_validate(body, ESUREPAY)

        paypal = body.get('paypal')
        uid = body.get('uid')

        session = endpoint_session()
        query = model_query(session, Order, filter=Order.oid == oid)
        order = query.one()
        if order.uid != uid:
            raise InvalidArgument('User id not the same')
        if order.serial != paypal.get('paymentID'):
            raise InvalidArgument('paymentID not the same')

        def paypal_execute(extdata=None):
            LOG.info('Call paypalApi execute order')
            paypalApi.execute(paypal, order.money)
            return extdata

        try:
            self.record(session,
                        order,
                        None,
                        None,
                        on_transaction_call=paypal_execute)
        except DBError:
            LOG.error('Paypal save order %d to database fail' % order.oid)
        except exceptions.EsureOrderError:
            LOG.error('Call Paypal execute order fail')
            raise

        return resultutils.results(result='notify orde success',
                                   data=[
                                       dict(paypal=dict(
                                           paymentID=paypal.get('paymentID'),
                                           payerID=paypal.get('payerID')),
                                            oid=oid,
                                            coins=order.gift + order.coin,
                                            money=order.money)
                                   ])
Beispiel #17
0
 def unmark(self, req, cid, uid, body=None):
     """取消收藏"""
     cid = int(cid)
     uid = int(uid)
     session = endpoint_session()
     query = model_query(session,
                         UserBook,
                         filter=and_(UserBook.uid == uid,
                                     UserBook.cid == cid))
     book = query.one_or_none()
     if book:
         query.delete(book)
         session.flush()
     return resultutils.results(result='unmark book success')
Beispiel #18
0
 def index(self, req, body=None):
     session = endpoint_session(readonly=True)
     query = model_query(session, User)
     query = query.order_by(User.uid)
     return resultutils.results(result='list users success',
                                data=[
                                    dict(name=user.name,
                                         uid=user.uid,
                                         offer=user.offer,
                                         coins=user.coins,
                                         gifts=user.gifts,
                                         status=user.status,
                                         regtime=user.regtime)
                                    for user in query
                                ])
Beispiel #19
0
 def finished(self, req, cid, chapter, body=None):
     cid = int(cid)
     chapter = int(chapter)
     session = endpoint_session(readonly=True)
     query = session.query(Comic).filter(Comic.cid == cid)
     comic = query.one()
     if comic.last < chapter:
         raise InvalidArgument(
             'Last chapter less then check chpater, chapter upload fail?')
         # return resultutils.results(result='chapter is unfinish', resultcode=manager_common.RESULT_ERROR)
     elif comic.last == chapter:
         if len(msgpack.unpackb(comic.chapters)) != chapter:
             return resultutils.results(
                 result='chapter is unfinish',
                 resultcode=manager_common.RESULT_ERROR)
     return resultutils.results(result='chapter is finish')
Beispiel #20
0
 def notify(self, req, oid, body=None):
     """这个接口由微信调用"""
     oid = int(oid)
     now = int(time.time() * 1000)
     otime = uuidutils.Gprimarykey.timeformat(oid)
     if (now - otime) > weiXinApi.overtime * 2000 or otime > now:
         raise InvalidArgument('Order id error or overtime')
     session = endpoint_session()
     query = model_query(session, Order, filter=Order.oid == oid)
     order = query.one()
     serial, extdata = weiXinApi.esure_notify(body, order)
     self.record(session, order, serial, extdata)
     return webob.Response(request=req,
                           status=200,
                           content_type='application/xml',
                           body=weiXinApi.success)
Beispiel #21
0
 def autocover(self, req, cid, body=None):
     """自动生成封面"""
     cid = int(cid)
     session = endpoint_session(readonly=True)
     query = model_query(session, Comic, filter=Comic.cid == cid)
     comic = query.one()
     src = os.path.join(self.chapter_path(comic.cid, 1), '1.%s' % comic.ext)
     dst = os.path.join(self.comic_path(comic.chapters),
                        'main.%s' % comic.ext)
     if os.path.exists(dst):
         return resultutils.results('Conver exist, do nothing')
     if not os.path.exists(src):
         raise InvalidArgument(
             'Auth set cover pic fail, chapter 1 not exist')
     shutil.copy(src, dst)
     return resultutils.results('Auto set conver success')
Beispiel #22
0
    def loginout(self, req, mid, body=None):
        body = body or {}
        mid = int(mid)
        session = endpoint_session(readonly=True)
        query = model_query(session, Manager, filter=Manager.mid == mid)
        manager = query.one()
        if TokenProvider.is_fernet(req):
            raise InvalidArgument('Manager use uuid token')
        token_id = TokenProvider.getid(req)
        if not token_id:
            raise InvalidArgument('Not token find, not login?')

        def checker(token):
            if token.get('mid') != mid:
                raise InvalidArgument('Mnager id not the same')

        TokenProvider.delete(req, token_id, checker)
        return resultutils.results(
            result='manager loginout success',
            data=[dict(name=manager.name, mid=manager.mid)])
Beispiel #23
0
 def _finish(cid, chapter, body):
     """章节上传完成 通知开放"""
     max = body.get('max')  # 章节最大页数
     key = body.get('key')  # 加密key
     session = endpoint_session()
     query = session.query(Comic).filter(Comic.cid == cid).with_for_update()
     with session.begin():
         comic = query.one()
         last = comic.last
         if last != chapter:
             raise InvalidArgument('Finish chapter value error')
         chapters = msgpack.unpackb(comic.chapters)
         if len(chapters) != (last - 1):
             LOG.error('Comic chapter is not uploading, do not finish it')
             raise InvalidArgument('Finish chapter value error')
         chapters.append([max, key])
         comic.lastup = int(time.time())
         comic.chapters = msgpack.packb(chapters)
         session.flush()
         return comic
Beispiel #24
0
 def login(self, req, mid, body=None):
     """管理员登录"""
     body = body or {}
     passwd = body.get('passwd')
     session = endpoint_session(readonly=True)
     query = model_query(session, Manager, filter=Manager.name == mid)
     manager = query.one()
     if not passwd:
         raise InvalidArgument('Need passwd')
     if manager.passwd != digestutils.strmd5(
             manager.salt.encode('utf-8') + passwd):
         raise InvalidArgument('Password error')
     if TokenProvider.is_fernet(req):
         raise InvalidArgument('Manager use uuid token')
     token = TokenProvider.create(req,
                                  dict(mid=manager.mid, name=manager.name),
                                  3600)
     return resultutils.results(
         result='manager login success',
         data=[dict(token=token, name=manager.name, mid=manager.mid)])
Beispiel #25
0
 def show(self, req, cid, body=None):
     """显示漫画详细, 自动确认用户登陆登陆信息"""
     cid = int(cid)
     session = endpoint_session(readonly=True)
     query = model_query(session, Comic, filter=Comic.cid == cid)
     comic = query.one()
     if comic.status < 0:
         raise exceptions.ComicError('Comic status error')
     chapter = 0
     point = comic.point
     uid, mid = online(req)
     # 管理员
     if mid:
         point = common.MAXCHAPTERS
     #  已登陆,token经过校验
     elif uid:
         query = model_query(session,
                             UserOwn.chapter,
                             filter=and_(UserOwn.uid == uid,
                                         UserOwn.cid == cid))
         owns = query.one_or_none()
         if owns:
             chapter = owns.chapter
     elif comic.status == common.HIDE:
         raise exceptions.ComicError('Comic status error')
     return resultutils.results(result='show comic success',
                                data=[
                                    dict(cid=comic.cid,
                                         name=comic.name,
                                         author=comic.author,
                                         type=comic.type,
                                         region=comic.region,
                                         point=comic.point,
                                         last=comic.last,
                                         lastup=comic.lastup,
                                         ext=comic.ext,
                                         chapters=format_chapters(
                                             point, comic.chapters,
                                             chapter))
                                ])
Beispiel #26
0
 def mark(self, req, cid, uid, body=None):
     """收藏漫画"""
     cid = int(cid)
     uid = int(uid)
     session = endpoint_session()
     if model_count_with_key(session, UserBook, filter=UserBook.uid
                             == uid) >= common.MAXBOOKS:
         raise InvalidArgument('Mark over 50')
     query = model_query(session, Comic.name, filter=Comic.cid == cid)
     comic = query.one()
     try:
         session.add(
             UserBook(uid=uid,
                      cid=cid,
                      ext=comic.ext,
                      name=comic.name,
                      time=int(time.time())))
         session.flush()
     except DBDuplicateEntry:
         LOG.warning('User alreday mark comic')
     return resultutils.results(result='mark book success',
                                data=[dict(cid=comic.cid, name=comic.name)])
Beispiel #27
0
 def paylogs(self, req, uid, body=None):
     """用户支付列表"""
     body = body or {}
     uid = int(uid)
     desc = body.get('desc', True)
     session = endpoint_session(readonly=True)
     query = model_query(session, UserPayLog, filter=UserPayLog.uid == uid)
     query = query.order_by(
         UserPayLog.time.desc() if desc else UserPayLog.time)
     return resultutils.results(result='list users paylogs success',
                                data=[
                                    dict(cid=paylog.cid,
                                         chapter=paylog.chapter,
                                         value=paylog.value,
                                         offer=paylog.offer,
                                         coin=paylog.coin,
                                         gift=paylog.gift,
                                         coins=paylog.coins,
                                         gifts=paylog.gifts,
                                         time=paylog.time)
                                    for paylog in query
                                ])
Beispiel #28
0
    def new(self, req, body=None):
        """发起订单"""
        body = body or {}
        if not isinstance(body, dict):
            raise InvalidArgument(
                'Http body not json or content type is not application/json')
        jsonutils.schema_validate(body, NEWPAYMENT)
        money = body.get('money')
        uid = body.get('uid')
        cid = body.get('cid')
        chapter = body.get('chapter')
        start_time = int(time.time())

        oid = uuidutils.Gkey()
        prepay_id, sign, random_str = weiXinApi.payment(
            money, oid, start_time, req)

        session = endpoint_session()
        coins = self.order(session,
                           weiXinApi,
                           None,
                           uid,
                           oid,
                           money,
                           cid,
                           chapter,
                           ext={'prepay_id': prepay_id},
                           order_time=start_time)
        return resultutils.results(result='create paypal payment success',
                                   data=[
                                       dict(oid=oid,
                                            coins=coins,
                                            money=money,
                                            weixin=dict(prepay_id,
                                                        time=start_time,
                                                        sign=sign,
                                                        random=random_str))
                                   ])
Beispiel #29
0
    def new(self, req, body=None):
        """发起订单"""
        body = body or {}
        if not isinstance(body, dict):
            raise InvalidArgument(
                'Http body not json or content type is not application/json')
        jsonutils.schema_validate(body, NEWPAYMENT)
        money = body.get('money')
        uid = body.get('uid')
        cid = body.get('cid')
        chapter = body.get('chapter')
        # h5 = bool(body.get('h5'))
        start_time = int(time.time())
        oid = uuidutils.Gkey()
        transid, url, url_r, url_h = iPayApi.payment(money, oid, req)
        session = endpoint_session()
        coins = self.order(session,
                           iPayApi,
                           transid,
                           uid,
                           oid,
                           money,
                           cid,
                           chapter,
                           order_time=start_time)

        return resultutils.results(result='create ipay payment success',
                                   data=[
                                       dict(ipay=dict(transid=transid,
                                                      url=url,
                                                      url_r=url_r,
                                                      url_h=url_h),
                                            oid=oid,
                                            coins=coins,
                                            money=money)
                                   ])
Beispiel #30
0
 def _unfinish(cid, chapter):
     """章节上传完成 失败, 通知还原"""
     session = endpoint_session()
     query = session.query(Comic).filter(Comic.cid == cid).with_for_update()
     with session.begin():
         comic = query.one()
         last = comic.last
         if last != chapter:
             raise InvalidArgument('Unfinish chapter value error')
         chapters = msgpack.unpackb(comic.chapters)
         if len(chapters) != (last - 1):
             LOG.error('Comic chapters is not uploading')
             raise InvalidArgument('Unfinish chapter value error')
         comic.last = last - 1
         session.flush()
     chapter_path = ComicRequest.chapter_path(cid, chapter)
     LOG.error('Chapter %d.%d unfinish success, try remove chapter path' %
               (cid, chapter))
     try:
         shutil.rmtree(chapter_path)
     except (OSError, IOError):
         LOG.error('Api _unfinsh Remove chapter path %s fail' %
                   chapter_path)
     return comic