Skip to content

Commit

Permalink
Merge pull request #4 from nortonandrews/scanner-bugfixing
Browse files Browse the repository at this point in the history
Bugfixing, media notifications, recursive scanning and password protection
  • Loading branch information
nortonandrews authored Sep 6, 2019
2 parents 0717a1f + bf2062b commit 343b07f
Show file tree
Hide file tree
Showing 16 changed files with 295 additions and 78 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"rules": {
"import/no-extraneous-dependencies": [ 2, {"devDependencies": true}],
"no-restricted-syntax": [0, "iterators/generators"],
"react/react-in-jsx-scope": 0,
"react/prop-types": 0
}
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ npm start
```

### Configuration
You must change `rootDir` in the `config.json` to point to the directory where you keep your voice works. Each work must be a folder containing an RJ code anywhere in its name.
#### Media scanner
You must change `rootDir` in the `config.json` file to point to the directory where you keep your voice works. Each work must be a folder containing an RJ code anywhere in its name.

**NOTE:** Even if you're on Windows, you still need to use forward slashes when specifying `rootDir`. For example:
```json
Expand All @@ -63,10 +64,10 @@ npm run scan
This will create a file named `db.sqlite3`, containing metadata scraped from HVDB for each work found by the scanner. This file can safely be deleted if you wish to rebuild the database. It will also create a folder called `Images` inside your `rootDir` containing work cover images.

Subsequent runs of the scan command will do two things:
- Look for new works add them to the database
- Look for new works and add them to the database
- Remove works which have been deleted from disk since last scan

It is important to note that the scanner is *not* recursive. That is to say, inside of the `rootDir` directory, every folder must contain a single work. If your works are inside a subdirectory for circle/VA or anything like that, the scanner will not find them. However, subdirectories *inside* a work are fine. For example, assuming `rootDir` is `/mnt/Voice/`:
It is important to note that the scanner has a configurable maximum recursion depth. However, subdirectories *inside* a work do not count towards the maximum. For example, assuming `rootDir` is `/mnt/Voice/`:
```bash
# OK - This work will be detected correctly:
/mnt/Voice/[Atelier Honey] 雨恋女の子守唄 (RJ136105)/
Expand All @@ -77,13 +78,21 @@ It is important to note that the scanner is *not* recursive. That is to say, ins
/mnt/Voice/RJ130297/wav/ノイズ有/
/mnt/Voice/RJ130297/wav/ノイズ無(推奨)/

# FAIL - This work won't be detected because it's in a subdirectory:
# OK - As long as `scannerMaxRecursionDepth` is at least 2:
/mnt/Voice/Atelier Honey/[RJ136105] 雨恋女の子守唄/

# OK - As long as `scannerMaxRecursionDepth` is at least 3:
/mnt/Voice/SFW/桃色CODE/【初夏耳かき】道草屋 芹7 ゆうがた【湯船怪談】(RJ253947)/1-帰り道mp3/
/mnt/Voice/SFW/桃色CODE/【初夏耳かき】道草屋 芹7 ゆうがた【湯船怪談】(RJ253947)/2-お風呂場のおはなしmp3/
/mnt/Voice/SFW/桃色CODE/【初夏耳かき】道草屋 芹7 ゆうがた【湯船怪談】(RJ253947)/3-夕焼け花火と耳掃除mp3/

# FAIL - This work won't be detected because there's no RJ code:
/mnt/Voice/雨恋女の子守唄/
```

#### Password protection
If you wish to password protect the web interface, you may change `password` in `config.json`. Be aware that falsy javascript values will turn this feature off (for example, setting `password` to `false` or `0`).

## Disclaimer
At the moment, although this works well enough for regular usage, you can expect to find small quirks and bugs.

Expand Down
2 changes: 2 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"rootDir": "/mnt/Media/Voice",
"password": false,
"scannerMaxRecursionDepth": 2,
"worksPerPage": 12
}
69 changes: 62 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
"dependencies": {
"cross-env": "^5.2.0",
"express": "^4.17.1",
"express-session": "^1.16.2",
"htmlparser2": "^3.10.1",
"knex": "^0.19.0",
"memorystore": "^1.6.1",
"natural-orderby": "^2.0.3",
"node-fetch": "^2.6.0",
"recursive-readdir": "^2.2.2",
Expand Down
4 changes: 2 additions & 2 deletions src/client/static/style/uikit.stripped.less
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@import "@{path}/less/components/table.less";
@import "@{path}/less/components/icon.less";
// @import "@{path}/less/components/form-range.less";
// @import "@{path}/less/components/form.less"; // After: Icon, Form Range
@import "@{path}/less/components/form.less"; // After: Icon, Form Range
@import "@{path}/less/components/button.less";

// Layout
Expand Down Expand Up @@ -116,7 +116,7 @@
@import "@{path}/less/theme/table.less";
@import "@{path}/less/theme/icon.less";
// @import "@{path}/less/theme/form-range.less";
// @import "@{path}/less/theme/form.less";
@import "@{path}/less/theme/form.less";
@import "@{path}/less/theme/button.less";

// Layout
Expand Down
33 changes: 33 additions & 0 deletions src/server/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require('path');
const express = require('express');

const config = require('../../config.json');

const router = express.Router();

router.get('/', (req, res, next) => {
res.sendFile(path.join(__dirname, '..', '..', 'static', 'auth.html'));
});

router.post('/', (req, res, next) => {
if (req.body.password === config.password) {
req.session.auth = true;
}

res.redirect('/');
});

const authenticator = (req, res, next) => {
if (req.path === '/auth/'
|| req.path === '/main.css'
|| req.path.indexOf('/static/') === 0
|| req.session.auth
|| !config.password
) {
next();
} else {
res.redirect('/auth/');
}
};

module.exports = { router, authenticator };
40 changes: 25 additions & 15 deletions src/server/database/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const getWorkMetadata = id => new Promise((resolve, reject) => {
* @param {*} tags Array of tag ids to check.
* @param {*} vas Array of VA ids to check.
*/
const cleanupOrphans = (trx, circle, tags, vas) => new Promise((resolve, reject) => {
const cleanupOrphans = (trx, circle, tags, vas) => new Promise(async (resolve, reject) => {
const getCount = (tableName, colName, colValue) => new Promise((resolveCount, rejectCount) => {
trx(tableName)
.select(colName)
Expand Down Expand Up @@ -146,25 +146,35 @@ const cleanupOrphans = (trx, circle, tags, vas) => new Promise((resolve, reject)
});
}));

tags.map(tag => promises.push(getCount('r_tag_work', 'tag_id', tag)
.then((count) => {
if (count === 0) {
for (let i = 0; i < tags.length; i += 1) {
const tag = tags[i];

// eslint-disable-next-line no-await-in-loop
const count = await getCount('r_tag_work', 'tag_id', tag);

if (count === 0) {
promises.push(
trx('t_tag')
.delete()
.where('id', '=', tag)
.then();
}
})));
.where('id', '=', tag),
);
}
}

vas.map(va => promises.push(getCount('r_va_work', 'va_id', va)
.then((count) => {
if (count === 0) {
for (let i = 0; i < vas.length; i += 1) {
const va = vas[i];

// eslint-disable-next-line no-await-in-loop
const count = await getCount('r_va_work', 'va_id', va);

if (count === 0) {
promises.push(
trx('t_va')
.delete()
.where('id', '=', va)
.then();
}
})));
.where('id', '=', va),
);
}
}

Promise.all(promises)
.then((results) => {
Expand Down
Loading

0 comments on commit 343b07f

Please sign in to comment.