def ListFavBoards(svc, session, params): start = Util.GetInt(params, 'start') end = Util.GetInt(params, 'end') count = Util.GetInt(params, 'count') father = Util.GetInt(params, 'father', -1) fboards = FavBoardMgr.LoadFavBoards(session.GetUser().name) if fboards == None: raise ServerError("failed to load fav boards") fboards.LoadFavBoards() start, end = Util.CheckRange(start, end, count, DEFAULT_LIST_FAVBOARD_COUNT, fboards._count) if (start <= end) and (start >= 1) and (end <= fboards._count): first = True result = '[\n' for index in range(0, fboards._count): fboard = fboards._favboards[index] if fboard.Exists(): if fboard._father == father: if not first: result += ',\n' first = False result += fboard.GetInfoJSON(index, session.GetUser()) result += '\n]' svc.writedata(result) return else: raise WrongArgs('invalid arguments')
def GetPostList(self, svc, session, params): """ handle board/post_list List posts in this board in mode 'mode'. Start listing from post #'start', till post #'end', return at most 'count' posts. """ mode = Util.GetString(params, 'mode', 'normal') start = Util.GetInt(params, 'start') end = Util.GetInt(params, 'end') count = Util.GetInt(params, 'count') allow_empty = not start and not end if (mode == 'normal'): total = self.status.total else: total = self.PostCount(mode) start, end = Util.CheckRange(start, end, count, DEFAULT_GET_POST_COUNT, total) if ((start <= end) and (start >= 1) and (end <= total)): bread = BRead.BReadMgr.LoadBRead(session.GetUser().name) if (bread != None): bread.Load(self.name) if (mode == 'normal' or mode == 'digest' or mode == 'mark' or mode == 'sticky' or mode == 'thread' or mode == 'origin'): dirf = open(self.GetDirPath(mode), 'rb') post = {} first = True result = '[\n' for i in range(start - 1, end): pe = self.GetPostEntry(i, mode, dirf) if (pe is None): continue if (not first): result += ',\n' first = False post = pe.GetInfoExtended(session.GetUser(), self, 'post') post['id'] = i + 1 read = True if (bread != None): read = not bread.QueryUnread(pe.id, self.name) post['read'] = read # post['filename'] = pe.filename result += json.dumps(post, 'utf-8') result += '\n]' svc.writedata(result) dirf.close() else: if allow_empty: svc.writedata('[]') else: raise OutOfRange('out of range') return
def GetAttachmentReq(self, svc, session, params, id): mode = Util.GetString(params, 'mode', 'normal') offset = Util.GetInt(params, 'offset') if (offset <= 0): raise WrongArgs("invalid or lacking offset") if ((id >= 1) and (id <= self.status.total)): pe = self.GetPostEntry(id - 1, mode) attach = Post.ReadAttachment(self.GetBoardPath() + pe.filename, offset) attach = { 'name': attach[0], 'content': base64.b64encode(attach[1]) } svc.writedata(json.dumps(attach)) else: raise OutOfRange("invalid post id")