diff --git a/packages/server/src/server/api/v1/interfaces/generalInterface.ts b/packages/server/src/server/api/v1/interfaces/generalInterface.ts index 2bbe78ed..0df5559a 100644 --- a/packages/server/src/server/api/v1/interfaces/generalInterface.ts +++ b/packages/server/src/server/api/v1/interfaces/generalInterface.ts @@ -10,13 +10,14 @@ import { FileSystem } from "@server/fileSystem"; const osVersion = macosVersion(); export class GeneralInterface { - static getServerMetadata(): ServerMetadataResponse { + static async getServerMetadata(): Promise { return { os_version: osVersion, server_version: app.getVersion(), private_api: Server().repo.getConfig("enable_private_api") as boolean, proxy_service: Server().repo.getConfig("proxy_service") as string, - helper_connected: !!Server().privateApiHelper?.helper + helper_connected: !!Server().privateApiHelper?.helper, + detected_icloud: await FileSystem.getIcloudAccount() }; } diff --git a/packages/server/src/server/fileSystem/index.ts b/packages/server/src/server/fileSystem/index.ts index 3c301b03..ffd70af9 100644 --- a/packages/server/src/server/fileSystem/index.ts +++ b/packages/server/src/server/fileSystem/index.ts @@ -522,4 +522,24 @@ export class FileSystem { return region; } + + static async getIcloudAccount(): Promise { + let account = null; + + try { + // Try to get the language (i.e. en_US) + const output = await FileSystem.execShellCommand( + `/usr/libexec/PlistBuddy -c "print :Accounts:0:AccountID" ~/Library/Preferences/MobileMeAccounts.plist` + ); + + // If we get a result back, pull the region out of it + if (isNotEmpty(output) && output.includes("@")) { + account = output.trim(); + } + } catch (ex) { + // Don't do anything if it fails, we'll just default to US + } + + return account; + } } diff --git a/packages/server/src/server/services/httpService/api/v1/routers/serverRouter.ts b/packages/server/src/server/services/httpService/api/v1/routers/serverRouter.ts index 84c9017c..6046b152 100644 --- a/packages/server/src/server/services/httpService/api/v1/routers/serverRouter.ts +++ b/packages/server/src/server/services/httpService/api/v1/routers/serverRouter.ts @@ -8,7 +8,7 @@ import { Success } from "../responses/success"; export class ServerRouter { static async getInfo(ctx: RouterContext, _: Next) { - return new Success(ctx, { data: GeneralInterface.getServerMetadata() }).send(); + return new Success(ctx, { data: await GeneralInterface.getServerMetadata() }).send(); } static async checkForUpdate(ctx: RouterContext, _: Next) { diff --git a/packages/server/src/server/services/httpService/api/v1/socketRoutes.ts b/packages/server/src/server/services/httpService/api/v1/socketRoutes.ts index 984c53ee..1cf0d5ad 100644 --- a/packages/server/src/server/services/httpService/api/v1/socketRoutes.ts +++ b/packages/server/src/server/services/httpService/api/v1/socketRoutes.ts @@ -76,15 +76,8 @@ export class SocketRoutes { /** * Return information about the server */ - socket.on("get-server-metadata", (_, cb): void => { - const meta: ServerMetadataResponse = { - os_version: osVersion, - server_version: app.getVersion(), - private_api: Server().repo.getConfig("enable_private_api") as boolean, - proxy_service: Server().repo.getConfig("proxy_service") as string, - helper_connected: !!Server().privateApiHelper?.helper - }; - + socket.on("get-server-metadata", async (_, cb): Promise => { + const meta: ServerMetadataResponse = await GeneralInterface.getServerMetadata(); return response(cb, "server-metadata", createSuccessResponse(meta, "Successfully fetched metadata")); }); @@ -589,16 +582,19 @@ export class SocketRoutes { Server().httpService.sendCache.remove(tempGuid); if ((sentMessage.error ?? 0) !== 0) { - return response(cb, "message-send-error", createServerErrorResponse( - 'Message failed to send!', - ErrorTypes.IMESSAGE_ERROR, - 'Message sent with an error. See attached message', - await getMessageResponse(sentMessage)) + return response( + cb, + "message-send-error", + createServerErrorResponse( + "Message failed to send!", + ErrorTypes.IMESSAGE_ERROR, + "Message sent with an error. See attached message", + await getMessageResponse(sentMessage) + ) ); } else { return response(cb, "message-sent", createSuccessResponse(await getMessageResponse(sentMessage))); } - } catch (ex: any) { Server().httpService.sendCache.remove(tempGuid); if (ex?.ROWID) { diff --git a/packages/server/src/server/types.ts b/packages/server/src/server/types.ts index 117929a9..52a4a689 100644 --- a/packages/server/src/server/types.ts +++ b/packages/server/src/server/types.ts @@ -6,6 +6,7 @@ export type ServerMetadataResponse = { private_api: boolean; helper_connected: boolean; proxy_service: string; + detected_icloud: string; }; /**