flesh out startup, connect to jf, handover to discordjs
This commit is contained in:
		
							
								
								
									
										37
									
								
								index.ts
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								index.ts
									
									
									
									
									
								
							@@ -1,26 +1,21 @@
 | 
				
			|||||||
import { ExtendedClient } from "./server/structures/client"
 | 
					import { ExtendedClient } from "./server/structures/client"
 | 
				
			||||||
export const client = new ExtendedClient()
 | 
					import { JellyfinHandler } from "./jellyfin/handler"
 | 
				
			||||||
 | 
					 | 
				
			||||||
import { AuthenticateUserByNameRequest, CreateUserByNameRequest } from "./jellyfin/api"
 | 
					 | 
				
			||||||
import { UserApi } from "./jellyfin/api/userApi"
 | 
					 | 
				
			||||||
import { config } from "./server/configuration"
 | 
					import { config } from "./server/configuration"
 | 
				
			||||||
client.start()
 | 
					import { logger } from "./server/logger"
 | 
				
			||||||
 | 
					const requestId = 'startup'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function start() {
 | 
					const jellyfinHandler = new JellyfinHandler(config)
 | 
				
			||||||
  const jfUserAPI: UserApi = new UserApi(config.jellyfin_url)
 | 
					
 | 
				
			||||||
  const options = {
 | 
					export const client = new ExtendedClient(jellyfinHandler)
 | 
				
			||||||
    headers: {
 | 
					
 | 
				
			||||||
      "X-MediaBrowser-Token": config.jellfin_token
 | 
					async function init() {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    const users = await jellyfinHandler.getCurrentUsers("", requestId)
 | 
				
			||||||
 | 
					    logger.info(`Fetched ${users.map(x => x.name).join(', ')} from JF`, { requestId })
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    logger.error(`Error fetching existing users from Jellyfin`, { requestId })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  }
 | 
					  logger.info(`Starting client`, { requestId })
 | 
				
			||||||
  let u = (await jfUserAPI.getUsers(false, false, options)).body
 | 
					  client.start()
 | 
				
			||||||
  console.log(JSON.stringify(u.map(x => x.name), null, 2))
 | 
					 | 
				
			||||||
  const user: CreateUserByNameRequest = {
 | 
					 | 
				
			||||||
    name: "Testuser1",
 | 
					 | 
				
			||||||
    password: "1234"
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  const a = await jfUserAPI.createUserByName(user, options)
 | 
					 | 
				
			||||||
  console.log(JSON.stringify(a, null, 2))
 | 
					 | 
				
			||||||
  u = (await jfUserAPI.getUsers(undefined, undefined, options)).body
 | 
					 | 
				
			||||||
  console.log(JSON.stringify(u.map(x => x.name), null, 2))
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					init()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user