rag-kb-system / debug-yuque-notes.ts
duqing2026's picture
同步 hf
9ed89c8
import * as dotenv from "dotenv";
import fetch from "node-fetch";
dotenv.config({ path: ".env.local" });
dotenv.config();
const TOKEN = process.env.YUQUE_TOKEN;
const BASE_URL = "https://www.yuque.com/api/v2";
interface Note {
tags?: string[];
[key: string]: unknown;
}
interface YuqueResponse {
data: {
notes: Note[];
};
}
async function checkNotes() {
if (!TOKEN) {
console.error("No YUQUE_TOKEN found in env");
return;
}
console.log("Fetching notes...");
const url = `${BASE_URL}/notes?offset=0&limit=50`;
const headers = {
"X-Auth-Token": TOKEN,
"User-Agent": "debug-script",
"Content-Type": "application/json",
};
try {
const res = await fetch(url, { headers });
if (!res.ok) {
console.error(`Error: ${res.status} ${res.statusText}`);
const text = await res.text();
console.error(text);
return;
}
const data = await res.json() as unknown as YuqueResponse;
const notes = data.data.notes || [];
console.log(`Found ${notes.length} notes.`);
const notesWithTags = notes.filter((n) => n.tags && n.tags.length > 0);
console.log(`Notes with tags: ${notesWithTags.length}`);
if (notesWithTags.length > 0) {
console.log("Example note with tags:");
console.log(JSON.stringify(notesWithTags[0], null, 2));
} else {
console.log("No tags found in the first 50 notes.");
}
} catch (e) {
console.error("Failed:", e);
}
}
checkNotes();