Skip to content

Commit beef0b4

Browse files
authored
Merge pull request #16 from pct-org/improvements
Improvements
2 parents 23cbcd4 + 347aaca commit beef0b4

File tree

3 files changed

+1005
-709
lines changed

3 files changed

+1005
-709
lines changed

apps/api/src/watch/watch.controller.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { Controller, Get, Res, Req, Param, Logger, Inject } from '@nestjs/common
55
import { ConfigService } from '../shared/config/config.service'
66
import { TorrentService } from '../shared/torrent/torrent.service'
77

8+
export type Files = [{ stats: fs.Stats, fileName: string }]
9+
810
@Controller()
911
export class WatchController {
1012

@@ -24,14 +26,17 @@ export class WatchController {
2426
const filesInDirectory = fs.readdirSync(dir, { withFileTypes: true })
2527

2628
const files = filesInDirectory.map((file) => {
27-
const res = path.resolve(dir, file.name)
29+
const fileName = path.resolve(dir, file.name)
2830

2931
return file.isDirectory()
30-
? this.getFiles(res)
31-
: res
32+
? this.getFiles(fileName)
33+
: {
34+
stats: fs.statSync(fileName),
35+
fileName
36+
}
3237
})
3338

34-
return Array.prototype.concat(...files)
39+
return Array.prototype.concat(...files) as Files
3540
}
3641

3742
@Get('watch/:_id')
@@ -57,13 +62,13 @@ export class WatchController {
5762
}
5863

5964
// Get the correct media file
60-
const mediaFile = files.reduce((previous, current, index) => {
61-
const formatIsSupported = !!this.torrentService.supportedFormats.find(format => (
62-
current.includes(format) && !current.includes('transcoding')
65+
const mediaFile = files.reduce((previous, current) => {
66+
const formatIsSupported = !!this.torrentService.supportedFormats.find((format) => (
67+
current.fileName.includes(format)
6368
))
6469

6570
if (formatIsSupported) {
66-
if (!previous || current.length > previous.length) {
71+
if (!previous || current.stats.size > previous.stats.size) {
6772
return current
6873
}
6974
}
@@ -84,7 +89,7 @@ export class WatchController {
8489
const isChromeCast = req?.query?.device === 'chromecast' ?? false
8590

8691
// Get the size of the media file
87-
let { size: mediaSize } = fs.statSync(mediaFile)
92+
let mediaSize = mediaFile.stats.size
8893

8994
// If it its Chromecast and we have a torrent then use the file size from that
9095
if (isChromeCast && torrent) {
@@ -135,7 +140,7 @@ export class WatchController {
135140
torrent.file.createReadStream(streamOptions)
136141
}
137142

138-
res.send(fs.createReadStream(mediaFile, streamOptions))
143+
res.send(fs.createReadStream(mediaFile.fileName, streamOptions))
139144
}
140145

141146
}

package.json

+11-16
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
"update": "nx migrate latest",
4343
"workspace-schematic": "nx workspace-schematic"
4444
},
45-
"resolutions": {
46-
"webtorrent": "0.111.0",
47-
"webtorrent-cli": "3.0.7",
48-
"wrtc": "0.4.5"
49-
},
5045
"dependencies": {
5146
"@hapi/joi": "17.1.1",
5247
"@nestjs/cli": "7.5.4",
@@ -63,23 +58,23 @@
6358
"class-transformer": "^0.3.1",
6459
"class-validator": "0.12.2",
6560
"cron-parser": "^2.18.0",
66-
"debug": "^4.3.1",
61+
"debug": "^4.3.2",
6762
"diskusage": "^1.1.3",
6863
"dotenv": "8.2.0",
6964
"fanart.tv-api": "^2.0.1",
7065
"fastify-static": "2.7.0",
7166
"get-folder-size": "^2.0.1",
72-
"got": "^11.8.1",
73-
"graphql": "15.4.0",
74-
"graphql-subscriptions": "^1.1.0",
67+
"got": "^11.8.2",
68+
"graphql": "15.5.1",
69+
"graphql-subscriptions": "^1.2.1",
7570
"ical-generator": "^1.15.3",
7671
"mongoose": "5.10.15",
7772
"node-tvdb": "^4.1.0",
7873
"omdb-api-pt": "^2.0.1",
7974
"opensubtitles-api": "^5.1.2",
8075
"p-map": "^4.0.0",
8176
"p-times": "^3.0.0",
82-
"pm2": "^4.5.1",
77+
"pm2": "^5.1.1",
8378
"reflect-metadata": "^0.1.12",
8479
"rimraf": "3.0.2",
8580
"rxjs": "6.6.3",
@@ -88,7 +83,7 @@
8883
"tmdb": "^2.6.0",
8984
"trakt.tv": "^8.0.0",
9085
"url": "^0.11.0",
91-
"webtorrent-hybrid": "^4.0.3",
86+
"webtorrent-hybrid": "^4.1.3",
9287
"xtorrent": "^1.0.0",
9388
"yts-api-pt": "^2.0.0"
9489
},
@@ -104,17 +99,17 @@
10499
"@types/jest": "26.0.19",
105100
"@types/mongoose": "^5.10.3",
106101
"@types/node": "~14.14.14",
107-
"@types/webtorrent": "^0.109.0",
108-
"@typescript-eslint/eslint-plugin": "4.11.0",
109-
"@typescript-eslint/parser": "4.11.0",
102+
"@types/webtorrent": "^0.109.1",
103+
"@typescript-eslint/eslint-plugin": "4.29.3",
104+
"@typescript-eslint/parser": "4.29.3",
110105
"dotenv": "6.2.0",
111-
"eslint": "7.16.0",
106+
"eslint": "7.32.0",
112107
"eslint-config-prettier": "7.1.0",
113108
"jest": "26.6.3",
114109
"prettier": "2.2.1",
115110
"ts-jest": "26.4.4",
116111
"ts-node": "~9.1.1",
117112
"tslint": "~6.1.3",
118-
"typescript": "~4.1.3"
113+
"typescript": "~4.3.5"
119114
}
120115
}

0 commit comments

Comments
 (0)