fix(config): fixed saving configuration on develop builds
This commit is contained in:
@ -14,7 +14,6 @@ import createWindow from "./helpers/window";
|
|||||||
// Special module holding environment variables which you declared
|
// Special module holding environment variables which you declared
|
||||||
// in config/env_xxx.json file.
|
// in config/env_xxx.json file.
|
||||||
import env from "env";
|
import env from "env";
|
||||||
import spiderCall from './spider'
|
|
||||||
|
|
||||||
const { spawn, exec } = require('child_process')
|
const { spawn, exec } = require('child_process')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
@ -35,6 +34,9 @@ if (env.name !== "production") {
|
|||||||
app.setPath("userData", `${userDataPath} (${env.name})`);
|
app.setPath("userData", `${userDataPath} (${env.name})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const spiderCall = require('./spider')
|
||||||
|
const appConfig = require('./config')
|
||||||
|
|
||||||
let sphinx = undefined
|
let sphinx = undefined
|
||||||
let spider = undefined
|
let spider = undefined
|
||||||
|
|
||||||
@ -88,12 +90,12 @@ const getSphinxPath = () => {
|
|||||||
return 'searchd'
|
return 'searchd'
|
||||||
}
|
}
|
||||||
|
|
||||||
const writeSphinxConfig = (path) => {
|
const writeSphinxConfig = (path, dbPath) => {
|
||||||
const config = `
|
const config = `
|
||||||
index torrents
|
index torrents
|
||||||
{
|
{
|
||||||
type = rt
|
type = rt
|
||||||
path = ${path}/database/torrents
|
path = ${dbPath}/database/torrents
|
||||||
|
|
||||||
rt_attr_string = hash
|
rt_attr_string = hash
|
||||||
rt_attr_string = name
|
rt_attr_string = name
|
||||||
@ -117,7 +119,7 @@ const writeSphinxConfig = (path) => {
|
|||||||
index files
|
index files
|
||||||
{
|
{
|
||||||
type = rt
|
type = rt
|
||||||
path = ${path}/database/files
|
path = ${dbPath}/database/files
|
||||||
|
|
||||||
rt_attr_string = path
|
rt_attr_string = path
|
||||||
rt_field = pathIndex
|
rt_field = pathIndex
|
||||||
@ -128,7 +130,7 @@ const writeSphinxConfig = (path) => {
|
|||||||
index statistic
|
index statistic
|
||||||
{
|
{
|
||||||
type = rt
|
type = rt
|
||||||
path = ${path}/database/statistic
|
path = ${dbPath}/database/statistic
|
||||||
|
|
||||||
rt_attr_bigint = size
|
rt_attr_bigint = size
|
||||||
rt_attr_bigint = files
|
rt_attr_bigint = files
|
||||||
@ -155,9 +157,9 @@ const writeSphinxConfig = (path) => {
|
|||||||
// clear dir in test env
|
// clear dir in test env
|
||||||
if(env.name === 'test')
|
if(env.name === 'test')
|
||||||
{
|
{
|
||||||
if (fs.existsSync(`${path}/database`)) {
|
if (fs.existsSync(`${dbPath}/database`)) {
|
||||||
fs.readdirSync(`${path}/database`).forEach(function(file, index){
|
fs.readdirSync(`${dbPath}/database`).forEach(function(file, index){
|
||||||
const curPath = `${path}/database` + "/" + file;
|
const curPath = `${dbPath}/database` + "/" + file;
|
||||||
if (!fs.lstatSync(curPath).isDirectory()) {
|
if (!fs.lstatSync(curPath).isDirectory()) {
|
||||||
fs.unlinkSync(curPath);
|
fs.unlinkSync(curPath);
|
||||||
}
|
}
|
||||||
@ -174,12 +176,13 @@ const writeSphinxConfig = (path) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(`${path}/database`)){
|
if (!fs.existsSync(`${dbPath}/database`)){
|
||||||
fs.mkdirSync(`${path}/database`);
|
fs.mkdirSync(`${dbPath}/database`);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(`${path}/sphinx.conf`, config)
|
fs.writeFileSync(`${path}/sphinx.conf`, config)
|
||||||
console.log(`writed sphinx config to ${path}`)
|
console.log(`writed sphinx config to ${path}`)
|
||||||
|
console.log('db path:', dbPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
const sphinxPath = path.resolve(getSphinxPath())
|
const sphinxPath = path.resolve(getSphinxPath())
|
||||||
@ -187,7 +190,8 @@ console.log('Sphinx Path:', sphinxPath)
|
|||||||
|
|
||||||
const startSphinx = (callback) => {
|
const startSphinx = (callback) => {
|
||||||
const sphinxConfigDirectory = app.getPath("userData")
|
const sphinxConfigDirectory = app.getPath("userData")
|
||||||
writeSphinxConfig(sphinxConfigDirectory)
|
appConfig['dbPath'] = appConfig.dbPath && appConfig.dbPath.length > 0 ? appConfig.dbPath : sphinxConfigDirectory;
|
||||||
|
writeSphinxConfig(sphinxConfigDirectory, appConfig.dbPath)
|
||||||
|
|
||||||
const config = `${sphinxConfigDirectory}/sphinx.conf`
|
const config = `${sphinxConfigDirectory}/sphinx.conf`
|
||||||
const options = ['--config', config]
|
const options = ['--config', config]
|
||||||
|
@ -36,7 +36,9 @@ let config = {
|
|||||||
trafficInterface: 'enp2s0',
|
trafficInterface: 'enp2s0',
|
||||||
trafficMax: 0,
|
trafficMax: 0,
|
||||||
trafficUpdateTime: 3, //secs
|
trafficUpdateTime: 3, //secs
|
||||||
trafficIgnoreDHT: false
|
trafficIgnoreDHT: false,
|
||||||
|
|
||||||
|
dbPath: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@ -59,7 +61,8 @@ const configProxy = new Proxy(config, {
|
|||||||
let obj = JSON.parse(data)
|
let obj = JSON.parse(data)
|
||||||
obj[prop] = value;
|
obj[prop] = value;
|
||||||
fs.writeFileSync(configPath, JSON.stringify(obj, null, 4), 'utf8');
|
fs.writeFileSync(configPath, JSON.stringify(obj, null, 4), 'utf8');
|
||||||
debug('saving config.json:', prop, '=', value)
|
debug('saving rats.json:', prop, '=', value)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -73,7 +76,7 @@ config.load = () => {
|
|||||||
for(let prop in obj)
|
for(let prop in obj)
|
||||||
{
|
{
|
||||||
config[prop] = obj[prop]
|
config[prop] = obj[prop]
|
||||||
debug('config.json:', prop, '=', obj[prop])
|
debug('rats.json:', prop, '=', obj[prop])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return configProxy
|
return configProxy
|
||||||
|
Reference in New Issue
Block a user