diff --git a/package-lock.json b/package-lock.json
index 0275b3a..eac3494 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "rats-search",
- "version": "0.30.0",
+ "version": "0.30.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -8541,12 +8541,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -8561,17 +8563,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"core-util-is": {
"version": "1.0.2",
@@ -8688,7 +8693,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"ini": {
"version": "1.3.5",
@@ -8700,6 +8706,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -8714,6 +8721,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@@ -8721,12 +8729,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@@ -8745,6 +8755,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"minimist": "0.0.8"
}
@@ -8825,7 +8836,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"object-assign": {
"version": "4.1.1",
@@ -8837,6 +8849,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"wrappy": "1"
}
@@ -8958,6 +8971,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
diff --git a/src/app/torrent.js b/src/app/torrent.js
index ac2bdf5..1878b97 100644
--- a/src/app/torrent.js
+++ b/src/app/torrent.js
@@ -320,7 +320,17 @@ export default class Torrent extends Component {
torrent.path && torrent.path.length > 0
?
torrent.path.map((path, index) => {
- return
{path}
+ const boldRe = /\(.+?)\<\/b\>/g;
+ let boldText;
+ let newPath = [];
+ let idx = 0;
+ while ((boldText = boldRe.exec(path)) !== null) {
+ newPath.push({path.substring(idx, boldText.index)});
+ newPath.push({boldText[1]});
+ idx = boldRe.lastIndex;
+ }
+ newPath.push({path.substring(idx, path.length)});
+ return {newPath}
})
:
null
diff --git a/src/background/api.js b/src/background/api.js
index a0375bc..8d6217b 100644
--- a/src/background/api.js
+++ b/src/background/api.js
@@ -1,11 +1,12 @@
const ipaddr = require('ipaddr.js');
const forBigTable = require('./forBigTable')
const compareVersions = require('compare-versions');
-const getTorrent = require('./gettorrent')
+const getTorrent = require('./getTorrent')
const _ = require('lodash')
const asyncForEach = require('./asyncForEach')
const cpuUsage = require('./bt/cpu-usage-global')
const magnetParse = require('./magnetParse')
+const parseTorrentFiles = require('./parsetTorrentFiles')
module.exports = async ({
sphinx,
@@ -125,14 +126,14 @@ module.exports = async ({
let result = {torrents: rows[0].torrents || 0, size: rows[0].sz || 0}
- sphinx.query('SELECT count(*) AS files FROM `files`', function (error, rows, fields) {
+ sphinx.query('SELECT sum(files) AS flist FROM `torrents`', function (error, rows, fields) {
if(!rows) {
logTE('statistic', error)
callback(undefined)
return;
}
- result.files = rows[0].files || 0
+ result.files = (rows[0] && rows[0].flist) || 0
callback(result)
})
@@ -183,7 +184,7 @@ module.exports = async ({
if(options.files)
{
- torrent.filesList = await sphinx.query('SELECT * FROM `files` WHERE `hash` = ? LIMIT 50000', hash);
+ torrent.filesList = parseTorrentFiles(await sphinx.query('SELECT * FROM `files` WHERE `hash` = ?', hash));
callback(baseRowData(torrent))
}
else
@@ -239,17 +240,10 @@ module.exports = async ({
}
const inSql = Object.keys(hashes).map(hash => sphinx.escape(hash)).join(',');
- sphinxSingle.query(`SELECT * FROM files WHERE hash IN(${inSql}) limit 50000`, (error, files) => {
- if(!files)
- {
- files = []
- }
-
- files.forEach((file) => {
- if(!hashes[file.hash].filesList)
- hashes[file.hash].filesList = []
- hashes[file.hash].filesList.push(file)
- })
+ sphinxSingle.query(`SELECT * FROM files WHERE hash IN(${inSql})`, (error, files) => {
+ for(const file of files)
+ hashes[file.hash].filesList = parseTorrentFiles(file);
+
callback(Object.values(hashes))
})
})
@@ -403,70 +397,39 @@ module.exports = async ({
const index = navigation.index || 0;
const limit = navigation.limit || 10;
- let args = [text, index, limit];
+ let args = [text, text, index, limit];
const orderBy = navigation.orderBy;
let order = '';
let where = '';
- /*
- if(orderBy && orderBy.length > 0)
- {
- const orderDesc = navigation.orderDesc ? 'DESC' : 'ASC';
- args.splice(1, 0, orderBy);
- order = 'ORDER BY ?? ' + orderDesc;
- }
- */
- /*
- if(safeSearch)
- {
- where += " and contentCategory != 'xxx' ";
- }
- if(navigation.type && navigation.type.length > 0)
- {
- where += ' and contentType = ' + sphinx.escape(navigation.type) + ' ';
- }
- if(navigation.size)
- {
- if(navigation.size.max > 0)
- where += ' and torrentSize < ' + sphinx.escape(navigation.size.max) + ' ';
- if(navigation.size.min > 0)
- where += ' and torrentSize > ' + sphinx.escape(navigation.size.min) + ' ';
- }
- if(navigation.files)
- {
- if(navigation.files.max > 0)
- where += ' and files < ' + sphinx.escape(navigation.files.max) + ' ';
- if(navigation.files.min > 0)
- where += ' and files > ' + sphinx.escape(navigation.files.min) + ' ';
- }
- */
-
let search = {};
- //args.splice(orderBy && orderBy.length > 0 ? 1 : 0, 1);
- //sphinx.query('SELECT * FROM `files` inner join torrents on(torrents.hash = files.hash) WHERE files.path like \'%' + text + '%\' ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, rows, fields) {
- sphinx.query('SELECT * FROM `files` WHERE MATCH(?) ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, files, fields) {
- if(!files) {
- logT('search', error)
+ sphinx.query('SELECT *, SNIPPET(path, ?, \'around=100\', \'force_all_words=1\') as snipplet FROM `files` WHERE MATCH(?) ' + where + ' ' + order + ' LIMIT ?,?', args, function (error, searchTorrents) {
+ if(!searchTorrents) {
+ logTE('search', error)
callback(undefined)
return;
}
- if(files.length === 0)
+ if(searchTorrents.length === 0)
{
+ logT('search', 'not torrents founded for files search');
callback(undefined)
return;
}
- for(const file of files)
+ for(const torrent of searchTorrents)
{
- if(!search[file.hash])
+ if(!search[torrent.hash])
{
- search[file.hash] = { path: [] }
+ search[torrent.hash] = { path: [] }
+ }
+ for(const file of torrent.snipplet.split('\n').filter(text => text.includes('')).slice(0, 25))
+ {
+ search[torrent.hash].path.push(file)
}
- search[file.hash].path.push(file.path)
}
const inSql = Object.keys(search).map(hash => sphinx.escape(hash)).join(',');
sphinx.query(`SELECT * FROM torrents WHERE hash IN(${inSql})`, (err, torrents) => {
if(!torrents) {
- logT('search', err)
+ logTE('search', err)
return;
}
diff --git a/src/background/background.js b/src/background/background.js
index eaddc5f..7e9fc1c 100644
--- a/src/background/background.js
+++ b/src/background/background.js
@@ -179,6 +179,10 @@ app.on("ready", async () => {
height: 600
});
+ // Need for db patcher, to close application
+ if(stop)
+ mainWindow.appClose = stop;
+
dbPatcher(() => {
changeLanguage(appConfig.language, () => setApplicationMenu())
diff --git a/src/background/dbPatcher.js b/src/background/dbPatcher.js
index d642127..f2ab549 100644
--- a/src/background/dbPatcher.js
+++ b/src/background/dbPatcher.js
@@ -8,11 +8,10 @@ const glob = require("glob")
const asyncForEach = require('./asyncForEach')
const {torrentTypeDetect} = require('../app/content');
-const getTorrent = require('./gettorrent')
const startSphinx = require('./sphinx')
-const currentVersion = 6
+const currentVersion = 7
module.exports = async (callback, mainWindow, sphinxApp) => {
@@ -26,7 +25,7 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
}
let patchWindow;
- const openPatchWindow = () => {
+ const openPatchWindow = (closable = false) => {
if(patchWindow)
return
@@ -36,10 +35,12 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
if(mainWindow)
mainWindow.hide()
- patchWindow = new BrowserWindow({width: 800, height: 400, closable: false})
+ patchWindow = new BrowserWindow({width: 800, height: 400, closable})
patchWindow.setMenu(null)
+ patchWindow.on('close', () => mainWindow.appClose())
+
patchWindow.loadURL("data:text/html;charset=utf-8," + encodeURI(`
Database patching...
@@ -73,12 +74,24 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
}
#one {
padding: 20px;
+ }
+ #long {
+ font-size: 0.8em;
+ padding: 10px;
+ }
+ #canBreak {
+ font-size: 0.8em;
+ padding: 10px;
}