Skip to content

Commit

Permalink
Merge pull request #7 from crawlab-team/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tikazyq authored Sep 19, 2019
2 parents d016569 + 9d58d82 commit 9b90d97
Show file tree
Hide file tree
Showing 63 changed files with 2,298 additions and 1,826 deletions.
22 changes: 2 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
FROM tikazyq/crawlab:latest
FROM jelastic/nodejs:8.16.1-npm

ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 8.12.0

RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install v$NODE_VERSION \
&& nvm use v$NODE_VERSION \
&& nvm alias default v$NODE_VERSION
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

# frontend port
EXPOSE 8080

# backend port
EXPOSE 8000

# start backend
CMD ["/bin/sh", "/app/docker_init.sh"]
COPY . /app
37 changes: 31 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,43 @@
const os = require('os')
const exec = require('child_process').exec
const path = require('path')
const program = require('commander')
const program = require('caporal')

program
.command('start')
.action(async () => {
.command('start', 'Start ArtiPub server')
.option('-H, --host', 'MongoDB host name', null)
.option('-P, --port', 'MongoDB port number', null, '27017')
.option('-d, --db', 'MongoDB database name', null, 'artipub')
.option('-u, --username', 'MongoDB username', null, '')
.option('-p, --password', 'MongoDB password', null, '')
.action((...arr) => {
const cmdObj = arr[arr.length - 2]

const umiCmd = path.join(
__dirname,
'node_modules',
'.bin',
os.platform().match(/^win/) ? 'umi' : 'umi.cmd'
)
exec(umiCmd, ['dev'])
os.platform()
.match(/^win/) ? 'umi.cmd' : 'umi'
) + ' dev'

// 开启前端服务
console.log(umiCmd)
exec(umiCmd, { shell: true })

const host = cmdObj.host || 'localhost'
const port = cmdObj.port || '27017'
const db = cmdObj.db || 'artipub'
const username = cmdObj.username || ''
const password = cmdObj.password || ''

process.env.MONGO_HOST = host
process.env.MONGO_PORT = port
process.env.MONGO_DB = db
process.env.MONGO_USERNAME = username
process.env.MONGO_PASSWORD = password

// 开启后段服务
require('./server')
})

Expand Down
3 changes: 0 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ module.exports = {
MONGO_DB: 'artipub',
MONGO_USERNAME: '',
MONGO_PASSWORD: '',

// HEADLESS: true
HEADLESS: false
}
15 changes: 14 additions & 1 deletion config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ export const apiEndpoint = 'http://localhost:3000';

export default {
plugins,
history: 'hash',
block: {
defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
defaultGitUrl: 'https://github.com/crawlab-team/artipub',
},
hash: true,
targets: {
Expand Down Expand Up @@ -145,6 +146,18 @@ export default {
icon: 'read',
component: './ArticleList/ArticleList',
},
{
path: '/helper',
name: 'helper',
icon: 'key',
component: './Helper/Helper',
},
{
path: '/environments',
name: 'environments',
icon: 'setting',
component: './Environment/EnvironmentList',
},
{
component: './404',
},
Expand Down
53 changes: 32 additions & 21 deletions constants.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
module.exports = {
platform: {
JUEJIN: 'juejin',
SEGMENTFAULT: 'segmentfault',
JIANSHU: 'jianshu',
CSDN: 'csdn',
ZHIHU: 'zhihu'
},
status: {
NOT_STARTED: 'not-started',
PROCESSING: 'processing',
FINISHED: 'finished',
ERROR: 'error'
},
authType: {
LOGIN: 'login',
COOKIES: 'cookie'
},
editorType: {
MARKDOWN: 'markdown',
RICH_TEXT: 'rich-text'
}
platform: {
JUEJIN: 'juejin',
SEGMENTFAULT: 'segmentfault',
JIANSHU: 'jianshu',
CSDN: 'csdn',
ZHIHU: 'zhihu',
OSCHINA: 'oschina',
TOUTIAO: 'toutiao',
},
status: {
NOT_STARTED: 'not-started',
PROCESSING: 'processing',
FINISHED: 'finished',
ERROR: 'error'
},
authType: {
LOGIN: 'login',
COOKIES: 'cookie'
},
editorType: {
MARKDOWN: 'markdown',
RICH_TEXT: 'rich-text'
},
environment: {
UPDATE_STATS_CRON: 'update_stats_cron',
ENABLE_CHROME_DEBUG: 'enable_chrome_debug',
},
cookieStatus: {
NO_COOKIE: 'no_cookie',
EXPIRED: 'expired',
EXISTS: 'exists',
},
}
22 changes: 0 additions & 22 deletions credentials.example.json

This file was deleted.

22 changes: 0 additions & 22 deletions credentials.json

This file was deleted.

122 changes: 80 additions & 42 deletions data.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,83 @@
const constants = require('./constants')
module.exports = {
platforms: [
{
name: constants.platform.JUEJIN,
label: '掘金',
editorType: constants.editorType.MARKDOWN,
url: 'https://juejin.im',
description: '掘金是一个帮助开发者成长的社区,是给开发者用的 Hacker News,给设计师用的 Designer News,和给产品经理用的 Medium。掘金的技术文章由稀土上聚集的技术大牛和极客共同编辑为你筛选出最优质的干货,其中包括:Android、iOS、前端、后端等方面的内容。用户每天都可以在这里找到技术世界的头条内容。与此同时,掘金内还有沸点、掘金翻译计划、线下活动、专栏文章等内容。即使你是 GitHub、StackOverflow、开源中国的用户,我们相信你也可以在这里有所收获。',
enableImport: true,
},
{
name: constants.platform.SEGMENTFAULT,
label: 'SegmentFault',
editorType: constants.editorType.MARKDOWN,
url: 'https://segmentfault.com',
description: 'SegmentFault 思否 为开发者提供问答、学习与交流编程知识的平台,创造属于开发者的时代!',
enableImport: false,
},
{
name: constants.platform.CSDN,
label: 'CSDN',
editorType: constants.editorType.RICH_TEXT,
url: 'https://blog.csdn.net',
description: 'CSDN博客-专业IT技术发表平台',
enableImport: false,
},
{
name: constants.platform.JIANSHU,
label: '简书',
editorType: constants.editorType.MARKDOWN,
url: 'https://jianshu.com',
description: '简书是一个优质的创作社区,在这里,你可以任性地创作,一篇短文、一张照片、一首诗、一幅画……我们相信,每个人都是生活中的艺术家,有着无穷的创造力。',
enableImport: false,
},
{
name: constants.platform.ZHIHU,
label: '知乎',
editorType: constants.editorType.MARKDOWN,
url: 'https://zhihu.com',
description: '有问题,上知乎。知乎,可信赖的问答社区,以让每个人高效获得可信赖的解答为使命。知乎凭借认真、专业和友善的社区氛围,结构化、易获得的优质内容,基于问答的内容生产方式和独特的社区机制,吸引、聚集了各行各业中大量的亲历者、内行人、领域专家、领域爱好者,将高质量的内容透过人的节点来成规模地生产和分享。用户通过问答等交流方式建立信任和连接,打造和提升个人影响力,并发现、获得新机会。',
enableImport: false,
}
]
// 平台
platforms: [
{
name: constants.platform.JUEJIN,
label: '掘金',
editorType: constants.editorType.MARKDOWN,
url: 'https://juejin.im',
description: '掘金是一个帮助开发者成长的社区,是给开发者用的 Hacker News,给设计师用的 Designer News,和给产品经理用的 Medium。掘金的技术文章由稀土上聚集的技术大牛和极客共同编辑为你筛选出最优质的干货,其中包括:Android、iOS、前端、后端等方面的内容。用户每天都可以在这里找到技术世界的头条内容。与此同时,掘金内还有沸点、掘金翻译计划、线下活动、专栏文章等内容。即使你是 GitHub、StackOverflow、开源中国的用户,我们相信你也可以在这里有所收获。',
enableImport: false,
enableLogin: true,
},
{
name: constants.platform.SEGMENTFAULT,
label: 'SegmentFault',
editorType: constants.editorType.MARKDOWN,
url: 'https://segmentfault.com',
description: 'SegmentFault 思否 为开发者提供问答、学习与交流编程知识的平台,创造属于开发者的时代!',
enableImport: false,
enableLogin: true,
},
{
name: constants.platform.CSDN,
label: 'CSDN',
editorType: constants.editorType.RICH_TEXT,
url: 'https://blog.csdn.net',
description: 'CSDN博客-专业IT技术发表平台',
enableImport: false,
enableLogin: false,
},
{
name: constants.platform.JIANSHU,
label: '简书',
editorType: constants.editorType.MARKDOWN,
url: 'https://jianshu.com',
description: '简书是一个优质的创作社区,在这里,你可以任性地创作,一篇短文、一张照片、一首诗、一幅画……我们相信,每个人都是生活中的艺术家,有着无穷的创造力。',
enableImport: false,
enableLogin: false,
},
{
name: constants.platform.ZHIHU,
label: '知乎',
editorType: constants.editorType.MARKDOWN,
url: 'https://zhihu.com',
description: '有问题,上知乎。知乎,可信赖的问答社区,以让每个人高效获得可信赖的解答为使命。知乎凭借认真、专业和友善的社区氛围,结构化、易获得的优质内容,基于问答的内容生产方式和独特的社区机制,吸引、聚集了各行各业中大量的亲历者、内行人、领域专家、领域爱好者,将高质量的内容透过人的节点来成规模地生产和分享。用户通过问答等交流方式建立信任和连接,打造和提升个人影响力,并发现、获得新机会。',
enableImport: false,
enableLogin: false,
},
{
name: constants.platform.OSCHINA,
label: '开源中国',
editorType: constants.editorType.RICH_TEXT,
url: 'https://www.oschina.net',
description: 'OSCHINA.NET 是目前领先的中文开源技术社区。我们传播开源的理念,推广开源项目,为 IT 开发者提供了一个发现、使用、并交流开源技术的平台',
enableImport: false,
enableLogin: false,
},
{
name: constants.platform.TOUTIAO,
label: '今日头条',
editorType: constants.editorType.MARKDOWN,
url: 'https://www.toutiao.com',
description: '《今日头条》(www.toutiao.com)是一款基于数据挖掘的推荐引擎产品,它为用户推荐有价值的、个性化的信息,提供连接人与信息的新型服务,是国内移动互联网领域成长最快的产品服务之一。',
enableImport: false,
enableLogin: false,
}
],

// 环境变量
environments: [
{
_id: constants.environment.UPDATE_STATS_CRON,
label: '更新文章统计数据频率',
value: '0 0/30 * * * *'
},
{
_id: constants.environment.ENABLE_CHROME_DEBUG,
label: 'Chrome浏览器调试模式',
value: 'Y'
}
]
}
9 changes: 6 additions & 3 deletions exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Runner {
constructor() {
}

run() {
async run() {
// 任务执行器
const taskLock = new AsyncLock()
const taskCronJob = new CronJob('* * * * * *', () => {
Expand All @@ -42,15 +42,18 @@ class Runner {
})
taskCronJob.start()

// 获取环境变量
const updateStatsCron = await models.Environment.findOne({ _id: constants.environment.UPDATE_STATS_CRON })

// 数据统计执行器
const statsLock = new AsyncLock()
const statsCronJob = new CronJob('0 0/30 * * * *', () => {
const statsCronJob = new CronJob(updateStatsCron.value, () => {
if (!statsLock.isBusy()) {
statsLock.acquire('key', async () => {
const tasks = await models.Task.find({
url: {
$ne: '',
$exists:true
$exists: true
}
})
for (let i = 0; i < tasks.length; i++) {
Expand Down
Loading

0 comments on commit 9b90d97

Please sign in to comment.