Пример #1
0
 def addPage(pageName, creator, imgPath, pageData):
     if (pageName is None) | (creator is None) | (imgPath is None) | (pageData is None):
         return PageClient.EMPTY_INPUT
     if len(pageName) > PageClient.PAGE_NAME_MAX_LENGTH:
         return PageClient.NAME_TOO_LONG
     if (PageClient.checkPageByName(pageName)):
         return PageClient.REDUNDANT
     LogClient.info('INSERT PAGE')
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     now = time.time()
     try:
         sql = "INSERT INTO `wp_page` (`name`, `creator`, `img_path`, `data`, `ctime`, `last_update`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s')" % (pageName, creator, imgPath, pageData, now, now)
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     PageClient.addPageHistory(pageName, creator, pageData)
     PageClient.convertPage(pageName, creator, imgPath, pageData)
     LogClient.info('INSERT PAGE SUCCEED')
     return {
         "status": "succeed"
     }
Пример #2
0
 def updateCard(cardId, cardJsonStr):
     if (cardId is None) | (cardJsonStr is None):
         return BuildClient.EMPTY_INPUT
     try:
         cardJsonObj = json.loads(cardJsonStr)
     except:
         return BuildClient.NOT_JSON_FORMAT
     LogClient.info('UPDATE CARD')
     LogClient.info(cardJsonObj)
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     description = '%s - %s' % (cardJsonObj['introduction'],
                                cardJsonObj['name'])
     now = time.time()
     try:
         if cardId[0] == 'p':
             ids = cardId.split('-')
             cardId = ids[1]
             privateToken = ids[2]
             sql = "UPDATE `wp_card` SET `data` = '%s', `description` = '%s', `last_update` = '%s' WHERE `id` = '%s' AND `private_token` = '%s'" % (
                 cardJsonStr, description, now, cardId, privateToken)
         else:
             sql = "UPDATE `wp_card` SET `data` = '%s', `description` = '%s', `last_update` = '%s' WHERE `id` = '%s' AND `is_private` = '0'" % (
                 cardJsonStr, description, now, cardId)
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     BuildClient.addCardHistory(cardId, cardJsonStr)
     LogClient.info('UPDATE CARD SUCCEED')
     return {"status": "succeed"}
Пример #3
0
 def getCard(cardId):
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     item = None
     try:
         if cardId[0] == 'p':
             ids = cardId.split('-')
             cardId = ids[1]
             privateToken = ids[2]
             sql = "SELECT * FROM `wp_card` WHERE `id` = '%s' AND `is_delete` = '0' AND `private_token` = '%s' LIMIT 1" % (
                 cardId, privateToken)
         else:
             sql = "SELECT * FROM `wp_card` WHERE `id` = '%s' AND `is_delete` = '0' AND `is_private` = '0' LIMIT 1" % cardId
         cur.execute(sql)
         item = cur.fetchone()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     if item is not None:
         return {
             "status": "succeed",
             "data": {
                 "creator": item['creator'],
                 "imgpath": item['img_path'],
                 "imgpath_large": item['img_path_large'],
                 "ctime": item['ctime'],
                 "last_update": item['last_update'],
                 "data": json.loads(item['data'])
             }
         }
     else:
         return BuildClient.ERROR
Пример #4
0
 def updateCardImgLarge(cardId, imgPath):
     if (cardId is None) | (imgPath is None):
         return BuildClient.EMPTY_INPUT
     LogClient.info('UPDATE CARD IMG LARGE')
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     now = time.time()
     try:
         if cardId[0] == 'p':
             ids = cardId.split('-')
             cardId = ids[1]
             privateToken = ids[2]
             sql = "UPDATE `wp_card` SET `img_path_large` = '%s', `last_update` = '%s' WHERE `id` = '%s' AND `private_token` = '%s'" % (
                 imgPath, now, cardId, privateToken)
         else:
             sql = "UPDATE `wp_card` SET `img_path_large` = '%s', `last_update` = '%s' WHERE `id` = '%s' AND `is_private` = '0'" % (
                 imgPath, now, cardId)
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     LogClient.info('UPDATE CARD IMG LARGE SUCCEED')
     return {"status": "succeed"}
