Files
oh-my-opencode/src/shared/opencode-message-dir.ts
T

30 lines
866 B
TypeScript
Raw Normal View History

import { existsSync, readdirSync } from "node:fs"
import { join } from "node:path"
import { MESSAGE_STORAGE } from "./opencode-storage-paths"
import { log } from "./logger"
export function getMessageDir(sessionID: string): string | null {
if (!sessionID.startsWith("ses_")) return null
2026-02-16 14:59:10 +09:00
if (/[/\\]|\.\./.test(sessionID)) return null
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
}
}
2026-02-16 00:02:44 +09:00
} catch (error) {
log("[opencode-message-dir] Failed to scan message directories", { sessionID, error: String(error) })
return null
}
return null
}