Skip to content

Commit

Permalink
1.0.9 (#9)
Browse files Browse the repository at this point in the history
* better media type ident logic

* 1.0.9

* replace some special chars with spaces

* files > downloads

* rework regex

* add forward slash

* set replica numbers

* add slow search api
  • Loading branch information
yowmamasita authored Apr 15, 2023
1 parent 7e7576d commit 5a8bc39
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 28 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NODE_ENV=production
GH_PAT=github-access-token
REDIS_URL=redis://redis:6379
REDIS_SLAVE_URL=redis://redis-slave:6379
PROXY=socks5h://tor:9050
18 changes: 14 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
version: '3.9'
services:
debugger:
image: ubuntu
volumes:
- redis_data:/userdata
entrypoint: ['tail', '-f', '/dev/null']
deploy:
replicas: 1

tor:
image: dockage/tor-privoxy:latest
deploy:
replicas: 48
replicas: 64

web:
image: debridmediamanager/debrid-media-manager:latest
ports:
- 3000:3000
- 127.0.0.1:3000:3000
env_file:
- .env
- .env.local
Expand All @@ -24,6 +32,8 @@ services:
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- redis_data:/bitnami/redis/data
ports:
- 127.0.0.1:6379:6379
deploy:
replicas: 1

Expand All @@ -38,7 +48,7 @@ services:
volumes:
- redis_data:/bitnami/redis/data
deploy:
replicas: 3
replicas: 5

redis-sentinel:
image: 'bitnami/redis-sentinel:latest'
Expand All @@ -49,7 +59,7 @@ services:
- redis
- redis-slave
ports:
- '26379-26381:26379'
- '127.0.0.1:26379-26381:26379'
volumes:
- ./redis-sentinel.conf:/usr/local/etc/redis-sentinel.conf
deploy:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "debrid-media-manager",
"version": "1.0.8",
"version": "1.0.9",
"private": false,
"scripts": {
"dev": "next dev",
Expand Down
34 changes: 18 additions & 16 deletions src/pages/api/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const stopWords = [
const agent = new SocksProxyAgent(process.env.PROXY!, { timeout: 3000 });
const dhtSearchHostname = 'http://btdigggink2pdqzqrik3blmqemsbntpzwxottujilcdjfz56jumzfsyd.onion';

const cache = new RedisCache();
const cache = new RedisCache(process.env.REDIS_SLAVE_URL!);

export default async function handler(req: NextApiRequest, res: NextApiResponse<BtDiggApiResult>) {
const { search, libraryType } = req.query;
Expand All @@ -72,12 +72,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
}

const finalQuery = search
.split(/[\s\.\-\(\)]/)
.filter((e) => e !== '')
.map((e) => e.toLowerCase())
.filter((term) => !stopWords.includes(term))
.join(' ')
.replace(/[áàäâ]/g, 'a')
.split(/[\s\=:\?\.\-\(\)\/]/) // split the search query into an array of elements
.filter((e) => e !== '') // filter out any empty elements
.map((e) => e.toLowerCase()) // convert each element to lowercase
.filter((term) => !stopWords.includes(term)) // remove any stop words from an array
.join(' ') // join the remaining elements with a single space
.replace(/[áàäâ]/g, 'a') // replace certain characters with their equivalent
.replace(/[éèëê]/g, 'e')
.replace(/[íìïî]/g, 'i')
.replace(/[óòöô]/g, 'o')
Expand All @@ -86,9 +86,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
.replace(/[ñ]/g, 'n')
.replace(/[ş]/g, 's')
.replace(/[ğ]/g, 'g')
.replace(/[^\w\s]/g, '')
.replace(/\s+/g, ' ')
.trim();
.replace(/[^\w\s]/g, '') // remove any non-word or non-space characters
.replace(/\s+/g, ' ') // replace multiple spaces with a single space
.trim(); // trim any leading or trailing spaces

const libraryTypes = libraryType === '1080pOr2160p' ? ['1080p', '2160p', ''] : [libraryType];

Expand Down Expand Up @@ -139,9 +139,14 @@ async function fetchSearchResults(
const finalQuery = `${searchQuery}${
!libraryType || libraryType === '1080pOr2160p' ? '' : ` ${libraryType}`
}`;
const cached = await cache.getCachedJsonValue<SearchResult[]>(finalQuery.split(' '));
if (cached) {
return cached;

try {
const cached = await cache.getCachedJsonValue<SearchResult[]>(finalQuery.split(' '));
if (cached) {
return cached;
}
} catch (e: any) {
console.warn(e);
}

let pageNum = 1;
Expand Down Expand Up @@ -279,9 +284,6 @@ async function fetchSearchResults(

console.log(`Found ${searchResultsArr.length} results (${finalQuery})`);

// run async
cache.cacheJsonValue<SearchResult[]>(finalQuery.split(' '), searchResultsArr);

return searchResultsArr;
} catch (error) {
console.error('fetchSearchResults page processing error', error);
Expand Down
Loading

0 comments on commit 5a8bc39

Please sign in to comment.