"use strict";
/**
 * Project Caffeine
 * Copyright (c) 2025-2026 Gitconomy Research
 *
 * SPDX-License-Identifier: MIT
 *
 * Contributors:
 * - 郭晧 <guohao@gitconomy.org> (Initial Author)
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listObsidianNotes = listObsidianNotes;
exports.readObsidianNote = readObsidianNote;
const promises_1 = __importDefault(require("fs/promises"));
const path_1 = __importDefault(require("path"));
// 【⚠️ 重要配置】请修改为你电脑上真实的 Markdown 笔记文件夹绝对路径！
const OBSIDIAN_VAULT_PATH = '/home/wguo/Downloads/MyVault';
async function listObsidianNotes() {
    try {
        const files = await promises_1.default.readdir(OBSIDIAN_VAULT_PATH);
        return files.filter(file => file.toLowerCase().endsWith('.md'));
    }
    catch (error) {
        console.error(`[Project Caffeine] 无法读取知识库目录: ${error.message}`);
        return [];
    }
}
async function readObsidianNote(filename) {
    const targetPath = path_1.default.resolve(OBSIDIAN_VAULT_PATH, filename);
    const safeVaultPath = path_1.default.resolve(OBSIDIAN_VAULT_PATH);
    // 核心防御：防止大模型通过传入 "../../" 读取系统敏感文件
    if (!targetPath.startsWith(safeVaultPath)) {
        throw new Error(`安全警告：越权访问拦截！禁止读取目录外的文件: ${filename}`);
    }
    try {
        const content = await promises_1.default.readFile(targetPath, 'utf-8');
        return content;
    }
    catch (error) {
        throw new Error(`无法读取笔记 [${filename}]: 文件可能不存在或无权限。`);
    }
}
//# sourceMappingURL=resourceService.js.map