Skip to content

Commit

Permalink
fix: Fix title search logic
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Owater425 committed Jan 8, 2024
1 parent 5f5233e commit b6ea0c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
17 changes: 14 additions & 3 deletions source/gallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ERROR_CODE, IS_NEGATIVE, RAW_GALLERY_KEYS } from './constant';
import { IdSet, JsonObject, Node, PopularityPeriod, Tag } from './type';
import { Gallery } from './type';
import { getNozomiUri } from './uri';
import { HitomiError, binarySearch, fetch, filterIdSet, getIdSet, getNodeAtAddress } from './utility';
import { HitomiError, binarySearch, fetch, getIdSet, getNodeAtAddress } from './utility';

export function getGallery(id: number): Promise<Gallery> {
return fetch('ltn.hitomi.la/galleries/' + id + '.js')
Expand Down Expand Up @@ -102,7 +102,6 @@ export function getGalleryIds(options: {
if(isOptionsTitleAvailable) {
options['title'] += ' ';

const idSetPromises: Promise<IdSet>[] = [];
let currentIndex: number = 0;
// @ts-expect-error | Already checked
let nextIndex: number = options['title'].indexOf(' ');
Expand Down Expand Up @@ -154,7 +153,19 @@ export function getGalleryIds(options: {
}
}

return idSetPromises.reduce(filterIdSet, fetch(getNozomiUri()).then(getIdSet))
return idSetPromises.reduce(function (previousIdSetPromise: Promise<IdSet>, idSetPromise: Promise<IdSet>): Promise<IdSet> {
return previousIdSetPromise.then(function (previousIdSet: IdSet): Promise<IdSet> {
return idSetPromise.then(function (idSet: IdSet): IdSet {
for(const id of previousIdSet) {
if(idSet[IS_NEGATIVE] === idSet.has(id)/* ~(idSet[IS_NEGATIVE] ^ idSet.has(id)) */) {
previousIdSet.delete(id);
}
}

return previousIdSet;
});
});
}, fetch(getNozomiUri()).then(getIdSet))
.then(function (idSet: IdSet): number[] {
const ids: number[] = Array.from(idSet);

Expand Down
14 changes: 0 additions & 14 deletions source/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,4 @@ export function binarySearch(key: Buffer, node: Node, version: string): Promise<
} else {
return Promise.resolve() as Promise<undefined>;
}
}

export function filterIdSet(previousIdSetPromise: Promise<IdSet>, idSetPromise: Promise<IdSet>): Promise<IdSet> {
return previousIdSetPromise.then(function (previousIdSet: IdSet): Promise<IdSet> {
return idSetPromise.then(function (idSet: IdSet): IdSet {
for(const id of previousIdSet) {
if(idSet[IS_NEGATIVE] === idSet.has(id)/* ~(idSet[IS_NEGATIVE] ^ idSet.has(id)) */) {
previousIdSet.delete(id);
}
}

return previousIdSet;
});
});
}

0 comments on commit b6ea0c6

Please sign in to comment.