mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-24 23:06:51 +00:00
feat(sns): show loaded vs total posts in author timeline
This commit is contained in:
@@ -506,6 +506,10 @@ class SnsService {
|
||||
return Number.isFinite(num) && num > 0 ? Math.floor(num) : 0
|
||||
}
|
||||
|
||||
private escapeSqlString(value: string): string {
|
||||
return value.replace(/'/g, "''")
|
||||
}
|
||||
|
||||
private pickTimelineUsername(post: any): string {
|
||||
const raw = post?.username ?? post?.user_name ?? post?.userName ?? ''
|
||||
if (typeof raw !== 'string') return ''
|
||||
@@ -864,6 +868,54 @@ class SnsService {
|
||||
})
|
||||
}
|
||||
|
||||
async getUserPostStats(username: string): Promise<{ success: boolean; data?: { username: string; totalPosts: number }; error?: string }> {
|
||||
const normalizedUsername = this.toOptionalString(username)
|
||||
if (!normalizedUsername) {
|
||||
return { success: false, error: '用户名不能为空' }
|
||||
}
|
||||
|
||||
const escapedUsername = this.escapeSqlString(normalizedUsername)
|
||||
const primaryResult = await wcdbService.execQuery(
|
||||
'sns',
|
||||
null,
|
||||
`SELECT COUNT(1) AS total FROM SnsTimeLine WHERE user_name = '${escapedUsername}'`
|
||||
)
|
||||
|
||||
if (primaryResult.success) {
|
||||
const totalPosts = primaryResult.rows && primaryResult.rows.length > 0
|
||||
? this.parseCountValue(primaryResult.rows[0])
|
||||
: 0
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
username: normalizedUsername,
|
||||
totalPosts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fallbackResult = await wcdbService.execQuery(
|
||||
'sns',
|
||||
null,
|
||||
`SELECT COUNT(1) AS total FROM SnsTimeLine WHERE userName = '${escapedUsername}'`
|
||||
)
|
||||
|
||||
if (fallbackResult.success) {
|
||||
const totalPosts = fallbackResult.rows && fallbackResult.rows.length > 0
|
||||
? this.parseCountValue(fallbackResult.rows[0])
|
||||
: 0
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
username: normalizedUsername,
|
||||
totalPosts
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { success: false, error: primaryResult.error || fallbackResult.error || '统计单个好友朋友圈失败' }
|
||||
}
|
||||
|
||||
// 安装朋友圈删除拦截
|
||||
async installSnsBlockDeleteTrigger(): Promise<{ success: boolean; alreadyInstalled?: boolean; error?: string }> {
|
||||
return wcdbService.installSnsBlockDeleteTrigger()
|
||||
|
||||
Reference in New Issue
Block a user