Skip to content

Commit

Permalink
Adds detected_icloud to server metadata request
Browse files Browse the repository at this point in the history
  • Loading branch information
zlshames committed Apr 17, 2022
1 parent 2a2322a commit e1b6d31
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { FileSystem } from "@server/fileSystem";
const osVersion = macosVersion();

export class GeneralInterface {
static getServerMetadata(): ServerMetadataResponse {
static async getServerMetadata(): Promise<ServerMetadataResponse> {
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()
};
}

Expand Down
20 changes: 20 additions & 0 deletions packages/server/src/server/fileSystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,24 @@ export class FileSystem {

return region;
}

static async getIcloudAccount(): Promise<string> {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
const meta: ServerMetadataResponse = await GeneralInterface.getServerMetadata();
return response(cb, "server-metadata", createSuccessResponse(meta, "Successfully fetched metadata"));
});

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type ServerMetadataResponse = {
private_api: boolean;
helper_connected: boolean;
proxy_service: string;
detected_icloud: string;
};

/**
Expand Down

0 comments on commit e1b6d31

Please sign in to comment.