Files
wzdj/scripts/bind-approved-streamer.ts
卡若 b95d1a94c6 feat(live): 直播与主播工作台 API、云厂商解析与文档调研
- 新增直播评论/上下文/礼物等 API 与回放组件
- 主播开播、云端推流配置与 streamer 校验
- 依赖与 Mongo 集合/种子更新
- 需求与调研文档补充

Made-with: Cursor
2026-04-14 16:24:17 +08:00

78 lines
2.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 为指定手机号用户插入一条「已审核」主播档案(若尚无 approved + userId 绑定)
* 用法pnpm exec tsx scripts/bind-approved-streamer.ts [手机号]
* 默认15880802661
*/
import { config } from "dotenv"
import { resolve } from "path"
config({ path: resolve(process.cwd(), ".env.local") })
import { MongoClient, ObjectId } from "mongodb"
import { COLLECTIONS } from "../lib/db/mongo/collections"
const phone = (process.argv[2] || "15880802661").trim()
function nowIso() {
return new Date().toISOString()
}
async function main() {
const uri = process.env.MONGODB_URI
if (!uri) {
console.error("缺少 MONGODB_URI")
process.exit(1)
}
const client = new MongoClient(uri)
await client.connect()
try {
const db = client.db("wanzhi_esports")
const users = db.collection(COLLECTIONS.users)
const streamers = db.collection(COLLECTIONS.streamers)
const u = await users.findOne({ phone })
if (!u || !(u as { _id?: ObjectId })._id) {
console.error(`未找到用户 phone=${phone},请先注册`)
process.exit(1)
}
const uid = (u as { _id: ObjectId })._id.toString()
const exists = await streamers.findOne({ userId: uid, status: "approved" })
if (exists) {
console.log(`已有已审核主播绑定 userId=${uid},跳过`)
return
}
await streamers.insertOne({
userId: uid,
name: (u as { name?: string }).name || "主播",
title: "玩值测试主播 · 工作台",
game: "英雄联盟",
gameId: 2,
avatar: "/gamer-boy-esports-jersey.jpg",
coverImage: "/lol-stream.jpg",
tags: ["测试", "工作台"],
level: 1,
fans: 888,
hotValue: 8.8,
isLive: false,
totalGifts: 0,
totalIncome: 0,
commissionRate: 0.7,
status: "approved",
verifiedAt: nowIso(),
createdAt: nowIso(),
updatedAt: nowIso(),
})
console.log(`已为 ${phone} 创建已审核主播userId=${uid}`)
} finally {
await client.close()
}
}
main().catch((e) => {
console.error(e)
process.exit(1)
})