2026-02-14 17:41:40 +09:00
|
|
|
import { existsSync, readdirSync } from "node:fs"
|
|
|
|
|
import { join } from "node:path"
|
2026-02-14 17:50:08 +09:00
|
|
|
import { getOpenCodeStorageDir } from "./data-path"
|
|
|
|
|
|
|
|
|
|
const MESSAGE_STORAGE = join(getOpenCodeStorageDir(), "message")
|
2026-02-14 17:41:40 +09:00
|
|
|
|
|
|
|
|
export function getMessageDir(sessionID: string): string | null {
|
2026-02-14 17:50:08 +09:00
|
|
|
if (!sessionID.startsWith("ses_")) return null
|
2026-02-14 17:41:40 +09:00
|
|
|
if (!existsSync(MESSAGE_STORAGE)) return null
|
|
|
|
|
|
|
|
|
|
const directPath = join(MESSAGE_STORAGE, sessionID)
|
|
|
|
|
if (existsSync(directPath)) {
|
|
|
|
|
return directPath
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (const dir of readdirSync(MESSAGE_STORAGE)) {
|
|
|
|
|
const sessionPath = join(MESSAGE_STORAGE, dir, sessionID)
|
|
|
|
|
if (existsSync(sessionPath)) {
|
|
|
|
|
return sessionPath
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
}
|