Пример #5
0
 def upload(fileName, data):
     if (fileName is None) | (data is None):
         return ImgClient.EMPTY_INPUT
     LogClient.info(fileName)
     ext = fileName.replace('\\', '/').split('/')[-1].split('.', 1)[1]
     if (not ((ext == 'jpeg') | (ext == 'gif') | (ext == 'png') | (ext == 'bmp') | (ext == 'jpg') | (ext == 'webp'))):
         return ImgClient.NOT_SUPPORTED_FORMAT
     randFileName = randomStr(10)
     fout = open(ImgClient.IMG_STORAGE_PATH + randFileName + '.' + ext, 'wb')
     fout.write(data)
     fout.close()
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     now = time.time()
     try:
         sql = "INSERT INTO `wp_img` (`filename`, `ctime`) VALUES ('%s', '%s')" % (randFileName + '.' + ext, now)
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     return {
         "status": "succeed",
         "filepath": WEB_CONF['host'] + '/static/img/custom/' + randFileName + '.' + ext
     }
Пример #6
0
 def updatePage(pageName, creator, imgPath, pageData):
     if (pageName is None) | (creator is None) | (imgPath is None) | (pageData is None):
         return PageClient.EMPTY_INPUT
     if len(pageName) > PageClient.PAGE_NAME_MAX_LENGTH:
         return PageClient.NAME_TOO_LONG
     pageItem = PageClient.getPage(pageName)
     if pageItem['status'] != 'succeed':
         return PageClient.NOT_EXIST
     if pageItem['is_lock'] != 0:
         return {
             "status": "locked"
         }
     LogClient.info('UPDATE PAGE')
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     now = time.time()
     try:
         sql = "UPDATE `wp_page` SET `creator` = '%s', `img_path` = '%s', `data` = '%s', `last_update` = '%s' WHERE `name` = '%s'" % (creator, imgPath, pageData, now, pageName)
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     PageClient.addPageHistory(pageName, creator, pageData)
     PageClient.convertPage(pageName, creator, imgPath, pageData)
     LogClient.info('UPDATE PAGE SUCCEED')
     return {
         "status": "succeed"
     }
Пример #7
0
 def addPageHistory(pageName, creator, pageData):
     LogClient.info('INSERT PAGE HISTORY')
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     now = time.time()
     try:
         sql = "INSERT INTO `wp_page_history` (`name`, `creator`, `data`, `ctime`) VALUES ('%s', '%s', '%s', '%s')" % (pageName, creator, pageData, now)
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     LogClient.info('INSERT PAGE HISTORY SUCCEED')
Пример #8
0
 def addCardHistory(cardId, cardJsonStr):
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     now = time.time()
     try:
         sql = "INSERT INTO `wp_card_history` (`card_id`, `data`, `ctime`) VALUES ('%s', '%s', '%s')" % (
             cardId, cardJsonStr, now)
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     LogClient.info('INSERT CARD HISTORY SUCCEED')
Пример #9
0
 def refreshAllPages():
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     items = None
     try:
         sql = "SELECT `name`, `creator`, `img_path`, `data` FROM `wp_page` WHERE 1=1"
         cur.execute(sql)
         items = cur.fetchall()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     if items is not None:
         for item in items:
             PageClient.convertPage(item['name'], item['creator'], item['img_path'], item['data'])
Пример #10
0
 def countCards():
     item = None
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     try:
         sql = "SELECT COUNT(1) AS num FROM `wp_card` WHERE `is_delete` = '0' AND `is_private` = '0'"
         cur.execute(sql)
         item = cur.fetchone()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     if item is not None:
         return item['num']
     else:
         return 0
Пример #11
0
 def checkPageByName(name):
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     item = None
     try:
         sql = "SELECT * FROM `wp_page` WHERE `name` = '%s' LIMIT 1" % name
         cur.execute(sql)
         item = cur.fetchone()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     if item is not None:
         return True
     else:
         return False
Пример #12
0
 def getPageHistory():
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     items = None
     try:
         sql = "SELECT `id`, `name`, `creator`, `ctime` FROM `wp_page_history` WHERE 1=1 ORDER BY `id` DESC LIMIT 0, 20"
         cur.execute(sql)
         items = cur.fetchall()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     if items is not None:
         return {'status': 'succeed', 'data': items}
     else:
         return {'status': 'succeed', 'data': []}
