UNPKG

ovm

Version:

Obsidian Vaults Manager

67 lines 2.92 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPluginVersion = exports.findPluginInRegistry = exports.fetchPlugins = exports.handleExceedRateLimitError = void 0; const node_fetch_cache_1 = __importStar(require("node-fetch-cache")); const os_1 = require("os"); const cacheDirectory = (0, os_1.platform)() === 'win32' ? `${(0, os_1.tmpdir)()}\\.cache\\obsidian-utils` : `${(0, os_1.tmpdir)()}/.cache/obsidian-utils`; const fetch = node_fetch_cache_1.default.create({ cache: new node_fetch_cache_1.FileSystemCache({ cacheDirectory, ttl: 3600, }), calculateCacheKey: async (url, options) => { return JSON.stringify([options?.method, url]); }, shouldCacheResponse: (response) => response.ok, }); const handleExceedRateLimitError = (error) => { if (error instanceof Error && 'message' in error && error.message.search('find') !== -1) { const apiRateLimitMessage = 'API rate limit exceeded, Try again later. Check out Github documentation for rate limit.'; throw new Error(apiRateLimitMessage); } }; exports.handleExceedRateLimitError = handleExceedRateLimitError; const fetchPlugins = async () => { const url = 'https://raw.githubusercontent.com/obsidianmd/obsidian-releases/master/community-plugins.json'; const response = await fetch(url); if (!response.ok) { throw new Error('Failed to fetch plugins'); } return response.json(); }; exports.fetchPlugins = fetchPlugins; const findPluginInRegistry = async (name) => { const pluginsRegistry = await (0, exports.fetchPlugins)(); return pluginsRegistry.find(({ id }) => id === name); }; exports.findPluginInRegistry = findPluginInRegistry; const getPluginVersion = (plugin) => plugin?.version ?? 'latest'; exports.getPluginVersion = getPluginVersion; //# sourceMappingURL=github.js.map