22 lines
549 B
TypeScript
22 lines
549 B
TypeScript
|
|
import { existsSync, readdirSync } from "node:fs"
|
||
|
|
import { join } from "node:path"
|
||
|
|
import { MESSAGE_STORAGE } from "../constants"
|
||
|
|
|
||
|
|
export function getMessageDir(sessionID: string): string {
|
||
|
|
if (!existsSync(MESSAGE_STORAGE)) return ""
|
||
|
|
|
||
|
|
const directPath = join(MESSAGE_STORAGE, sessionID)
|
||
|
|
if (existsSync(directPath)) {
|
||
|
|
return directPath
|
||
|
|
}
|
||
|
|
|
||
|
|
for (const dir of readdirSync(MESSAGE_STORAGE)) {
|
||
|
|
const sessionPath = join(MESSAGE_STORAGE, dir, sessionID)
|
||
|
|
if (existsSync(sessionPath)) {
|
||
|
|
return sessionPath
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return ""
|
||
|
|
}
|