diff --git a/.dockerignore b/.dockerignore index 558338d..880648e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,5 +4,6 @@ build .idea .env .DS_Store +.git backend/plugins diff --git a/backend/nest-cli.json b/backend/nest-cli.json index bc097ce..f9aa683 100644 --- a/backend/nest-cli.json +++ b/backend/nest-cli.json @@ -5,4 +5,4 @@ "compilerOptions": { "deleteOutDir": true } -} \ No newline at end of file +} diff --git a/backend/package.json b/backend/package.json index d11377a..98785ea 100644 --- a/backend/package.json +++ b/backend/package.json @@ -18,6 +18,9 @@ "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json", + "publish:patch": "npm version -w packages/reiverr-plugin --git-tag-version false patch && npm run -w packages/reiverr-plugin build && npm publish -w packages/reiverr-plugin", + "publish:minor": "npm version -w packages/reiverr-plugin --git-tag-version false minor && npm run -w packages/reiverr-plugin build && npm publish -w packages/reiverr-plugin", + "publish:major": "npm version -w packages/reiverr-plugin --git-tag-version false major && npm run -w packages/reiverr-plugin build && npm publish -w packages/reiverr-plugin", "openapi:generate:tmdb": "ts-node scripts/generate-tmdb-openapi.ts", "openapi:generate-spec": "ts-node scripts/generate-openapi-spec.ts", "typeorm": "ts-node ./node_modules/typeorm/cli", @@ -96,4 +99,4 @@ "packages/jellyfin.plugin", "packages/torrent-stream.plugin" ] -} \ No newline at end of file +} diff --git a/backend/packages/reiverr-plugin/package.json b/backend/packages/reiverr-plugin/package.json index 5ec6912..f9342c7 100644 --- a/backend/packages/reiverr-plugin/package.json +++ b/backend/packages/reiverr-plugin/package.json @@ -1,12 +1,9 @@ { "name": "@aleksilassila/reiverr-plugin", - "version": "1.0.0", - "main": "dist/index", + "version": "2.0.0", + "main": "dist/src/index", "scripts": { - "build": "tsc", - "publish:patch": "npm version patch && npm publish", - "publish:minor": "npm version minor && npm publish", - "publish:major": "npm version major && npm publish" + "build": "tsc" }, "author": "", "license": "ISC", diff --git a/backend/packages/reiverr-plugin/src/plugin.ts b/backend/packages/reiverr-plugin/src/plugin.ts index 73ebaf7..7d1baba 100644 --- a/backend/packages/reiverr-plugin/src/plugin.ts +++ b/backend/packages/reiverr-plugin/src/plugin.ts @@ -11,6 +11,7 @@ import { Stream, StreamCandidate, } from './types'; +import * as packageJson from '../package.json'; /** * PluginProvider is a class that provides a list of SourceProvider instances. @@ -139,4 +140,27 @@ export abstract class SourceProvider { res: any, options: { context: UserContext; uri: string; targetUrl?: string }, ) => Promise; + + _isCompatibleWith(version: string): boolean { + const pluginVersion = getReiverrPluginVersion(); + const pluginVersionParts = pluginVersion.split('.'); + const versionParts = version.split('.'); + console.log('comparing versions', pluginVersion, version); + + if ( + !pluginVersionParts.length || + pluginVersionParts.length !== versionParts.length + ) { + return false; + } + + return ( + pluginVersionParts[0] === versionParts[0] && + Number(pluginVersionParts[1]) >= Number(versionParts[1]) + ); + } +} + +export function getReiverrPluginVersion(): string { + return packageJson.version; } diff --git a/backend/packages/reiverr-plugin/tsconfig.json b/backend/packages/reiverr-plugin/tsconfig.json index 901b29d..b86ebb7 100644 --- a/backend/packages/reiverr-plugin/tsconfig.json +++ b/backend/packages/reiverr-plugin/tsconfig.json @@ -14,7 +14,8 @@ "incremental": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": false, - "lib": ["es6"] + "lib": ["es6"], + "resolveJsonModule": true }, - "include": ["src/**/*.ts"] + "include": ["src/**/*.ts", "package.json"] } diff --git a/backend/packages/torrent-stream.plugin/.dockerignore b/backend/packages/torrent-stream.plugin/.dockerignore new file mode 100644 index 0000000..4c27d8d --- /dev/null +++ b/backend/packages/torrent-stream.plugin/.dockerignore @@ -0,0 +1,2 @@ +stream-cache.json +torrent-stream-downloads diff --git a/backend/src/source-providers/source-providers.service.ts b/backend/src/source-providers/source-providers.service.ts index fffbdfe..3bdb4db 100644 --- a/backend/src/source-providers/source-providers.service.ts +++ b/backend/src/source-providers/source-providers.service.ts @@ -1,7 +1,11 @@ import { Injectable, Logger } from '@nestjs/common'; import * as fs from 'fs'; import * as path from 'path'; -import { PluginProvider, SourceProvider } from '@aleksilassila/reiverr-plugin'; +import { + PluginProvider, + SourceProvider, + getReiverrPluginVersion, +} from '@aleksilassila/reiverr-plugin'; @Injectable() export class SourceProvidersService { @@ -43,9 +47,12 @@ export class SourceProvidersService { try { // eslint-disable-next-line @typescript-eslint/no-var-requires const pluginModule = require(pluginPath); - const provider: PluginProvider = new pluginModule.default(); + const provider: PluginProvider = + new pluginModule.default() as PluginProvider; provider.getPlugins().forEach((plugin) => { - plugins[plugin.name] = plugin; + if (plugin._isCompatibleWith(getReiverrPluginVersion())) { + plugins[plugin.name] = plugin; + } }); } catch (e) { this.logger.error(`Failed to load plugin from ${pluginPath}: ${e}`);