From 6702a1b2ccd666285dee9c72b5bace641d2fce8b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 16 Jul 2019 11:33:22 +0200 Subject: Add ability to search available plugins --- shared/core-utils/miscs/miscs.ts | 20 +++++++++++++++++++- .../plugins/peertube-plugin-index-list.model.ts | 10 ++++++++++ shared/models/plugins/peertube-plugin-index.model.ts | 3 +++ .../plugins/peertube-plugin-latest-version.model.ts | 7 ++++++- shared/models/plugins/peertube-plugin-list.model.ts | 10 ---------- 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 shared/models/plugins/peertube-plugin-index-list.model.ts delete mode 100644 shared/models/plugins/peertube-plugin-list.model.ts (limited to 'shared') diff --git a/shared/core-utils/miscs/miscs.ts b/shared/core-utils/miscs/miscs.ts index c668e44c1..a3921b568 100644 --- a/shared/core-utils/miscs/miscs.ts +++ b/shared/core-utils/miscs/miscs.ts @@ -2,6 +2,24 @@ function randomInt (low: number, high: number) { return Math.floor(Math.random() * (high - low) + low) } +// Thanks https://stackoverflow.com/a/16187766 +function compareSemVer (a: string, b: string) { + const regExStrip0 = /(\.0+)+$/ + const segmentsA = a.replace(regExStrip0, '').split('.') + const segmentsB = b.replace(regExStrip0, '').split('.') + + const l = Math.min(segmentsA.length, segmentsB.length) + + for (let i = 0; i < l; i++) { + const diff = parseInt(segmentsA[ i ], 10) - parseInt(segmentsB[ i ], 10) + + if (diff) return diff + } + + return segmentsA.length - segmentsB.length +} + export { - randomInt + randomInt, + compareSemVer } diff --git a/shared/models/plugins/peertube-plugin-index-list.model.ts b/shared/models/plugins/peertube-plugin-index-list.model.ts new file mode 100644 index 000000000..817bac31e --- /dev/null +++ b/shared/models/plugins/peertube-plugin-index-list.model.ts @@ -0,0 +1,10 @@ +import { PluginType } from './plugin.type' + +export interface PeertubePluginIndexList { + start: number + count: number + sort: string + pluginType?: PluginType + currentPeerTubeEngine?: string + search?: string +} diff --git a/shared/models/plugins/peertube-plugin-index.model.ts b/shared/models/plugins/peertube-plugin-index.model.ts index 2957a338d..e91c8b4dc 100644 --- a/shared/models/plugins/peertube-plugin-index.model.ts +++ b/shared/models/plugins/peertube-plugin-index.model.ts @@ -8,4 +8,7 @@ export interface PeerTubePluginIndex { popularity: number latestVersion: string + + name?: string + installed?: boolean } diff --git a/shared/models/plugins/peertube-plugin-latest-version.model.ts b/shared/models/plugins/peertube-plugin-latest-version.model.ts index 36dd3af54..dec4618fa 100644 --- a/shared/models/plugins/peertube-plugin-latest-version.model.ts +++ b/shared/models/plugins/peertube-plugin-latest-version.model.ts @@ -1,5 +1,10 @@ -export interface PeertubePluginLatestVersion { +export interface PeertubePluginLatestVersionRequest { currentPeerTubeEngine?: string, npmNames: string[] } + +export type PeertubePluginLatestVersionResponse = { + npmName: string + latestVersion: string | null +}[] diff --git a/shared/models/plugins/peertube-plugin-list.model.ts b/shared/models/plugins/peertube-plugin-list.model.ts deleted file mode 100644 index 5f0ecce68..000000000 --- a/shared/models/plugins/peertube-plugin-list.model.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { PluginType } from './plugin.type' - -export interface PeertubePluginList { - start: number - count: number - sort: string - pluginType?: PluginType - currentPeerTubeEngine?: string - search?: string -} -- cgit v1.2.3