mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
feat: 图片复制定位信息
This commit is contained in:
1 parent
a799fc1490
commit
52c89bf0c7
7 files changed
+273
No files matched your search
@@ -91,6 +91,14 @@ import {
|
||||
testImageDecryption
|
||||
} from './services/image-decryption-status-service'
|
||||
import type { SaveImageKeyRequest, TestImageDecryptionRequest } from '../shared/image-decryption'
|
||||
import { imageFileQuality } from '../shared/image-quality'
|
||||
import {
|
||||
IMAGE_DEBUG_KIND,
|
||||
type ImageDebugInfoRequest,
|
||||
type ImageDebugInfoResult,
|
||||
type ImageDebugPayload,
|
||||
type ImageDebugQuality
|
||||
} from '../shared/image-debug-info'
|
||||
import {
|
||||
loadSettings,
|
||||
saveSettings,
|
||||
@@ -686,6 +694,16 @@ function getLocalMediaMimeType(filePath: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出用的三档质量(original/medium/thumbnail)与调试信息的两档命名不同:
|
||||
* 调试侧用 normal 表示「中图」,避免与 ExportImageQuality 的 medium 混淆。
|
||||
*/
|
||||
function toDebugQuality(quality: 'original' | 'medium' | 'thumbnail'): ImageDebugQuality {
|
||||
if (quality === 'original') return 'original'
|
||||
if (quality === 'thumbnail') return 'thumbnail'
|
||||
return 'normal'
|
||||
}
|
||||
|
||||
function buildImageResponse(
|
||||
image: DecodedImage,
|
||||
includeData = false
|
||||
@@ -1725,6 +1743,69 @@ app.whenReady().then(async () => {
|
||||
|
||||
ipcMain.handle('image:getConfig', () => imageKeyConfigService.getConfig())
|
||||
|
||||
/**
|
||||
* 复制图片调试定位信息。
|
||||
*
|
||||
* 只回答「用户点中的是哪一条消息、当前展示的是哪份本地资源」。
|
||||
* 刻意不返回资源密钥、完整 XML、fileid 或任何 CDN 凭据。
|
||||
*/
|
||||
ipcMain.handle(
|
||||
'image:getDebugInfo', async (_, request: ImageDebugInfoRequest): Promise<ImageDebugInfoResult> => {
|
||||
try {
|
||||
const service = ensureImageDecryptService()
|
||||
const self = chat.getSelfAccountInfo()
|
||||
const accountRoot = self?.accountRoot || loadSettings().dbRoot || ''
|
||||
const sessionId = String(request?.sessionId || '').trim() || null
|
||||
const localId =
|
||||
typeof request?.localId === 'number' && Number.isFinite(request.localId)
|
||||
? String(request.localId)
|
||||
: null
|
||||
const serverId = String(request?.serverId || '').trim() || null
|
||||
const createTimeSeconds =
|
||||
typeof request?.createTime === 'number' && Number.isFinite(request.createTime)
|
||||
? request.createTime
|
||||
: null
|
||||
|
||||
const md5 = String(request?.imageMd5 || '').trim() || null
|
||||
const datName = String(request?.imageDatName || '').trim() || null
|
||||
|
||||
// 复用真实选图逻辑;找不到就是 null,不根据文件名猜。
|
||||
const filePath = service
|
||||
? service.findImageFile(md5 || undefined, datName || undefined, { sessionId: sessionId || undefined })
|
||||
: null
|
||||
const quality = filePath ? toDebugQuality(imageFileQuality(filePath)) : 'unknown'
|
||||
const relativePath =
|
||||
filePath && accountRoot && filePath.startsWith(accountRoot)
|
||||
? path.relative(accountRoot, filePath).split(path.sep).join('/')
|
||||
: null
|
||||
const evidence = filePath ? path.basename(filePath) : null
|
||||
|
||||
const payload: ImageDebugPayload = {
|
||||
kind: IMAGE_DEBUG_KIND,
|
||||
message: {
|
||||
accountId: self?.wxid || null,
|
||||
conversationId: sessionId,
|
||||
localId,
|
||||
serverId,
|
||||
createTimeSeconds
|
||||
},
|
||||
image: { md5, datName },
|
||||
display: {
|
||||
quality,
|
||||
evidence,
|
||||
path: relativePath
|
||||
}
|
||||
}
|
||||
return { success: true, payload }
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
ipcMain.handle('image:getStatus', async () =>
|
||||
inspectImageDecryptionStatus(imageKeyConfigService.getConfig())
|
||||
)
|
||||
|
||||
Vendored
+2
@@ -39,6 +39,7 @@ import type {
|
||||
SaveImageKeyRequest,
|
||||
TestImageDecryptionRequest
|
||||
} from '../shared/image-decryption'
|
||||
import type { ImageDebugInfoRequest, ImageDebugInfoResult } from '../shared/image-debug-info'
|
||||
import type {
|
||||
AIChatRequestOptions,
|
||||
AiSearchExternalAuthorizationRequest,
|
||||
@@ -458,6 +459,7 @@ declare global {
|
||||
isThumb?: boolean
|
||||
filePath?: string
|
||||
}>
|
||||
getImageDebugInfo: (request: ImageDebugInfoRequest) => Promise<ImageDebugInfoResult>
|
||||
getVideo: (
|
||||
hashes: string[],
|
||||
options?: {
|
||||
|
||||
@@ -83,6 +83,7 @@ import type {
|
||||
import type { CacheClearScope, CacheSummary } from '../shared/cache'
|
||||
import type { ExportRequest, ExportJobProgress } from '../shared/export'
|
||||
import type { ImageDecoderSelectionResult, ImageDecoderStatus } from '../shared/image-decryption'
|
||||
import type { ImageDebugInfoRequest, ImageDebugInfoResult } from '../shared/image-debug-info'
|
||||
import type { AccountDiscoveryResult } from '../shared/database-key'
|
||||
import type {
|
||||
VoiceBatchConversationSummary,
|
||||
@@ -394,6 +395,8 @@ const api = {
|
||||
includeData?: boolean
|
||||
}
|
||||
) => ipcRenderer.invoke('db:getImage', imageMd5, imageDatNameOrThumb, sessionId, options),
|
||||
getImageDebugInfo: (request: ImageDebugInfoRequest): Promise<ImageDebugInfoResult> =>
|
||||
ipcRenderer.invoke('image:getDebugInfo', request),
|
||||
getVideo: (
|
||||
hashes: string[],
|
||||
options?: {
|
||||
|
||||
@@ -6,6 +6,9 @@ interface ImageBubbleProps {
|
||||
imageMd5?: string
|
||||
imageDatName?: string
|
||||
sessionId?: string
|
||||
localId?: number
|
||||
serverId?: string
|
||||
createTime?: number
|
||||
isThumb?: boolean
|
||||
fallbackUrl?: string
|
||||
onImageClick?: (imageUrl: string) => void
|
||||
@@ -15,6 +18,9 @@ export function ImageBubble({
|
||||
imageMd5,
|
||||
imageDatName,
|
||||
sessionId,
|
||||
localId,
|
||||
serverId,
|
||||
createTime,
|
||||
fallbackUrl,
|
||||
onImageClick
|
||||
}: ImageBubbleProps): JSX.Element {
|
||||
@@ -125,6 +131,34 @@ export function ImageBubble({
|
||||
alert('图片已复制')
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制的是「消息定位信息」而非图片内容:
|
||||
* 不带 aeskey / XML / fileid / 带票据的下载地址。
|
||||
*/
|
||||
const handleCopyDebugInfo = async (event: MouseEvent): Promise<void> => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
try {
|
||||
const result = await window.api.getImageDebugInfo({
|
||||
sessionId,
|
||||
localId,
|
||||
serverId,
|
||||
createTime,
|
||||
imageMd5,
|
||||
imageDatName
|
||||
})
|
||||
if (!result.success || !result.payload) {
|
||||
alert(result.error ? `图片调试信息获取失败:${result.error}` : '图片调试信息获取失败')
|
||||
return
|
||||
}
|
||||
const text = JSON.stringify(result.payload, null, 2)
|
||||
await navigator.clipboard.writeText(text)
|
||||
alert('图片调试信息已复制')
|
||||
} catch (error) {
|
||||
alert(error instanceof Error ? `图片调试信息复制失败:${error.message}` : '图片调试信息复制失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleClick = async (): Promise<void> => {
|
||||
if (!imageUrl && !error) return
|
||||
if (!imageMd5 && !imageDatName) {
|
||||
@@ -196,6 +230,7 @@ export function ImageBubble({
|
||||
tabIndex={0}
|
||||
aria-label="查看图片"
|
||||
onClick={handleClick}
|
||||
onContextMenu={handleCopyDebugInfo}
|
||||
onKeyDown={handlePreviewKeyDown}
|
||||
>
|
||||
<img
|
||||
|
||||
@@ -74,6 +74,9 @@ export function MessageBubble({
|
||||
imageMd5={message.contentData.md5}
|
||||
imageDatName={message.contentData.datName}
|
||||
sessionId={message.sessionId}
|
||||
localId={message.localId}
|
||||
serverId={message.serverId}
|
||||
createTime={message.createTime}
|
||||
onImageClick={onImageClick}
|
||||
/>
|
||||
) : isVideo && message.contentData && message.contentData.type === 'video' ? (
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 图片调试定位信息。
|
||||
*
|
||||
* 只用于把「用户点中的那一条图片消息」精确交给本地排查工具,
|
||||
* 不承载任何密钥、完整 XML 或图片内容。
|
||||
*
|
||||
* 所有消息 ID 一律用字符串:serverId 是 64 位整数,
|
||||
* 经 Number 转换会在 2^53 以上丢精度,届时定位会指向另一条消息。
|
||||
*
|
||||
* 字段即契约:结构里只保留消费方实际使用的定位/验收字段;
|
||||
* 拿不到的字段(如表名、宽高)直接不出现,不要加 null 占位。
|
||||
*/
|
||||
export const IMAGE_DEBUG_KIND = 'tracememo.image-debug' as const
|
||||
|
||||
export type ImageDebugQuality = 'thumbnail' | 'normal' | 'original' | 'unknown'
|
||||
|
||||
export interface ImageDebugMessage {
|
||||
/** 本机账号定位标识;取不到时为 null。 */
|
||||
accountId: string | null
|
||||
conversationId: string | null
|
||||
localId: string | null
|
||||
/** 消息唯一键;跨库定位一律用它,不要依赖 localId。 */
|
||||
serverId: string | null
|
||||
/** 消息创建时间,单位:秒(epoch seconds),不是毫秒。 */
|
||||
createTimeSeconds: number | null
|
||||
}
|
||||
|
||||
export interface ImageDebugPayload {
|
||||
kind: typeof IMAGE_DEBUG_KIND
|
||||
message: ImageDebugMessage
|
||||
image: {
|
||||
md5: string | null
|
||||
datName: string | null
|
||||
}
|
||||
display: {
|
||||
quality: ImageDebugQuality
|
||||
/** 已有的质量判定依据(如命中的候选文件名)。 */
|
||||
evidence: string | null
|
||||
/** 相对账号根目录的资源路径;取不到时为 null。 */
|
||||
path: string | null
|
||||
}
|
||||
}
|
||||
|
||||
/** 渲染进程 → 主进程的查询入参。 */
|
||||
export interface ImageDebugInfoRequest {
|
||||
sessionId?: string
|
||||
localId?: number
|
||||
serverId?: string
|
||||
createTime?: number
|
||||
imageMd5?: string
|
||||
imageDatName?: string
|
||||
}
|
||||
|
||||
export interface ImageDebugInfoResult {
|
||||
success: boolean
|
||||
payload?: ImageDebugPayload
|
||||
error?: string
|
||||
}
|
||||
Reference in new issue
Block a user