Skip to content

Commit da584d5

Browse files
committed
fix: make upstream urls unique
1 parent a0c8531 commit da584d5

5 files changed

Lines changed: 39 additions & 10 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@omss/framework",
3-
"version": "1.1.17",
3+
"version": "1.1.18",
44
"description": "Official OMSS backend framework - Multi-provider streaming media aggregation framework with auto-discovery",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/services/proxy.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class ProxyService {
5252
* Returns either buffered response or streaming response based on file type
5353
*/
5454
async proxyRequest(encodedData: string): Promise<ProxyResult> {
55-
const proxyData = this.decodeProxyData(encodedData)
55+
const proxyData = ProxyService.decodeProxyData(encodedData)
5656

5757
this.isProd ?? console.log(`[ProxyService] Proxying request to: ${proxyData.url}`)
5858

@@ -202,7 +202,7 @@ export class ProxyService {
202202
/**
203203
* Decode proxy data parameter
204204
*/
205-
private decodeProxyData(encodedData: string): ProxyData {
205+
public static decodeProxyData(encodedData: string): ProxyData {
206206
try {
207207
const decoded = decodeURIComponent(encodedData)
208208
const data = JSON.parse(decoded) as ProxyData

src/services/source.service.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { OMSSErrors } from '../core/errors.js'
66
import { TMDBService } from '../services/tmdb.service.js'
77
import { v4 as uuidv4 } from 'uuid'
88
import { StremioService } from './stremio.service.js'
9+
import { ProxyService } from './proxy.service.js'
910

1011
export class SourceService {
1112
private tmdbValidator: ReturnType<typeof createTMDBValidator>
@@ -277,15 +278,43 @@ export class SourceService {
277278
// Deduplicate sources by URL
278279
results.forEach((r) => {
279280
r.sources.forEach((source) => {
280-
if (!allSourcesMap.has(source.url)) {
281-
allSourcesMap.set(source.url, source)
281+
try {
282+
const urlObj = new URL(source.url)
283+
const data = urlObj.searchParams.get('data')
284+
if (!data) throw new Error('Missing data parameter in source URL')
285+
286+
const proxyData = ProxyService.decodeProxyData(data)
287+
288+
// Use upstream URL as dedup key, but store the original source (with proxy URL)
289+
if (!allSourcesMap.has(proxyData.url)) {
290+
allSourcesMap.set(proxyData.url, source)
291+
}
292+
} catch (error) {
293+
console.warn(`[SourceService] Failed to decode source URL: ${source.url}`, error)
294+
// Fallback: dedup by proxy URL itself
295+
if (!allSourcesMap.has(source.url)) {
296+
allSourcesMap.set(source.url, source)
297+
}
282298
}
283299
})
284300

285301
// Deduplicate subtitles by URL
286302
r.subtitles.forEach((subtitle) => {
287-
if (!allSubtitlesMap.has(subtitle.url)) {
288-
allSubtitlesMap.set(subtitle.url, subtitle)
303+
try {
304+
const urlObj = new URL(subtitle.url)
305+
const data = urlObj.searchParams.get('data')
306+
if (!data) throw new Error('Missing data parameter in subtitle URL')
307+
308+
const proxyData = ProxyService.decodeProxyData(data)
309+
310+
if (!allSubtitlesMap.has(proxyData.url)) {
311+
allSubtitlesMap.set(proxyData.url, subtitle)
312+
}
313+
} catch (error) {
314+
console.warn(`[SourceService] Failed to decode subtitle URL: ${subtitle.url}`, error)
315+
if (!allSubtitlesMap.has(subtitle.url)) {
316+
allSubtitlesMap.set(subtitle.url, subtitle)
317+
}
289318
}
290319
})
291320

src/services/stremio.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class StremioService {
8484

8585
const promises = enabled.map((a) =>
8686
this.fetchAddonStreams(a, type, id).catch((err) => {
87-
console.error(`[StremioService] Addon '${a.id}' failed:`, err)
87+
console.log(`[StremioService] Addon '${a.id}' failed:`, err)
8888
return {
8989
addonId: a.id,
9090
streams: [],

0 commit comments

Comments
 (0)