try: db = DBPools() media_type = params_kw.get('media_type', '') page = int(params_kw.get('page', 1)) page_size = int(params_kw.get('page_size', 20)) offset = (page - 1) * page_size where = "WHERE status = '1'" bindparams = {} if media_type: where += " AND media_type = ${media_type}$" bindparams['media_type'] = media_type async with db.sqlorContext('sage') as sor: total_r = await sor.sqlExe( f"SELECT COUNT(*) as cnt FROM showcase_posts {where}", bindparams ) total = total_r[0]['cnt'] if total_r else 0 posts = await sor.sqlExe( f"""SELECT id, author_id, author_name, title, description, media_type, content_url, thumbnail_url, duration, tags, category, like_count, comment_count, view_count, download_count, is_featured, price, created_at FROM showcase_posts {where} ORDER BY created_at DESC LIMIT {page_size} OFFSET {offset}""", bindparams ) return json.dumps({ "status": "ok", "data": list(posts), "total": total, "page": page, "page_size": page_size }, ensure_ascii=False) except Exception as e: return json.dumps({"status": "error", "data": [], "message": str(e)}, ensure_ascii=False)