Unallow transcoding per default for new users
This commit is contained in:
parent
a4d7c57d10
commit
fa9998e92c
@ -2,7 +2,7 @@ import { GuildMember } from "discord.js";
|
||||
import { JellyfinConfig, Maybe, PermissionLevel } from "../interfaces";
|
||||
import { logger } from "../logger";
|
||||
import { CreateUserByNameOperationRequest, DeleteUserRequest, GetItemsRequest, ItemsApi, SystemApi, UpdateUserPasswordOperationRequest, UpdateUserPolicyOperationRequest, UserApi } from "./apis";
|
||||
import { BaseItemDto, UpdateUserPasswordRequest } from "./models";
|
||||
import { BaseItemDto, UpdateUserPasswordRequest, UpdateUserPolicyRequest } from "./models";
|
||||
import { UserDto } from "./models/UserDto";
|
||||
import { Configuration, ConfigurationParameters } from "./runtime";
|
||||
|
||||
@ -52,24 +52,46 @@ export class JellyfinHandler {
|
||||
return (Math.random() * 10000 + 10000).toFixed(0)
|
||||
}
|
||||
|
||||
public async createUserAccountForDiscordUser(discordUser: GuildMember, level: PermissionLevel, guildId?: string, requestId?: string): Promise<UserDto> {
|
||||
public async createUserAccountForDiscordUser(discordUser: GuildMember, level: PermissionLevel, requestId: string, guildId?: string): Promise<UserDto> {
|
||||
const newUserName = this.generateJFUserName(discordUser, level)
|
||||
logger.info(`New Username for ${discordUser.displayName}: ${newUserName}`, { guildId, requestId })
|
||||
const req: CreateUserByNameOperationRequest = {
|
||||
createUserByNameRequest: {
|
||||
name: newUserName,
|
||||
password: this.generatePasswordForUser(),
|
||||
password: this.generatePasswordForUser()
|
||||
}
|
||||
}
|
||||
logger.debug(JSON.stringify(req), { requestId, guildId })
|
||||
const createResult = await this.userApi.createUserByName(req)
|
||||
if (createResult) {
|
||||
if(createResult.policy) {
|
||||
this.setUserPermissions(createResult, requestId, guildId)
|
||||
}
|
||||
(await discordUser.createDM()).send(`Ich hab dir mal nen Account angelegt :)\nDein Username ist ${createResult.name}, dein Password ist "${req.createUserByNameRequest.password}"!`)
|
||||
return createResult
|
||||
}
|
||||
else throw new Error('Could not create User in Jellyfin')
|
||||
}
|
||||
|
||||
public async setUserPermissions(user: UserDto, requestId: string, guildId?: string) {
|
||||
if(!user.policy || !user.id) {
|
||||
logger.error(`Cannot update user policy. User ${user.name} has no policy to modify`, {guildId, requestId})
|
||||
return
|
||||
}
|
||||
user.policy.enableVideoPlaybackTranscoding = false
|
||||
|
||||
const operation: UpdateUserPolicyRequest = {
|
||||
...user.policy,
|
||||
enableVideoPlaybackTranscoding: false
|
||||
}
|
||||
|
||||
const request: UpdateUserPolicyOperationRequest = {
|
||||
userId: user.id,
|
||||
updateUserPolicyRequest: operation
|
||||
}
|
||||
this.userApi.updateUserPolicy(request)
|
||||
}
|
||||
|
||||
public async isUserAlreadyPresent(discordUser: GuildMember, requestId?: string): Promise<boolean> {
|
||||
const jfuser = await this.getUser(discordUser, requestId)
|
||||
logger.debug(`Presence for DiscordUser ${discordUser.id}:${jfuser !== undefined}`, { guildId: discordUser.guild.id, requestId })
|
||||
|
Loading…
Reference in New Issue
Block a user