def update(db): bid = int(request.POST.get('bookmarkid','')) cid = int(request.POST.get('category','0')) title = request.POST.get('title','') tag = request.POST.get('tag','') notes = request.POST.get('notes','') if ulen(title) > 512: return {'error' : '你对标题也太有爱了 这么长的标题'} if ulen(tag) > 1024: return {'error' : '你的标签太有爱了 这么丰富的'} if ulen(notes) > 1024: return {'error' : '你的备注也超长的,您一定是细心的人'} tag = refineTag(tag) #检查这个书签是否存在 db.execute('SELECT CATEGORY_ID,URL FROM URLS WHERE ID=%s',bid) v = db.getone() if not v: return {'noauth' : 1} catid,url = v isnewcat = (cid != int(catid)) if isnewcat: #变更类目了 #检查这个catid是否存在 db.execute('SELECT 1 FROM CATEGORY WHERE ID=%s',cid) v = db.getone() if not v: return {'noauth' : 1} if isnewcat: db.execute('UPDATE URLS SET CATEGORY_ID=%s,TITLE=%s,TAG=%s,NOTES=%s WHERE ID=%s',(cid,title,tag,notes,bid)) else: db.execute('UPDATE URLS SET TITLE=%s,TAG=%s,NOTES=%s WHERE ID=%s',(title,tag,notes,bid)) db.commit() return {'ok':1}
def jstie(db): """ 新版本的Tie过程 """ url = request.GET.get('url', '').strip() title = request.GET.get('title', '').strip() tag = request.GET.get('tag', '').strip() catid = int(request.GET.get('category', '').strip()) notes = request.GET.get('notes', '').strip() isheart = request.GET.get('heart', '').strip() if not url or isdeny(url): #返回1x1的数据,表示正确,实为吞没 response['Content-Type'] = 'image/png' return png_1x1 if ulen(url) > 1024: url = ulenget(url, 1024) if ulen(title) > 1024: title = ulenget(title, 1024) if tag: tag = refineTag(tag) if ulen(tag) > 1024: tag = ulenget(tag, 1024) if ulen(notes) > 1024: notes = ulenget(notes, 1024) try: catid = int(catid) #检查这个catid是否存在 db.execute('SELECT ID FROM CATEGORY WHERE ID=%s', catid) v = db.getone() if not v: raise Exception("invalid catid param") #非法用户插入,选用默认的结果. except: catid = getdefaultcatid(db) heart = 0 if isheart: heart = 1 shortid = 0 if url: shortid = getshorturlid(url) db.execute( 'INSERT INTO URLS(IS_HEART,IS_ARCHIVED,ARCHIVED_OK,CATEGORY_ID,URL,SHORT_URL_ID,TITLE,TAG,NOTES,TIE_TIME) VALUES(%s,0,0,%s,%s,%s,%s,%s,%s,%s)', (heart, catid, url, shortid, title, tag, notes, nt())) recordid = db.insert_id() if needarchive(db) and archiveapiok(db) and url: db.execute('UPDATE URLS SET IS_ARCHIVED=2 WHERE ID=%s', recordid) db.commit() response['Content-Type'] = 'image/png' return png_1x1
def jstie(db): """ 新版本的Tie过程 """ url = request.GET.get('url','').strip() title = request.GET.get('title','').strip() tag = request.GET.get('tag','').strip() catid = int(request.GET.get('category','').strip()) notes = request.GET.get('notes','').strip() isheart = request.GET.get('heart','').strip() if not url or isdeny(url): #返回1x1的数据,表示正确,实为吞没 response['Content-Type'] = 'image/png' return png_1x1 if ulen(url) > 1024: url = ulenget(url,1024) if ulen(title) > 1024: title=ulenget(title,1024) if tag: tag = refineTag(tag) if ulen(tag) > 1024: tag = ulenget(tag,1024) if ulen(notes) > 1024: notes= ulenget(notes,1024) try: catid = int(catid) #检查这个catid是否存在 db.execute('SELECT ID FROM CATEGORY WHERE ID=%s',catid) v = db.getone() if not v: raise Exception("invalid catid param") #非法用户插入,选用默认的结果. except: catid = getdefaultcatid(db) heart = 0 if isheart: heart = 1 shortid = 0 if url: shortid = getshorturlid(url) db.execute('INSERT INTO URLS(IS_HEART,IS_ARCHIVED,ARCHIVED_OK,CATEGORY_ID,URL,SHORT_URL_ID,TITLE,TAG,NOTES,TIE_TIME) VALUES(%s,0,0,%s,%s,%s,%s,%s,%s,%s)',(heart,catid,url,shortid,title,tag,notes,nt())) recordid = db.insert_id() if needarchive(db) and archiveapiok(db) and url: db.execute('UPDATE URLS SET IS_ARCHIVED=2 WHERE ID=%s',recordid) db.commit() response['Content-Type'] = 'image/png' return png_1x1
def apinewcat(db): """ api的新建目录 """ title = request.POST.get('title','').strip() if not title: return {'error' : '收藏夹的名称总是不可少的'} if ulen(title) > 128: return {'error' : '收藏夹的名称太长了'} curid = 0 ret = getCategory(db) for cid,t in ret: if t.lower() == title.lower(): break curid += 1 if curid == len(ret): #没有相同的 db.execute('INSERT INTO CATEGORY(TITLE) VALUES(%s)',title) db.commit() ret = getCategory(db) else: ret[curid],ret[0] = ret[0],ret[curid] return {'content' : [ (cid,t) for cid,t in ret]}
def apinewcat(db): """ api的新建目录 """ title = request.POST.get('title', '').strip() if not title: return {'error': '收藏夹的名称总是不可少的'} if ulen(title) > 128: return {'error': '收藏夹的名称太长了'} curid = 0 ret = getCategory(db) for cid, t in ret: if t.lower() == title.lower(): break curid += 1 if curid == len(ret): #没有相同的 db.execute('INSERT INTO CATEGORY(TITLE) VALUES(%s)', title) db.commit() ret = getCategory(db) else: ret[curid], ret[0] = ret[0], ret[curid] return {'content': [(cid, t) for cid, t in ret]}
def importonecat(db, cat): catname = cat['title'] if ulen(catname) > 128: catname = ulenget(catname, 128) catid = createnewcat(db, catname) for alink in cat['links']: importalink(db, catid, alink)
def importonecat(db,cat): catname = cat['title'] if ulen(catname) > 128: catname = ulenget(catname,128) catid = createnewcat(db,catname) for alink in cat['links']: importalink(db,catid,alink)