From 3545e72c686ff1725bbdfd8d16d693e2f4aa75a3 Mon Sep 17 00:00:00 2001 From: Chocobozzz <me@florianbigard.com> Date: Wed, 12 Oct 2022 16:09:02 +0200 Subject: Put private videos under a specific subdirectory --- client/src/root-helpers/users/index.ts | 2 +- client/src/root-helpers/users/oauth-user-tokens.ts | 46 ++++++++++++++++++++++ client/src/root-helpers/users/user-tokens.ts | 46 ---------------------- 3 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 client/src/root-helpers/users/oauth-user-tokens.ts delete mode 100644 client/src/root-helpers/users/user-tokens.ts (limited to 'client/src/root-helpers/users') 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 @@ export * from './user-local-storage-keys' -export * from './user-tokens' +export * from './oauth-user-tokens' diff --git a/client/src/root-helpers/users/oauth-user-tokens.ts b/client/src/root-helpers/users/oauth-user-tokens.ts new file mode 100644 index 000000000..a24e76b91 --- /dev/null +++ b/client/src/root-helpers/users/oauth-user-tokens.ts @@ -0,0 +1,46 @@ +import { UserTokenLocalStorageKeys } from './user-local-storage-keys' + +export class OAuthUserTokens { + accessToken: string + refreshToken: string + tokenType: string + + constructor (hash?: Partial<OAuthUserTokens>) { + if (hash) { + this.accessToken = hash.accessToken + this.refreshToken = hash.refreshToken + + if (hash.tokenType === 'bearer') { + this.tokenType = 'Bearer' + } else { + this.tokenType = hash.tokenType + } + } + } + + static getUserTokens (localStorage: Pick<Storage, 'getItem'>) { + const accessTokenLocalStorage = localStorage.getItem(UserTokenLocalStorageKeys.ACCESS_TOKEN) + const refreshTokenLocalStorage = localStorage.getItem(UserTokenLocalStorageKeys.REFRESH_TOKEN) + const tokenTypeLocalStorage = localStorage.getItem(UserTokenLocalStorageKeys.TOKEN_TYPE) + + if (!accessTokenLocalStorage || !refreshTokenLocalStorage || !tokenTypeLocalStorage) return null + + return new OAuthUserTokens({ + accessToken: accessTokenLocalStorage, + refreshToken: refreshTokenLocalStorage, + tokenType: tokenTypeLocalStorage + }) + } + + static saveToLocalStorage (localStorage: Pick<Storage, 'setItem'>, tokens: OAuthUserTokens) { + localStorage.setItem(UserTokenLocalStorageKeys.ACCESS_TOKEN, tokens.accessToken) + localStorage.setItem(UserTokenLocalStorageKeys.REFRESH_TOKEN, tokens.refreshToken) + localStorage.setItem(UserTokenLocalStorageKeys.TOKEN_TYPE, tokens.tokenType) + } + + static flushLocalStorage (localStorage: Pick<Storage, 'removeItem'>) { + localStorage.removeItem(UserTokenLocalStorageKeys.ACCESS_TOKEN) + localStorage.removeItem(UserTokenLocalStorageKeys.REFRESH_TOKEN) + localStorage.removeItem(UserTokenLocalStorageKeys.TOKEN_TYPE) + } +} diff --git a/client/src/root-helpers/users/user-tokens.ts b/client/src/root-helpers/users/user-tokens.ts deleted file mode 100644 index a6d614cb7..000000000 --- a/client/src/root-helpers/users/user-tokens.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { UserTokenLocalStorageKeys } from './user-local-storage-keys' - -export class UserTokens { - accessToken: string - refreshToken: string - tokenType: string - - constructor (hash?: Partial<UserTokens>) { - if (hash) { - this.accessToken = hash.accessToken - this.refreshToken = hash.refreshToken - - if (hash.tokenType === 'bearer') { - this.tokenType = 'Bearer' - } else { - this.tokenType = hash.tokenType - } - } - } - - static getUserTokens (localStorage: Pick<Storage, 'getItem'>) { - const accessTokenLocalStorage = localStorage.getItem(UserTokenLocalStorageKeys.ACCESS_TOKEN) - const refreshTokenLocalStorage = localStorage.getItem(UserTokenLocalStorageKeys.REFRESH_TOKEN) - const tokenTypeLocalStorage = localStorage.getItem(UserTokenLocalStorageKeys.TOKEN_TYPE) - - if (!accessTokenLocalStorage || !refreshTokenLocalStorage || !tokenTypeLocalStorage) return null - - return new UserTokens({ - accessToken: accessTokenLocalStorage, - refreshToken: refreshTokenLocalStorage, - tokenType: tokenTypeLocalStorage - }) - } - - static saveToLocalStorage (localStorage: Pick<Storage, 'setItem'>, tokens: UserTokens) { - localStorage.setItem(UserTokenLocalStorageKeys.ACCESS_TOKEN, tokens.accessToken) - localStorage.setItem(UserTokenLocalStorageKeys.REFRESH_TOKEN, tokens.refreshToken) - localStorage.setItem(UserTokenLocalStorageKeys.TOKEN_TYPE, tokens.tokenType) - } - - static flushLocalStorage (localStorage: Pick<Storage, 'removeItem'>) { - localStorage.removeItem(UserTokenLocalStorageKeys.ACCESS_TOKEN) - localStorage.removeItem(UserTokenLocalStorageKeys.REFRESH_TOKEN) - localStorage.removeItem(UserTokenLocalStorageKeys.TOKEN_TYPE) - } -} -- cgit v1.2.3