Пример #13
0
 def getCards(page, pageSize):
     total = BuildClient.countCards()
     start = pageSize * (page - 1)
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     items = None
     try:
         sql = "SELECT `id`, `description`, `img_path` FROM `wp_card` WHERE `is_delete` = '0' AND `is_private` = '0' ORDER BY `id` DESC LIMIT %s, %s" % (
             start, pageSize)
         cur.execute(sql)
         items = cur.fetchall()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     if items is not None:
         return {'status': 'succeed', 'total': total, 'data': items}
     else:
         return BuildClient.ERROR
Пример #14
0
 def makePublic(cardId):
     if cardId is None:
         return BuildClient.EMPTY_INPUT
     LogClient.info('MAKE PUBLIC CARD')
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     try:
         ids = cardId.split('-')
         cardId = ids[1]
         privateToken = ids[2]
         sql = "UPDATE `wp_card` SET `is_private` = '0', `private_token` = '' WHERE `id` = '%s' AND `private_token` = '%s'" % (
             cardId, privateToken)
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     LogClient.info('MAKE PUBLIC CARD SUCCEED')
     return {"status": "succeed"}
Пример #15
0
 def getPage(pageName):
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     item = None
     try:
         sql = "SELECT `data`, `creator`, `img_path`, `is_lock` FROM `wp_page` WHERE `name` = '%s' AND `is_delete` = '0' LIMIT 1" % pageName
         cur.execute(sql)
         item = cur.fetchone()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     if item is not None:
         return {
             "status": "succeed",
             "pagedata": item['data'],
             "creator": item['creator'],
             "imgpath": item['img_path'],
             "is_lock": item['is_lock']
         }
     else:
         return PageClient.NOT_EXIST
Пример #16
0
 def deleteCard(cardId):
     if cardId is None:
         return BuildClient.EMPTY_INPUT
     LogClient.info('DELETE CARD')
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     try:
         if cardId[0] == 'p':
             ids = cardId.split('-')
             cardId = ids[1]
             privateToken = ids[2]
             sql = "UPDATE `wp_card` SET `is_delete` = '1' WHERE `id` = '%s' AND `private_token` = '%s'" % (
                 cardId, privateToken)
         else:
             sql = "UPDATE `wp_card` SET `is_delete` = '1' WHERE `id` = '%s' AND `is_private` = '0'" % cardId
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     LogClient.info('DELETE CARD SUCCEED')
     return {"status": "succeed"}
Пример #17
0
 def addCard(creator, imgPath, cardJsonStr, isPrivate=False):
     if (creator is None) | (imgPath is None) | (cardJsonStr is None):
         return BuildClient.EMPTY_INPUT
     try:
         cardJsonObj = json.loads(cardJsonStr)
     except:
         return BuildClient.NOT_JSON_FORMAT
     LogClient.info('INSERT CARD')
     LogClient.info(creator)
     LogClient.info(cardJsonObj)
     db = MysqlConn().getMysqlConn('wp')
     cur = db.cursor()
     description = '%s - %s' % (cardJsonObj['introduction'],
                                cardJsonObj['name'])
     private = isPrivate and 1 or 0
     privateToken = isPrivate and randomStr(10) or ''
     lastId = 0
     now = time.time()
     try:
         sql = "INSERT INTO `wp_card` (`creator`, `data`, `description`, `img_path`, `is_private`, `private_token`, `ctime`, `last_update`) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" % (
             creator, cardJsonStr, description, imgPath, private,
             privateToken, now, now)
         LogClient.info(sql)
         cur.execute(sql)
         db.commit()
         lastId = cur.lastrowid
     except:
         LogClient.error(sys.exc_info())
     finally:
         cur.close()
     BuildClient.addCardHistory(lastId, cardJsonStr)
     LogClient.info('INSERT CARD SUCCEED')
     return {
         "status": "succeed",
         "id": isPrivate and ('p-%s-%s' % (lastId, privateToken)) or lastId
     }