Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ablula/egg-yuque-viewer

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ablula/egg-yuque-viewer - npm Package Compare versions

Comparing version 0.2.0-beta.1 to 0.2.0-beta.2

lib/cache.js

20

lib/YuqueClient.js

@@ -5,2 +5,3 @@ 'use strict';

const { deepMerge } = require('./utils');
const cache = require('./cache');
const BASE_URL = 'https://www.yuque.com/api/v2';

@@ -11,3 +12,3 @@

let miniIndex = 0;
if (segments && segments.length) {
if (segments && segments.length && content) {
miniIndex = segments.map(regexp => {

@@ -38,3 +39,3 @@ const idx = content.search(regexp);

title: item.title,
locator: item.target.slug,
locator: item.target && item.target.slug,
searchEngine: 1,

@@ -233,3 +234,3 @@ };

`${this.baseUrl}/search/?q=${encodeURIComponent(keywords)}&type=doc&scope=${config.namespace}`);
result.data = LarkService.formatSearchResult(result.data, {
const data = LarkService.formatSearchResult(result.data, {
segments: [ keywords ],

@@ -239,5 +240,5 @@ namespace: config.namespace,

return {
total: result.data.length,
total: data.length,
segments: [ keywords ],
data: result.data,
data,
};

@@ -248,2 +249,7 @@ }

const { app, config } = this;
if (cache.get(url)) {
app.logger.info('[EggYuqeuViewer] get data of %s from cache', url);
return cache.get(url);
}
app.logger.info('[EggYuqeuViewer] get data of %s from yuque', url);
const result = await app.curl(url, {

@@ -259,5 +265,9 @@ timeout: 5000,

});
if (result && +result.status === 429) {
app.logger.error('当前资源 %s 的访问频率过高,请稍后再试', url);
}
if (result.status !== 200 || !result.data) {
throw new Error(`request document from lark failed, url: ${url}`);
}
cache.set(url, {...result.data});
return result.data;

@@ -264,0 +274,0 @@ }

@@ -5,2 +5,3 @@ 'use strict';

const YuqueClient = require('./YuqueClient');
const cache = require('./cache');

@@ -131,2 +132,10 @@ class YuQueViewer {

});
this.unshiftRoute(`GetCache`, `/LIST-ABLULA-DOCUMENT-CACHE`, async (ctx, next) => {
const data = cache.listAll();
ctx.body = data;
});
this.unshiftRoute(`ClearCache`, `/CLEAR-ABLULA-DOCUMENT-CACHE`, async (ctx, next) => {
cache.clear();
ctx.body = 'ok';
});
}

@@ -133,0 +142,0 @@

{
"name": "@ablula/egg-yuque-viewer",
"author": "mark.ck",
"version": "0.2.0-beta.1",
"version": "0.2.0-beta.2",
"description": "egg plugin for yuque viewer",

@@ -6,0 +6,0 @@ "eggPlugin": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc