feat: reiverr-plugin:2.0.0 version checking

This commit is contained in:
Aleksi Lassila
2025-02-12 18:27:17 +02:00
parent dfa59a1994
commit 77cb5d6192
8 changed files with 48 additions and 13 deletions

View File

@@ -4,5 +4,6 @@ build
.idea
.env
.DS_Store
.git
backend/plugins

View File

@@ -5,4 +5,4 @@
"compilerOptions": {
"deleteOutDir": true
}
}
}

View File

@@ -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"
]
}
}

View File

@@ -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",

View File

@@ -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<any>;
_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;
}

View File

@@ -14,7 +14,8 @@
"incremental": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": false,
"lib": ["es6"]
"lib": ["es6"],
"resolveJsonModule": true
},
"include": ["src/**/*.ts"]
"include": ["src/**/*.ts", "package.json"]
}

View File

@@ -0,0 +1,2 @@
stream-cache.json
torrent-stream-downloads

View File

@@ -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}`);