Skip to content
This repository has been archived by the owner on Apr 10, 2022. It is now read-only.

Commit

Permalink
更新默认设置;更新规则;规则加载失败时使用内置规则
Browse files Browse the repository at this point in the history
  • Loading branch information
xiandanin committed Jan 14, 2020
1 parent fb76b92 commit 939c6b0
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 57 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "magnetw",
"version": "3.1.0",
"version": "3.1.1",
"description": "磁力链接聚合搜索",
"license": "GNU General Public License v3.0",
"main": "./dist/electron/main.js",
"scripts": {
"build": "cross-env BUILD_TARGET=electron node .electron-vue/build.js && electron-builder --platform=all",
"build": "cross-env BUILD_TARGET=electron node .electron-vue/build.js && electron-builder -mwl",
"build:dir": "cross-env BUILD_TARGET=electronnode .electron-vue/build.js && electron-builder --dir",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:mac": "cross-env BUILD_TARGET=electron node .electron-vue/build.js && electron-builder --platform=mac",
"build:win": "cross-env BUILD_TARGET=electron node .electron-vue/build.js && electron-builder --platform=win",
"build:mac": "cross-env BUILD_TARGET=electron node .electron-vue/build.js && electron-builder --mac",
"build:win": "cross-env BUILD_TARGET=electron node .electron-vue/build.js && electron-builder --win",
"build:service": "node scripts/build-service.js",
"dev": "cross-env BUILD_TARGET=electron node .electron-vue/dev-runner.js",
"lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter src",
Expand Down Expand Up @@ -85,6 +85,7 @@
"request": "^2.88.0",
"request-promise-native": "^1.0.7",
"socks-proxy-agent": "^4.0.2",
"tunnel": "0.0.6",
"urijs": "^1.19.2",
"vue": "^2.6.11",
"vue-clipboard2": "^0.3.1",
Expand Down Expand Up @@ -116,8 +117,8 @@
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^7.1.8",
"electron-builder": "^21.2.0",
"electron-debug": "^1.5.0",
"electron-builder": "^22.2.0",
"electron-debug": "^3.0.0",
"electron-devtools-installer": "^2.2.4",
"element-ui": "^2.13.0",
"eslint": "^4.19.1",
Expand Down
22 changes: 19 additions & 3 deletions rule.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
{
"id": "btdb",
"name": " BTDB",
"proxy": true,
"url": "https://btdb.io",
"paths": {
"time": "?s={k}&sort=time&page={p}",
Expand All @@ -124,7 +125,7 @@
{
"id": "btdiguo",
"name": "BT目录",
"url": "https://www.btweb.xyz",
"url": "https://www.aixiazai.xyz",
"paths": {
"time": "/search-update/{k}/page-{p}.html",
"size": "/search-size/{k}/page-{p}.html",
Expand Down Expand Up @@ -160,7 +161,7 @@
{
"id": "bthub",
"name": "BThub",
"url": "https://bthub.site",
"url": "https://bthub.xyz",
"paths": {
"preset": "/main-search-kw-{k}-{p}.html",
"size": "/main-search-kw-{k}-length-{p}.html",
Expand Down Expand Up @@ -194,6 +195,21 @@
"hot": "./div[2]/span[5]/b[1]"
}
},
{
"id": "alibt",
"name": " 阿里BT",
"url": "https://alibt.pw",
"paths": {
"preset": "/zh-cn/s/{p}/{k}"
},
"xpath": {
"group": "//*[@id=\"wrapper\"]/ul/li",
"magnet": "./p[1]/a/@href",
"name": "./p[1]/a",
"size": "./p[2]/span[2]",
"date": "./p[2]/span[1]"
}
},
{
"id": "mag",
"name": "MAG磁力站",
Expand Down Expand Up @@ -274,7 +290,7 @@
{
"id": "btfox",
"name": " btfox",
"url": "http://www.btfox.biz",
"url": "http://www.btfox.in",
"paths": {
"time": "/s?wd={k}&sort=time&page={p}",
"size": "/s?wd={k}&sort=length&page={p}",
Expand Down
21 changes: 0 additions & 21 deletions scripts/icns.sh

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/merge-filter-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ function unique (arr) {
return result
}

fs.writeFileSync('src/main/filter/keywords.txt', Buffer.from(uniqueWords.join('\n')).toString('base64'))
fs.writeFileSync('static/keywords.txt', Buffer.from(uniqueWords.join('\n')).toString('base64'))
2 changes: 0 additions & 2 deletions src/main/axios.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {remote} from 'electron'

const axios = require('axios')
const tunnel = require('tunnel')
const SocksProxyAgent = require('socks-proxy-agent')
Expand Down
4 changes: 2 additions & 2 deletions src/main/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ module.exports = function () {
// 使用代理
proxy: false,
// http|socks5
proxyType: 'http',
proxyType: 'socks5',
proxyHost: '127.0.0.1',
proxyPort: 1087,
proxyPort: 1080,
// 是否启用预加载 启用后会预加载下一页和下一个源站
preload: true,
// 缓存过期时间
Expand Down
5 changes: 4 additions & 1 deletion src/main/filter/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ const fs = require('fs')
const map = {}
let load = false

const isDev = process.env.NODE_ENV === 'development'

async function loadFilterData () {
if (load) {
return
}
load = true
const original = Buffer.from(fs.readFileSync(path.resolve(__dirname, './keywords.txt'), 'utf-8'), 'base64')
const file = isDev ? path.resolve('static/keywords.txt') : path.resolve(__dirname, './static/keywords.txt')
const original = Buffer.from(fs.readFileSync(file, 'utf-8'), 'base64')
const words = original.toString().split('\n')
words.forEach((line) => {
if (line) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// import fs from 'fs'

const moment = require('moment')
const logger = require('./logger')
const path = require('path')
const {ipcMain, app} = require('electron')
Expand Down Expand Up @@ -30,6 +29,12 @@ function getLocalConfig () {
}

function registerIPC (mainWindow) {
ipcMain.on('get-server-info', function (event) {
const configVariable = store.get('config_variable')
const newConfig = getConfig(configVariable)
event.sender.send('on-get-server-info', getServerInfo(), newConfig)
})

ipcMain.on('window-max', function () {
if (mainWindow.isMaximized()) {
mainWindow.unmaximize()
Expand Down
5 changes: 4 additions & 1 deletion src/main/middleware/response-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ module.exports = async (ctx, next) => {
ctx.throw(ctx.status, ctx.message)
}
} catch (e) {
let message = e.message
const statusCode = e.statusCode || 500
console.error(statusCode, e.message)
const maxLength = 100
const message = `${statusCode} - 请求异常,请查看日志`
if (statusCode !== 500) {
message = `${statusCode} - 请求源站异常,请查看日志`
}
ctx.status = statusCode
ctx.body = {
success: false,
Expand Down
25 changes: 15 additions & 10 deletions src/main/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,21 @@ function parseDetailDocument (document, expression) {
async function loadRuleByURL () {
const url = config.ruleUrl
let rule
if (url.startsWith('http')) {
// 如果是网络文件
console.info('获取网络规则文件', url)
rule = await request(url, {timeout: 8000, json: true})
} else {
console.info('读取本地规则文件', url)
rule = JSON.parse(fs.readFileSync(url))
}
if (!Array.isArray(rule) || rule.length <= 0) {
throw new Error('规则格式不正确')
try {
if (url.startsWith('http')) {
// 如果是网络文件
console.info('获取网络规则文件', url)
rule = await request(url, {timeout: 8000, json: true})
} else {
console.info('读取本地规则文件', url)
rule = JSON.parse(fs.readFileSync(url))
}
if (!Array.isArray(rule) || rule.length <= 0) {
throw new Error('规则格式不正确')
}
} catch (e) {
console.error(e.message, '规则加载失败,将使用内置规则')
rule = require('../../rule.json')
}
cacheManager.set('rule_json', JSON.stringify(rule))

Expand Down
41 changes: 40 additions & 1 deletion src/renderer/components/GuidePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
<span slot="title">{{title}}</span>
</el-alert>
<div class="guide-page-content">
<div class="guide-page-log" v-if="serverInfo">
<div>搜索服务已启动,启动模式:{{serverInfo.customServerPort?'自定义':'自动分配'}},<span class="guide-page-log-success">{{serverInfo.local}}:{{serverInfo.port}}</span>
</div>
<div v-if="serverInfo.proxy">
代理已启用:<span class="guide-page-log-success">{{serverInfo.proxyType}}://{{serverInfo.proxyHost}}:{{serverInfo.proxyPort}}</span>,请在设置中“测试连接”检查代理是否可用
</div>
<div v-if="serverInfo.filterBare||serverInfo.filterEmpty">内容过滤已启用</div>
<div v-show="serverInfo.message" class="guide-page-log-error">{{serverInfo.message}}</div>
</div>
<div v-for="it in $config.guide.content" class="guide-content">
<span class="guide-title">{{it.title}}</span>
<div class="guide-content-item" v-for="item in it.items">
Expand All @@ -23,18 +32,35 @@

<script>
import BrowserLink from './BrowserLink'
import {ipcRenderer} from 'electron'
export default {
props: ['message', 'type', 'title'],
components: {
BrowserLink
},
data () {
return {}
return {
serverInfo: null
}
},
computed: {},
methods: {},
created () {
// 接收设置刷新的通知
this.$on('global:event-config-refreshed', (config, oldConfig) => {
ipcRenderer.send('get-server-info')
})
ipcRenderer.on('on-get-server-info', (event, serverInfo, config) => {
if (serverInfo) {
const info = {}
Object.assign(info, serverInfo, config)
this.serverInfo = info
} else {
this.serverInfo = {message: '搜索服务启动失败,请查看日志'}
}
})
ipcRenderer.send('get-server-info')
}
}
</script>
Expand Down Expand Up @@ -90,4 +116,17 @@
color: $color-text-gray;
font-size: $font-size;
}
.guide-page-log {
color: $--color-text-primary;
line-height: 300%;
}
.guide-page-log-success {
color: $--color-success;
}
.guide-page-log-error {
color: $--color-danger;
}
</style>
10 changes: 6 additions & 4 deletions src/renderer/pages/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
</div>
</div>
<!--搜索结果-->
<div class="search-items-message" v-if="page.originalCount">
搜索到{{page.originalCount}}条结果
<span v-show="getItemsCount>0">,已过滤{{getItemsCount}}条,如需显示请更改设置</span>
</div>
<div ref="pagerSearchItems" class="pager-search-items" v-loading="loading.table">
<div class="index-main-content" v-if="page.items">
<div class="search-items-message">
搜索到{{page.originalCount}}条结果
<span v-show="getItemsCount>0">,已过滤{{getItemsCount}}条,如需显示请更改设置</span>
</div>
<pager-items :items="page.items"
:emptyMessage="page.emptyMessage"
:keyword="page.current.keyword"
Expand Down Expand Up @@ -268,6 +268,8 @@
.search-items-message {
color: $--color-success;
font-size: 14px;
line-height: 14px;
margin-top: 15px;
}
</style>
4 changes: 1 addition & 3 deletions src/renderer/pages/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
const after = JSON.stringify(this.config)
const local = JSON.stringify(this.localConfig)
// 如果设置改变
if (after !== local) {
this.saveDisabled = false
}
this.saveDisabled = after === local
},
deep: true
}
Expand Down
File renamed without changes.

0 comments on commit 939c6b0

Please sign in to comment.