Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make tag page number more accurate #70

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class App extends Component {
}

onFilterClick(event){
this.filterText = getSearchInputText();;
this.filterText = getSearchInputText();
this.forceUpdate();
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/ChartPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export default class ChartPage extends Component {
}else if(timeType === BY_MONTH){
tLabel = `${t.getFullYear()}-${t.getMonth()+1}`;
}else{
tLabel = t.getFullYear();;
tLabel = t.getFullYear();
}

if(valueType === VALUE_COUNT){
Expand Down
31 changes: 27 additions & 4 deletions src/client/TagPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ export default class TagPage extends Component {

this.bindUserInteraction();

Sender.post('/api/allInfo', { needThumbnail: true}, res => {
// Sender.post('/api/allInfo', { needThumbnail: true}, res => {
// if (!res.failed) {
// this.setItems(res);
// this.setState({ loaded: true });
// } else {
// this.res = res;
// this.forceUpdate();
// }
// });

Sender.post('/api/getAllAuthors', { needThumbnail: true}, res => {
if (!res.failed) {
this.setItems(res);
this.setState({ loaded: true });
Expand Down Expand Up @@ -120,16 +130,29 @@ export default class TagPage extends Component {
this.allThumbnails = allThumbnails;

const beginTime = getCurrentTime();
const groupSet = {};

for(let filePath in fileToInfo){
if(fileToInfo.hasOwnProperty(filePath) && isCompress(filePath)){
const fileName = getBaseName(filePath);
const result = nameParser.parse(fileName);
if (result && result.group) {
groupSet[result.group] = true;
}
}
}

for(let filePath in fileToInfo){
if(fileToInfo.hasOwnProperty(filePath) && isCompress(filePath)){
const fileName = getBaseName(filePath);
const result = nameParser.parse(fileName);
if (result) {

(result.authors||[]).forEach(author => {
addOne(authors, author);
addToArray(authorToFiles, author, filePath );
//some author is actually group, fake author
if(!groupSet[author]){
addOne(authors, author);
addToArray(authorToFiles, author, filePath );
}
})

result.tags.forEach(tag => {
Expand Down
4 changes: 2 additions & 2 deletions src/client/style/OneBook.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
overflow: scroll;

@media screen and (min-height: 600px) {
min-height: 600px;;
min-height: 600px;
}

.mobile-single-image{
Expand All @@ -109,7 +109,7 @@
max-height: 900px;

@media screen and (max-height: 800px) {
max-height: 600px;;
max-height: 600px;
}

&.has-music {
Expand Down
2 changes: 1 addition & 1 deletion src/client/subcomponent/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ class Dropdown extends Component {
}


export default enhanceWithClickOutside(Dropdown);;
export default enhanceWithClickOutside(Dropdown);
13 changes: 9 additions & 4 deletions src/name-parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function isStrDate(str) {

let invalid = y > 30 && y < 80;
invalid = invalid || (m < 0 || m > 12);
invalid = invalid || (d < 0 || d > 30);
invalid = invalid || (d < 0 || d > 31);
return !invalid;
}

Expand All @@ -199,7 +199,7 @@ function isFullStrDate(str){
}

function getAuthorName(str){
var macthes = str.match(/(.*?)\s*\((.*?)\)/);
var macthes = str.match(/^(.*?)\s*\((.*?)\)$/);
if(macthes && macthes.length > 0){
return {
group: macthes[1].trim(),
Expand Down Expand Up @@ -270,6 +270,8 @@ function getTag(str, pMacthes, author){
return tags;
}

const DLsiteReg = /RJ\d+/;

function parse(str) {
if (!str || localCache[str] === "NO_EXIST") {
return null;
Expand Down Expand Up @@ -303,7 +305,10 @@ function parse(str) {
const nextCharIndex = str.indexOf(bMacthes[ii]) + bMacthes[ii].length + 1;
const nextChar = str[nextCharIndex];

if (isStrDate(token)) {
if(token.match(DLsiteReg)){
//DLsite tag is not author
continue;
}else if (isStrDate(token)) {
//e.g 190214
dateTag = token;
} else if (not_author_but_tag_table[tt]){
Expand Down Expand Up @@ -343,7 +348,7 @@ function parse(str) {
title = title.trim();


const authors = author && author.split(/,|、/).map(e => e.trim()) ;
const authors = author && author.split(/,|、|&/).map(e => e.trim()) ;

const result = {
dateTag, author, tags, comiket, type, group, title, authors
Expand Down
78 changes: 76 additions & 2 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ async function init() {

setUpFileWatch(path_will_scan);

console.log("-------init author db---------------");
initAuthorDb();

const port = isProduction? http_port: dev_express_port;
const server = app.listen(port, async () => {
const lanIP = await internalIp.v4();
Expand Down Expand Up @@ -323,6 +326,75 @@ async function getStat(filePath){
return stat;
}

function initAuthorDb(){
const pathes = getAllFilePathes().filter(isCompress);
const groupSet = {};
pathes.forEach(filePath => {
const result = serverUtil.parse(filePath);
if (result && result.group) {
groupSet[result.group] = true;
}
})

const authorSets = {};
pathes.forEach(filePath => {
const result = serverUtil.parse(filePath);
if (result) {
(result.authors||[]).forEach(author => {
//some author is actually group, fake author
if(!groupSet[author]){
authorSets[author] = true;
}
})
}
})

const authors = _.keys(authorSets);
const authorTable = {};

const time1 = getCurrentTime();

authors.forEach((author, index) => {
if(index % 500 === 0){
console.log("[initAuthorDb]:", index);
}
authorTable[author] = searchByTagAndAuthor("", author, "", {onlyFileInfo: true}).fileInfos;
})

const time2 = getCurrentTime();
let timeUsed = (time2 - time1);
console.log(`[initAuthorDb] author ${timeUsed}ms`);


//------------init tag ----------------
const tagSets = {};
pathes.forEach(filePath => {
const result = serverUtil.parse(filePath);
if (result) {
result.tags.forEach(tag => {
tagSets[tag] = true;
});
}
});

const tags = _.keys(tagSets);
const tagTable = {}
tags.forEach((tag, index) => {
if(index % 500 === 0){
console.log("[initAuthorDb]:", index);
}
tagTable[tag] = searchByTagAndAuthor(tag, "", "", {onlyFileInfo: true}).fileInfos;
})

const time3 = getCurrentTime();
timeUsed = (time3 - time2);
console.log(`[initAuthorDb] tag ${timeUsed}ms`);

global.authorTable = authorTable;
global.tagTable = tagTable;

}


serverUtil.common.getCacheOutputPath = getCacheOutputPath;
serverUtil.common.getThumbnails = getThumbnails;
Expand All @@ -338,8 +410,7 @@ app.post("/api/tagFirstImagePath", (req, res) => {
return;
}

const onlyNeedFew = true;
const { fileInfos } = searchByTagAndAuthor(tag, author, null, onlyNeedFew);
const { fileInfos } = searchByTagAndAuthor(tag, author, null, {onlyNeedFew : true});
const files = _.keys(fileInfos);
chosendFileName = serverUtil.chooseOneZipForOneTag(files, db.getFileToInfo());
if(!chosendFileName){
Expand Down Expand Up @@ -645,6 +716,9 @@ app.use(search);
const AllInfo = require("./routes/AllInfo");
app.use(AllInfo);

const getAllAuhorsAndTag = require("./routes/getAllAuhorsAndTag");
app.use(getAllAuhorsAndTag);

const singleFileInfo = require("./routes/singleFileInfo");
app.use(singleFileInfo);

Expand Down
18 changes: 13 additions & 5 deletions src/server/models/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const {escapeRegExp} = util;
const path = require('path');
const _ = require('underscore');

function searchByTagAndAuthor(tag, author, text, onlyNeedFew) {
function searchByTagAndAuthor(tag, author, text, config) {
config = config || {};
let beg = (new Date).getTime()
const fileInfos = {};

Expand Down Expand Up @@ -38,7 +39,8 @@ function searchByTagAndAuthor(tag, author, text, onlyNeedFew) {
});

if(groups.length > 0){
groups = _.sortBy(groups, e => e.length);
const byFeq = _.countBy(groups, e => e);
groups = _.sortBy(_.keys(byFeq), e => -byFeq[e]);
const reg2 = escapeRegExp(groups[0]);
extraResults = getFileCollection().find({'authors': { '$regex' : reg2 },
'group': {'$len': 0 },
Expand All @@ -52,11 +54,12 @@ function searchByTagAndAuthor(tag, author, text, onlyNeedFew) {
.find({'tags': { '$regex' : reg }, isDisplayableInExplorer: true });
}

if(onlyNeedFew){
if(config.onlyNeedFew){
results = results.limit(5);
}

const finalResult = results.data().concat(extraResults);
let finalResult = (results && results.data())||[];
finalResult = finalResult.concat(extraResults);

finalResult.forEach(obj => {
const pp = obj.filePath;
Expand All @@ -68,7 +71,12 @@ function searchByTagAndAuthor(tag, author, text, onlyNeedFew) {

const getThumbnails = serverUtil.common.getThumbnails;
const files = _.keys(fileInfos);
return { tag, author, fileInfos, thumbnails: getThumbnails(files), zipInfo: getZipInfo(files) };

if(config.onlyFileInfo){
return { tag, author, fileInfos }
}else{
return { tag, author, fileInfos, thumbnails: getThumbnails(files), zipInfo: getZipInfo(files) };
}
}

module.exports = searchByTagAndAuthor;
2 changes: 1 addition & 1 deletion src/server/routes/AllInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const express = require('express');
const router = express.Router();
const serverUtil = require("../serverUtil");
const db = require("../models/db");
const { getAllFilePathes } = db;;
const { getAllFilePathes } = db;
const getThumbnails = serverUtil.common.getThumbnails;

router.post('/api/allInfo', (req, res) => {
Expand Down
23 changes: 23 additions & 0 deletions src/server/routes/getAllAuhorsAndTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const express = require('express');
const router = express.Router();
const util = global.requireUtil();

const db = require("../models/db");
const { getAllFilePathes } = db;
const serverUtil = require("../serverUtil");
const getThumbnails = serverUtil.common.getThumbnails;


// three para 1.mode 2.text
router.post("/api/getAllAuhorsAndTag", (req, res) => {

allThumbnails = getThumbnails(getAllFilePathes());

res.send({
authorTable: global.authorTable,
tagTable: global.tagTable,
allThumbnails
});
});

module.exports = router;
2 changes: 1 addition & 1 deletion src/server/routes/getGoodAuthorNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const express = require('express');
const router = express.Router();
const db = require("../models/db");
const { loopEachFileInfo } = db;;
const { loopEachFileInfo } = db;
const util = global.requireUtil();
const { isCompress } = util;
const userConfig = global.requireUserConfig();
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/hentaiApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const express = require('express');
const router = express.Router();
const db = require("../models/db");
const { getAllFilePathes } = db;;
const { getAllFilePathes } = db;
const util = global.requireUtil();
const { isCompress } = util;
const path = require('path');
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/homePagePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const express = require('express');
const router = express.Router();
const serverUtil = require("../serverUtil");
const db = require("../models/db");
const { getFileCollection } = db;;
const { getFileCollection } = db;
const util = global.requireUtil();
const {escapeRegExp} = util;

Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/lsdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const express = require('express');
const router = express.Router();
const serverUtil = require("../serverUtil");
const db = require("../models/db");
const { loopEachFileInfo, getFileCollection, getFileToInfo } = db;;
const { loopEachFileInfo, getFileCollection, getFileToInfo } = db;
const util = global.requireUtil();
const { getCurrentTime, isDisplayableInExplorer, escapeRegExp } = util;
const path = require('path');
Expand Down