diff options
Diffstat (limited to 'client/src/root-helpers')
-rw-r--r-- | client/src/root-helpers/logger.ts | 4 | ||||
-rw-r--r-- | client/src/root-helpers/users/index.ts | 2 | ||||
-rw-r--r-- | client/src/root-helpers/users/oauth-user-tokens.ts (renamed from client/src/root-helpers/users/user-tokens.ts) | 8 | ||||
-rw-r--r-- | client/src/root-helpers/video.ts | 9 |
4 files changed, 14 insertions, 9 deletions
diff --git a/client/src/root-helpers/logger.ts b/client/src/root-helpers/logger.ts index 0d486c433..d1fdf73aa 100644 --- a/client/src/root-helpers/logger.ts +++ b/client/src/root-helpers/logger.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { ClientLogCreate } from '@shared/models/server' | 1 | import { ClientLogCreate } from '@shared/models/server' |
2 | import { peertubeLocalStorage } from './peertube-web-storage' | 2 | import { peertubeLocalStorage } from './peertube-web-storage' |
3 | import { UserTokens } from './users' | 3 | import { OAuthUserTokens } from './users' |
4 | 4 | ||
5 | export type LoggerHook = (message: LoggerMessage, meta?: LoggerMeta) => void | 5 | export type LoggerHook = (message: LoggerMessage, meta?: LoggerMeta) => void |
6 | export type LoggerLevel = 'info' | 'warn' | 'error' | 6 | export type LoggerLevel = 'info' | 'warn' | 'error' |
@@ -56,7 +56,7 @@ class Logger { | |||
56 | }) | 56 | }) |
57 | 57 | ||
58 | try { | 58 | try { |
59 | const tokens = UserTokens.getUserTokens(peertubeLocalStorage) | 59 | const tokens = OAuthUserTokens.getUserTokens(peertubeLocalStorage) |
60 | 60 | ||
61 | if (tokens) headers.set('Authorization', `${tokens.tokenType} ${tokens.accessToken}`) | 61 | if (tokens) headers.set('Authorization', `${tokens.tokenType} ${tokens.accessToken}`) |
62 | } catch (err) { | 62 | } catch (err) { |
diff --git a/client/src/root-helpers/users/index.ts b/client/src/root-helpers/users/index.ts index 2b11d0b7e..c03e67325 100644 --- a/client/src/root-helpers/users/index.ts +++ b/client/src/root-helpers/users/index.ts | |||
@@ -1,2 +1,2 @@ | |||
1 | export * from './user-local-storage-keys' | 1 | export * from './user-local-storage-keys' |
2 | export * from './user-tokens' | 2 | export * from './oauth-user-tokens' |
diff --git a/client/src/root-helpers/users/user-tokens.ts b/client/src/root-helpers/users/oauth-user-tokens.ts index a6d614cb7..a24e76b91 100644 --- a/client/src/root-helpers/users/user-tokens.ts +++ b/client/src/root-helpers/users/oauth-user-tokens.ts | |||
@@ -1,11 +1,11 @@ | |||
1 | import { UserTokenLocalStorageKeys } from './user-local-storage-keys' | 1 | import { UserTokenLocalStorageKeys } from './user-local-storage-keys' |
2 | 2 | ||
3 | export class UserTokens { | 3 | export class OAuthUserTokens { |
4 | accessToken: string | 4 | accessToken: string |
5 | refreshToken: string | 5 | refreshToken: string |
6 | tokenType: string | 6 | tokenType: string |
7 | 7 | ||
8 | constructor (hash?: Partial<UserTokens>) { | 8 | constructor (hash?: Partial<OAuthUserTokens>) { |
9 | if (hash) { | 9 | if (hash) { |
10 | this.accessToken = hash.accessToken | 10 | this.accessToken = hash.accessToken |
11 | this.refreshToken = hash.refreshToken | 11 | this.refreshToken = hash.refreshToken |
@@ -25,14 +25,14 @@ export class UserTokens { | |||
25 | 25 | ||
26 | if (!accessTokenLocalStorage || !refreshTokenLocalStorage || !tokenTypeLocalStorage) return null | 26 | if (!accessTokenLocalStorage || !refreshTokenLocalStorage || !tokenTypeLocalStorage) return null |
27 | 27 | ||
28 | return new UserTokens({ | 28 | return new OAuthUserTokens({ |
29 | accessToken: accessTokenLocalStorage, | 29 | accessToken: accessTokenLocalStorage, |
30 | refreshToken: refreshTokenLocalStorage, | 30 | refreshToken: refreshTokenLocalStorage, |
31 | tokenType: tokenTypeLocalStorage | 31 | tokenType: tokenTypeLocalStorage |
32 | }) | 32 | }) |
33 | } | 33 | } |
34 | 34 | ||
35 | static saveToLocalStorage (localStorage: Pick<Storage, 'setItem'>, tokens: UserTokens) { | 35 | static saveToLocalStorage (localStorage: Pick<Storage, 'setItem'>, tokens: OAuthUserTokens) { |
36 | localStorage.setItem(UserTokenLocalStorageKeys.ACCESS_TOKEN, tokens.accessToken) | 36 | localStorage.setItem(UserTokenLocalStorageKeys.ACCESS_TOKEN, tokens.accessToken) |
37 | localStorage.setItem(UserTokenLocalStorageKeys.REFRESH_TOKEN, tokens.refreshToken) | 37 | localStorage.setItem(UserTokenLocalStorageKeys.REFRESH_TOKEN, tokens.refreshToken) |
38 | localStorage.setItem(UserTokenLocalStorageKeys.TOKEN_TYPE, tokens.tokenType) | 38 | localStorage.setItem(UserTokenLocalStorageKeys.TOKEN_TYPE, tokens.tokenType) |
diff --git a/client/src/root-helpers/video.ts b/client/src/root-helpers/video.ts index ba84e49ea..107ba1eba 100644 --- a/client/src/root-helpers/video.ts +++ b/client/src/root-helpers/video.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { HTMLServerConfig, Video } from '@shared/models' | 1 | import { HTMLServerConfig, Video, VideoPrivacy } from '@shared/models' |
2 | 2 | ||
3 | function buildVideoOrPlaylistEmbed (options: { | 3 | function buildVideoOrPlaylistEmbed (options: { |
4 | embedUrl: string | 4 | embedUrl: string |
@@ -26,9 +26,14 @@ function isP2PEnabled (video: Video, config: HTMLServerConfig, userP2PEnabled: b | |||
26 | return userP2PEnabled | 26 | return userP2PEnabled |
27 | } | 27 | } |
28 | 28 | ||
29 | function videoRequiresAuth (video: Video) { | ||
30 | return new Set([ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]).has(video.privacy.id) | ||
31 | } | ||
32 | |||
29 | export { | 33 | export { |
30 | buildVideoOrPlaylistEmbed, | 34 | buildVideoOrPlaylistEmbed, |
31 | isP2PEnabled | 35 | isP2PEnabled, |
36 | videoRequiresAuth | ||
32 | } | 37 | } |
33 | 38 | ||
34 | // --------------------------------------------------------------------------- | 39 | // --------------------------------------------------------------------------- |