Exemplo n.º 1
0
 def DELETE(self, uri):
     LogClient.info('DELETE - ' + uri)
     attrs = Controller.__getAttrs(uri)
     if (len(attrs) > 0) & (attrs[0] == 'api'):
         attrs[0] = 'delete'
         return self._cmd['api'](attrs)
     return ''
Exemplo n.º 2
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
     }
Exemplo n.º 3
0
 def PUT(self, uri):
     LogClient.info('PUT - ' + uri)
     attrs = Controller.__getAttrs(uri)
     if (len(attrs) > 0) & (attrs[0] == 'api'):
         attrs[0] = 'put'
         return self._cmd['api'](attrs)
     return ''
Exemplo n.º 4
0
 def convertPage(pageName, creator, imgPath, pageData):
     LogClient.info("Convert Page Start: %s" % pageName)
     filePath = r'%s/page/%s.html' % (ABS_PATH, pageName)
     if os.path.isfile(filePath):
         os.remove(filePath)
     htmlData = WikiEngine.strToHtml(pageData)
     file = open(filePath,'wa')
     file.write('$def with (DATA)\n')
     file.write('<!DOCTYPE html>\n')
     file.write('<html>\n')
     file.write('<head>\n')
     file.write('    <meta http-equiv="content-type" content="text/html; charset=UTF-8">\n')
     file.write('    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">\n')
     file.write('    <title>%s - Will Project Wiki</title>\n' % pageName)
     file.write('    <link rel="icon" type="image/png" href="$DATA[\'HOST\']/favicon.ico"/>\n')
     file.write('    <script type="text/javascript">const DATA = $:DATA; </script>\n')
     file.write('    <script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.2.0/jquery.min.js"></script>\n')
     file.write('    <script type="text/javascript" src="http://cdn.bootcss.com/react/15.2.0/react-with-addons.min.js"></script>\n')
     file.write('    <script type="text/javascript" src="http://cdn.bootcss.com/react/15.2.0/react-dom.min.js"></script>\n')
     file.write('    <script type="text/javascript" src="http://cdn.bootcss.com/antd/1.6.4/antd.min.js"></script>\n')
     file.write('    <link type="text/css" rel="stylesheet" href="http://cdn.bootcss.com/antd/1.6.4/antd.min.css"/>\n')
     file.write('    <script type="text/javascript" src="$DATA[\'HOST\']/static/js/base.bundle.js"></script>\n')
     file.write('</head>\n')
     file.write('<body>\n')
     file.write('<div class="stage">\n')
     file.write('    <script>\n')
     file.write('        if (wp.base.BROWSER_TYPE) { $$(".stage").addClass("mobile"); }\n')
     file.write('        else { $$(".stage").addClass("pc"); }\n')
     file.write('    </script>\n')
     file.write('    <div class="main wrap" id="main">\n')
     file.write('        <div class="nav" id="nav" style="min-height:139px;"></div>\n')
     file.write('        <div class="content" id="content">\n')
     file.write('            <div style="margin:10px 0;float:right;font-size:small;"><a href="/editpage/%s">编辑本页</a></div>\n' % pageName)
     file.write('            <p style="text-align:left;font-weight:bold;">%s</p>\n' % pageName)
     file.write('            <div style="margin:10px;"><hr/></div>\n')
     file.write('            <div class="page-content" style="text-align:left;">\n')
     file.write('                <script> $$(".page-content").css("minHeight", wp.base.WINDOW_HEIGHT-300); </script>\n')
     if imgPath != "":
         file.write('                <div style="margin:10px;text-align:center;"><img style="max-width:100%;" src="' + imgPath + '"/></div>\n')
     file.write(htmlData)
     file.write('\n            </div>\n')
     file.write('            <div style="margin:10px;"><hr/></div>\n')
     file.write('            <p style="font-size:small;">最后编辑:%s</p>\n' % creator)
     file.write('            <p style="font-size:small;">最后更新时间:%s</p>\n' % (time.strftime('%Y-%m-%d %H:%M', time.gmtime(time.time() + 3600 * 8))))
     file.write('        </div>\n')
     file.write('    </div>\n')
     file.write('</div>\n')
     file.write('<script>wp.base.calcWindowHeight();</script>\n')
     file.write('</body>\n')
     file.write('<script type="text/javascript" src="$DATA[\'HOST\']/static/js/nav.bundle.js"></script>\n')
     file.write('</html>\n')
     LogClient.info("Convert Page Finished: %s" % pageName)
Exemplo n.º 5
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"}
Exemplo n.º 6
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')
Exemplo n.º 7
0
 def GET(self, uri):
     LogClient.info('GET - ' + uri)
     attrs = Controller.__getAttrs(uri)
     if uri == '':
         return self._cmd['index'](attrs)
     if uri == 'favicon.ico':
         web.redirect('/static/img/favicon.ico')
     if (len(attrs) > 0) & (attrs[0] is not ''):
         if attrs[0] in self._cmd.keys():
             key = attrs[0]
             attrs[0] = 'get'
             return self._cmd[key](attrs)
     else:
         return self._cmd['index'](attrs)
     return self._cmd['404'](attrs)
Exemplo n.º 8
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"
     }
Exemplo n.º 9
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"
     }
Exemplo n.º 10
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"}
Exemplo n.º 11
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
     }
Exemplo n.º 12
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')
Exemplo n.º 13
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"}
Exemplo n.º 14
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"}
Exemplo n.º 15
0
 def __test(self):
     from common.dao import MemcacheConn
     mc = MemcacheConn()
     # mc.getMcConn('wp').set('test', 'helloworld!')
     LogClient.info(mc.getMcConn('wp').get('test'))