Remove backward compatibility (peertubeHelpers.user.getAuthUser always available).
This commit is contained in:
		
							
								
								
									
										7
									
								
								server/@types/peertube.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								server/@types/peertube.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -127,14 +127,12 @@ interface PeerTubeHelpers { | ||||
|   } | ||||
|   videos: { | ||||
|     loadByUrl: (url: string) => Promise<MVideoThumbnail> | ||||
|     // NB: loadByIdOrUUID was introduced in v3.1.0 | ||||
|     loadByIdOrUUID: (id: number | string) => Promise<MVideoThumbnail> | ||||
|     removeVideo: (videoId: number) => Promise<void> | ||||
|   } | ||||
|   config: { | ||||
|     getWebserverUrl: () => string | ||||
|     // getServerConfig comes with Peertube 3.2.0 | ||||
|     getServerConfig?: () => Promise<ServerConfig> | ||||
|     getServerConfig: () => Promise<ServerConfig> | ||||
|   } | ||||
|   moderation: { | ||||
|     blockServer: (options: { byAccountId: number, hostToBlock: string }) => Promise<void> | ||||
| @ -149,8 +147,7 @@ interface PeerTubeHelpers { | ||||
|   server: { | ||||
|     getServerActor: () => Promise<ActorModel> | ||||
|   } | ||||
|   // Added in Peertube 3.2.0 | ||||
|   user?: { | ||||
|   user: { | ||||
|     getAuthUser: (res: express.Response) => Promise<MUserDefault | undefined> | ||||
|   } | ||||
|   // Added in Peertube 3.2.0 | ||||
|  | ||||
| @ -29,10 +29,8 @@ function getBaseStaticRoute (options: RegisterServerOptions): string { | ||||
|   return '/plugins/' + pluginShortName + '/' + version + '/static/' | ||||
| } | ||||
|  | ||||
| // Peertube <= 3.1.0 has no way to test that current user is admin | ||||
| // Peertube >= 3.2.0 has getAuthUser helper | ||||
| async function isUserAdmin (options: RegisterServerOptions, res: Response): Promise<boolean> { | ||||
|   const user = await getAuthUser(options, res) | ||||
|   const user = await options.peertubeHelpers.user.getAuthUser(res) | ||||
|   if (!user) { | ||||
|     return false | ||||
|   } | ||||
| @ -45,18 +43,6 @@ async function isUserAdmin (options: RegisterServerOptions, res: Response): Prom | ||||
|   return true | ||||
| } | ||||
|  | ||||
| // Peertube <= 3.1.0 has no way to get user informations. | ||||
| // This is a hack. | ||||
| // Peertube >= 3.2.0 has getAuthUser helper | ||||
| async function getAuthUser (options: RegisterServerOptions, res: Response): Promise<MUserDefault | undefined> { | ||||
|   const peertubeHelpers = options.peertubeHelpers | ||||
|   if (peertubeHelpers.user?.getAuthUser) { | ||||
|     return peertubeHelpers.user.getAuthUser(res) | ||||
|   } | ||||
|   peertubeHelpers.logger.debug('Peertube does not provide getAuthUser for now, fallback on hack') | ||||
|   return res.locals.oauth?.token?.User | ||||
| } | ||||
|  | ||||
| async function getUserNickname (options: RegisterServerOptions, user: MUserDefault): Promise<string | undefined> { | ||||
|   const peertubeHelpers = options.peertubeHelpers | ||||
|   const logger = peertubeHelpers.logger | ||||
| @ -72,7 +58,6 @@ export { | ||||
|   getBaseRouterRoute, | ||||
|   getBaseStaticRoute, | ||||
|   isUserAdmin, | ||||
|   getAuthUser, | ||||
|   getUserNickname, | ||||
|   pluginName, | ||||
|   pluginShortName | ||||
|  | ||||
| @ -3,7 +3,7 @@ import { videoHasWebchat } from '../../../shared/lib/video' | ||||
| import { asyncMiddleware } from '../middlewares/async' | ||||
| import { getCheckAPIKeyMiddleware } from '../middlewares/apikey' | ||||
| import { prosodyCheckUserPassword, prosodyRegisterUser, prosodyUserRegistered } from '../prosody/auth' | ||||
| import { getAuthUser, getUserNickname } from '../helpers' | ||||
| import { getUserNickname } from '../helpers' | ||||
| import { Affiliations, getVideoAffiliations } from '../prosody/config/affiliations' | ||||
| import { getProsodyDomain } from '../prosody/config/domain' | ||||
|  | ||||
| @ -92,7 +92,7 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> { | ||||
|  | ||||
|   router.get('/auth', asyncMiddleware( | ||||
|     async (req: Request, res: Response, _next: NextFunction) => { | ||||
|       const user = await getAuthUser(options, res) | ||||
|       const user = await peertubeHelpers.user.getAuthUser(res) | ||||
|       if (!user) { | ||||
|         res.sendStatus(403) | ||||
|         return | ||||
|  | ||||
		Reference in New Issue
	
	Block a user