(permissions: Permission[])
| 38 | |
| 39 | let _apiKey: ApiKeyResponseDto; |
| 40 | export const requirePermissions = async (permissions: Permission[]) => { |
| 41 | if (!_apiKey) { |
| 42 | _apiKey = await getMyApiKey(); |
| 43 | } |
| 44 | |
| 45 | if (_apiKey.permissions.includes(Permission.All)) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | const missing: Permission[] = []; |
| 50 | |
| 51 | for (const permission of permissions) { |
| 52 | if (!_apiKey.permissions.includes(permission)) { |
| 53 | missing.push(permission); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if (missing.length > 0) { |
| 58 | const combined = missing.map((permission) => `"${permission}"`).join(', '); |
| 59 | console.log( |
| 60 | `Missing required permission${s(missing.length)}: ${combined}. |
| 61 | Please make sure your API key has the correct permissions.`, |
| 62 | ); |
| 63 | process.exit(1); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | export const connect = async (url: string, key: string) => { |
| 68 | const wellKnownUrl = new URL('.well-known/immich', url); |
no test coverage detected