mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-17 19:53:11 +02:00
feat: reiverr-plugin:2.0.0 version checking
This commit is contained in:
@@ -4,5 +4,6 @@ build
|
||||
.idea
|
||||
.env
|
||||
.DS_Store
|
||||
.git
|
||||
|
||||
backend/plugins
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"lib": ["es6"]
|
||||
"lib": ["es6"],
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
"include": ["src/**/*.ts", "package.json"]
|
||||
}
|
||||
|
||||
2
backend/packages/torrent-stream.plugin/.dockerignore
Normal file
2
backend/packages/torrent-stream.plugin/.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
||||
stream-cache.json
|
||||
torrent-stream-downloads
|
||||
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user