mirror of https://github.com/Chocobozzz/PeerTube
feat(client/plugins): add getUser to helpers
Let plugins access the user object. closes #6355pull/6346/head
parent
1eb8fc2c06
commit
8624325523
|
@ -250,6 +250,10 @@ export class PluginService implements ClientHook {
|
||||||
return firstValueFrom(obs)
|
return firstValueFrom(obs)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getUser: () => {
|
||||||
|
return this.authService.getUser()
|
||||||
|
},
|
||||||
|
|
||||||
getServerConfig: () => {
|
getServerConfig: () => {
|
||||||
const obs = this.server.getConfig()
|
const obs = this.server.getConfig()
|
||||||
.pipe(catchError(res => this.restExtractor.handleError(res)))
|
.pipe(catchError(res => this.restExtractor.handleError(res)))
|
||||||
|
|
|
@ -74,54 +74,12 @@ export class User implements UserServerModel {
|
||||||
createdAt: Date
|
createdAt: Date
|
||||||
|
|
||||||
constructor (hash: Partial<UserServerModel>) {
|
constructor (hash: Partial<UserServerModel>) {
|
||||||
this.id = hash.id
|
const { account, ...mergeProps }: Partial<UserServerModel> = hash
|
||||||
this.username = hash.username
|
|
||||||
this.email = hash.email
|
|
||||||
|
|
||||||
this.role = hash.role
|
Object.assign(this, mergeProps)
|
||||||
|
|
||||||
this.videoChannels = hash.videoChannels
|
if (account !== undefined) {
|
||||||
|
this.account = new Account(account)
|
||||||
this.videoQuota = hash.videoQuota
|
|
||||||
this.videoQuotaDaily = hash.videoQuotaDaily
|
|
||||||
this.videoQuotaUsed = hash.videoQuotaUsed
|
|
||||||
this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily
|
|
||||||
this.videosCount = hash.videosCount
|
|
||||||
this.abusesCount = hash.abusesCount
|
|
||||||
this.abusesAcceptedCount = hash.abusesAcceptedCount
|
|
||||||
this.abusesCreatedCount = hash.abusesCreatedCount
|
|
||||||
this.videoCommentsCount = hash.videoCommentsCount
|
|
||||||
|
|
||||||
this.nsfwPolicy = hash.nsfwPolicy
|
|
||||||
this.p2pEnabled = hash.p2pEnabled
|
|
||||||
this.autoPlayVideo = hash.autoPlayVideo
|
|
||||||
this.autoPlayNextVideo = hash.autoPlayNextVideo
|
|
||||||
this.autoPlayNextVideoPlaylist = hash.autoPlayNextVideoPlaylist
|
|
||||||
this.videosHistoryEnabled = hash.videosHistoryEnabled
|
|
||||||
this.videoLanguages = hash.videoLanguages
|
|
||||||
|
|
||||||
this.theme = hash.theme
|
|
||||||
|
|
||||||
this.adminFlags = hash.adminFlags
|
|
||||||
|
|
||||||
this.blocked = hash.blocked
|
|
||||||
this.blockedReason = hash.blockedReason
|
|
||||||
|
|
||||||
this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal
|
|
||||||
this.noWelcomeModal = hash.noWelcomeModal
|
|
||||||
this.noAccountSetupWarningModal = hash.noAccountSetupWarningModal
|
|
||||||
|
|
||||||
this.notificationSettings = hash.notificationSettings
|
|
||||||
|
|
||||||
this.twoFactorEnabled = hash.twoFactorEnabled
|
|
||||||
|
|
||||||
this.createdAt = hash.createdAt
|
|
||||||
|
|
||||||
this.pluginAuth = hash.pluginAuth
|
|
||||||
this.lastLoginDate = hash.lastLoginDate
|
|
||||||
|
|
||||||
if (hash.account !== undefined) {
|
|
||||||
this.account = new Account(hash.account)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,8 @@ export class PeerTubePlugin {
|
||||||
.then((obj: PublicServerSetting) => obj.publicSettings)
|
.then((obj: PublicServerSetting) => obj.publicSettings)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getUser: unimplemented,
|
||||||
|
|
||||||
isLoggedIn: () => this.http.isLoggedIn(),
|
isLoggedIn: () => this.http.isLoggedIn(),
|
||||||
getAuthHeader: () => {
|
getAuthHeader: () => {
|
||||||
if (!this.http.isLoggedIn()) return undefined
|
if (!this.http.isLoggedIn()) return undefined
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { AuthUser } from '@app/core'
|
||||||
import {
|
import {
|
||||||
RegisterClientFormFieldOptions,
|
RegisterClientFormFieldOptions,
|
||||||
RegisterClientHookOptions,
|
RegisterClientHookOptions,
|
||||||
|
@ -35,6 +36,8 @@ export type RegisterClientHelpers = {
|
||||||
|
|
||||||
getSettings: () => Promise<SettingEntries>
|
getSettings: () => Promise<SettingEntries>
|
||||||
|
|
||||||
|
getUser: () => AuthUser
|
||||||
|
|
||||||
getServerConfig: () => Promise<ServerConfig>
|
getServerConfig: () => Promise<ServerConfig>
|
||||||
|
|
||||||
notifier: {
|
notifier: {
|
||||||
|
|
Loading…
Reference in New Issue