Created
August 20, 2023 15:59
-
-
Save Syakhisk/ff8fc0619d7d56c1ad61cd66994028f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Install the plugin "Local REST API" and enable it. | |
* https://github.com/coddingtonbear/obsidian-local-rest-api | |
* | |
* Explore the API: | |
* https://coddingtonbear.github.io/obsidian-local-rest-api/ | |
*/ | |
import axios from "axios"; | |
import https from "https"; | |
// curl -X 'POST' \ | |
// 'https://127.0.0.1:27124/search/' \ | |
// -H 'accept: application/json' \ | |
// -H 'Authorization: Bearer 4d1eea014742d75137de07fa4b41c9fbb6df352a11a9aa6300dafc9558a5c057' \ | |
// -H 'Content-Type: application/vnd.olrapi.dataview.dql+txt' \ | |
// -d 'TABLE tag | |
// FROM "" | |
// WHERE file.tags | |
// FLATTEN file.tags AS tag' | |
const PORT = 27124; | |
const HOST = "https://127.0.0.1"; | |
const BASE_URL = `${HOST}:${PORT}/search`; | |
const API_TOKEN = | |
"4d1eea014742d75137de07fa4b41c9fbb6df352a11a9aa6300dafc9558a5c057"; | |
const api = axios.create({ | |
baseURL: BASE_URL, | |
headers: { | |
Authorization: `Bearer ${API_TOKEN}`, | |
"Content-Type": "application/vnd.olrapi.dataview.dql+txt", | |
}, | |
httpsAgent: new https.Agent({ | |
rejectUnauthorized: false, | |
}), | |
}); | |
const query = ` | |
TABLE tag | |
FROM "" | |
WHERE file.tags | |
FLATTEN file.tags AS tag | |
`; | |
/** @type {Array<{filename: string, result: {tag: string}}>} */ | |
const res = await api.post("/", query); | |
const tags = new Set(); | |
res.data.forEach((item) => { | |
tags.add(item.result.tag); | |
}); | |
for (const tag of tags.values()) { | |
console.log(tag); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment