fix: Instagram 热点过滤低互动内容并按点赞数排序

- 适配器过滤 like_count < 100 的低质量内容,按点赞数降序排列
- 后端 dev/start 脚本添加 --env-file=.env 自动加载环境变量

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
wxs 2026-03-03 16:11:40 +08:00
parent e933c71b3d
commit 286b73a287
3 changed files with 27 additions and 5 deletions

View File

@ -4,8 +4,8 @@
"private": true,
"type": "module",
"scripts": {
"dev": "tsx watch src/index.ts",
"start": "tsx src/index.ts",
"dev": "tsx watch --env-file=.env src/index.ts",
"start": "tsx --env-file=.env src/index.ts",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"

View File

@ -58,7 +58,7 @@ describe("InstagramAdapter", () => {
code: "SEC001",
caption: "Section post",
user: { username: "user1" },
like_count: 1000,
like_count: 5000,
},
],
},
@ -87,6 +87,7 @@ describe("InstagramAdapter", () => {
code: "cap-obj",
caption: { text: "Caption from object" },
user: { username: "test" },
like_count: 500,
},
],
});
@ -102,6 +103,7 @@ describe("InstagramAdapter", () => {
code: "cap-str",
caption: "String caption",
user: { username: "test" },
like_count: 500,
},
],
});
@ -117,6 +119,7 @@ describe("InstagramAdapter", () => {
code: "cap-null",
caption: null,
user: { username: "test" },
like_count: 500,
},
],
});
@ -132,6 +135,7 @@ describe("InstagramAdapter", () => {
code: "thumb-test",
thumbnail_url: "https://ig.com/thumb.jpg",
user: { username: "test" },
like_count: 500,
},
],
});
@ -139,6 +143,22 @@ describe("InstagramAdapter", () => {
const items = await adapter.fetchTrending(20);
expect(items[0].cover_url).toBe("https://ig.com/thumb.jpg");
});
it("filters out low-engagement items and sorts by likes", async () => {
mockFetch.mockResolvedValueOnce({
items: [
{ code: "low", caption: "Low", user: { username: "a" }, like_count: 5 },
{ code: "high", caption: "High", user: { username: "b" }, like_count: 10000 },
{ code: "mid", caption: "Mid", user: { username: "c" }, like_count: 500 },
{ code: "none", caption: "None", user: { username: "d" } },
],
});
const items = await adapter.fetchTrending(20);
expect(items).toHaveLength(2);
expect(items[0].id).toBe("high");
expect(items[1].id).toBe("mid");
});
});
describe("fetchDetail", () => {

View File

@ -34,10 +34,12 @@ export class InstagramAdapter implements PlatformAdapter {
}
return items
.slice(0, count)
.map((item: unknown, index: number) =>
this.mapToContentItem(item as Record<string, unknown>, index)
);
)
.filter((item) => item.like_count != null && item.like_count >= 100)
.sort((a, b) => (b.like_count ?? 0) - (a.like_count ?? 0))
.slice(0, count);
}
async fetchDetail(id: string): Promise<ContentItem> {