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.1.8-beta.0 to 0.1.8-beta.1

36

lib/index.js

@@ -27,3 +27,6 @@ 'use strict';

const view = _config.view;
let view = _config.view || '';
if (view === '/') {
view = '';
}
const prefix = _config.prefix;

@@ -41,3 +44,15 @@ const showSearch = _config.showSearch;

router.get('GetDocument', `${prefix}/*`, async (ctx, next) => {
const locator = ctx.request.path.split(`${prefix}/`)[1];
const locator = ctx.request.path.replace(`${prefix}/`, '');
if (!locator) {
return;
}
if (locator.startsWith('http')) {
try {
ctx.redirect(locator);
} catch (e) {
ctx.logger.error('redirect failed: %s-%s', e && e.message, e && e.stack);
ctx.body = `can not redirect to ${locator}, please check domainWhiteList in your config.`;
}
return;
}
const result = await yuqueClient.getDocument(locator);

@@ -56,6 +71,2 @@ ctx.status = 200;

router.get(`GetDocumentView-${view}`, `${view === '/' ? '' : view}/*`, async (ctx, next) => {
ctx.body = await yuqueClient.getDocumentView();
next();
});
router.get(`GetDocumentView-${view}`, `${view}`, async (ctx, next) => {

@@ -65,6 +76,17 @@ ctx.body = await yuqueClient.getDocumentView();

});
router.get(`GetDocumentView-${view}`, `${view}/*`, async (ctx, next) => {
const subPath = ctx.request.path.replace(`${view}/`, '');
if (subPath.startsWith('http')) {
try {
ctx.redirect(subPath);
} catch (e) {
ctx.logger.error('redirect failed: %s-%s', e && e.message, e && e.stack);
ctx.body = `can not redirect to ${subPath}, please check domainWhiteList in your config.`;
}
return;
}
ctx.body = await yuqueClient.getDocumentView();
next();
});
};
};

49

lib/YuqueClient.js

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

category,
...dir
});

@@ -75,3 +76,2 @@ }

const docs = await this.request(`${this.baseUrl}/users/${config.user}`);
// console.log('docs: ', docs);
if (!docs || !docs.data) {

@@ -93,4 +93,3 @@ throw new Error(`Get directories from lark failed, namespace: ${namespace}`);

const namespace = config.namespace;
const docs = await this.request(`${this.baseUrl}/repos/${namespace}/docs`);
// console.log('docs: ', docs);
const docs = await this.request(`${this.baseUrl}/repos/${namespace}/docs?include_hits=true`);
if (!docs || !docs.data) {

@@ -100,18 +99,33 @@ throw new Error(`Get directories from lark failed, namespace: ${namespace}`);

console.log('getDirectories SUCCESSFULLY');
return docs.data;
const documents = docs.data;
if (!documents || !documents.length) {
return [];
}
return documents.map(document => {
return {
id: document.id,
title: document.title,
slug: document.slug,
hits: document.hits,
created_at: document.created_at,
updated_at: document.updated_at,
content_updated_at: document.content_updated_at,
};
});
}
async getDocumentView() {
const { config } = this;
if (config.view === '/') {
config.view = '';
}
let directories, documents, userInfo;
[ directories, documents ] = await Promise.all([
this.getDirectories(),
this.getDocuments(),
]);
if (config.user) {
[ directories, userInfo ] = await Promise.all([
this.getDirectories(),
this.getUserInfo(),
]);
} else {
directories = await this.getDirectories();
userInfo = await this.getUserInfo();
}
if (directories.length <= 20) {
documents = await this.getDocuments();
directories = await Promise.all(directories.map(async directory => {

@@ -142,3 +156,3 @@ directory.document = await this.getDocument(directory.locator);

documents: documents || [],
userInfo,
userInfo: userInfo || {},
}, config))}</script>

@@ -184,2 +198,9 @@ <script src="https://cdn.jsdelivr.net/npm/${config.npm}/build/index.js"></script>

creator: data.creator && data.creator.name,
created_at: data.created_at,
updated_at: data.updated_at,
published_at: data.published_at,
word_count: data.word_count,
likes_count: data.likes_count,
comments_count: data.comments_count,
hits: data.hits
};

@@ -231,2 +252,2 @@ } catch (e) {

module.exports = LarkService;
module.exports = LarkService;
{
"name": "@ablula/egg-yuque-viewer",
"author": "mark.ck",
"version": "0.1.8-beta.0",
"version": "0.1.8-beta.1",
"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