diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-16 11:33:22 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 6702a1b2ccd666285dee9c72b5bace641d2fce8b (patch) | |
tree | 78b7125d664b6f6b6c993c4e8483e1bdd24a0a30 /shared | |
parent | 503c6f440abc8f5924c38c4bd63591cb6cefacec (diff) | |
download | PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.tar.gz PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.tar.zst PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.zip |
Add ability to search available plugins
Diffstat (limited to 'shared')
-rw-r--r-- | shared/core-utils/miscs/miscs.ts | 20 | ||||
-rw-r--r-- | shared/models/plugins/peertube-plugin-index-list.model.ts (renamed from shared/models/plugins/peertube-plugin-list.model.ts) | 2 | ||||
-rw-r--r-- | shared/models/plugins/peertube-plugin-index.model.ts | 3 | ||||
-rw-r--r-- | shared/models/plugins/peertube-plugin-latest-version.model.ts | 7 |
4 files changed, 29 insertions, 3 deletions
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) { | |||
2 | return Math.floor(Math.random() * (high - low) + low) | 2 | return Math.floor(Math.random() * (high - low) + low) |
3 | } | 3 | } |
4 | 4 | ||
5 | // Thanks https://stackoverflow.com/a/16187766 | ||
6 | function compareSemVer (a: string, b: string) { | ||
7 | const regExStrip0 = /(\.0+)+$/ | ||
8 | const segmentsA = a.replace(regExStrip0, '').split('.') | ||
9 | const segmentsB = b.replace(regExStrip0, '').split('.') | ||
10 | |||
11 | const l = Math.min(segmentsA.length, segmentsB.length) | ||
12 | |||
13 | for (let i = 0; i < l; i++) { | ||
14 | const diff = parseInt(segmentsA[ i ], 10) - parseInt(segmentsB[ i ], 10) | ||
15 | |||
16 | if (diff) return diff | ||
17 | } | ||
18 | |||
19 | return segmentsA.length - segmentsB.length | ||
20 | } | ||
21 | |||
5 | export { | 22 | export { |
6 | randomInt | 23 | randomInt, |
24 | compareSemVer | ||
7 | } | 25 | } |
diff --git a/shared/models/plugins/peertube-plugin-list.model.ts b/shared/models/plugins/peertube-plugin-index-list.model.ts index 5f0ecce68..817bac31e 100644 --- a/shared/models/plugins/peertube-plugin-list.model.ts +++ b/shared/models/plugins/peertube-plugin-index-list.model.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { PluginType } from './plugin.type' | 1 | import { PluginType } from './plugin.type' |
2 | 2 | ||
3 | export interface PeertubePluginList { | 3 | export interface PeertubePluginIndexList { |
4 | start: number | 4 | start: number |
5 | count: number | 5 | count: number |
6 | sort: string | 6 | sort: 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 { | |||
8 | popularity: number | 8 | popularity: number |
9 | 9 | ||
10 | latestVersion: string | 10 | latestVersion: string |
11 | |||
12 | name?: string | ||
13 | installed?: boolean | ||
11 | } | 14 | } |
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 @@ | |||
1 | export interface PeertubePluginLatestVersion { | 1 | export interface PeertubePluginLatestVersionRequest { |
2 | currentPeerTubeEngine?: string, | 2 | currentPeerTubeEngine?: string, |
3 | 3 | ||
4 | npmNames: string[] | 4 | npmNames: string[] |
5 | } | 5 | } |
6 | |||
7 | export type PeertubePluginLatestVersionResponse = { | ||
8 | npmName: string | ||
9 | latestVersion: string | null | ||
10 | }[] | ||