async _loadFile(filePath) { debug('docsify')(`load > ${filePath}`) let content try { if (isAbsolutePath(filePath)) { const res = await fetch(filePath) if (!res.ok) { throw Error() } content = await res.text() this.lock = 0 } else { content = await readFileSync(filePath, 'utf8') this.lock = 0 } return content } catch (e) { this.lock = this.lock || 0 if (++this.lock > 10) { this.lock = 0 return } const fileName = basename(filePath) const result = await this._loadFile(resolvePathname(`../${fileName}`, filePath)) return result } }
static async callWS(ws, action, parameters) { // console.log("ws=", ws, botId); if (ws) { // logger.info("ws=", ws); // WIP const post = { action, parameters }; const path = ws.path || ""; const url = `${ws.url}${path}?class=${ws.classes[0]}&secret=${ws.secret}`; // console.log("url=", url); try { const response = await fetch(url, { method: "post", body: JSON.stringify(post), headers: { "Content-Type": "application/json" }, }); if (response.ok) { const json = await response.json(); if (json && json.result) { // logger.info("result=", json.result); return json.result; } } else { logger.info("EventsMiddleware.doCall fetch error : ", response); } } catch (e) { logger.info("EventsMiddleware.doCall fetch error : ", e.message); } } return null; }
headers: { "Content-Type": "application/json" }, }); if (response.ok) { const json = await response.json(); if (json && json.result) {
async _loadFile(filePath) { debug('docsify')(`load > ${filePath}`) let content try { if (isAbsolutePath(filePath)) { const res = await fetch(filePath) if (!res.ok) { throw Error() } content = await res.text() this.lock = 0 } else { content = await readFileSync(filePath, 'utf8') this.lock = 0 } return content } catch (e) { this.lock = this.lock || 0 if (++this.lock > 10) { this.lock = 0 return } const fileName = basename(filePath) const result = await this._loadFile(resolvePathname(`../${fileName}`, filePath)) return result } }