Files
api/packages/unraid-api-plugin-connect/src/connection-status/cloud.resolver.ts
Pujit Mehrotra 0d443de20e refactor(connect): organize src by concern instead of artifact (#1457)
Reorganizes files, but keeps logic (and Nest dependency relationships)
unchanged.

* **Documentation**
  * Update README to reflect the new directory structure.

* **Refactor**
* Update import paths to match the new feature-based directory
structure.
* Rename `SystemModule` to `NetworkModule` for smaller scope and
increased clarity.
  * Reorganize source code into directories of feature-related concerns.
 
* **Chores**
* Delete unused demo configuration and related code for a cleaner
codebase.

* **Other**
  * No functional changes to end-user features or behaviors.
2025-07-03 09:47:31 -04:00

56 lines
1.7 KiB
TypeScript

import { Query, Resolver } from '@nestjs/graphql';
import { Resource } from '@unraid/shared/graphql.model.js';
import {
AuthActionVerb,
AuthPossession,
UsePermissions,
} from '@unraid/shared/use-permissions.directive.js';
import { NetworkService } from '../network/network.service.js';
import { Cloud } from './cloud.model.js';
import { CloudService } from './cloud.service.js';
/**
* Exposes details about the connection to the Unraid Connect cloud.
*/
@Resolver(() => Cloud)
export class CloudResolver {
constructor(
private readonly cloudService: CloudService,
private readonly networkService: NetworkService
) {}
@Query(() => Cloud)
@UsePermissions({
action: AuthActionVerb.READ,
resource: Resource.CLOUD,
possession: AuthPossession.ANY,
})
public async cloud(): Promise<Cloud> {
const minigraphql = this.cloudService.checkMothershipClient();
const cloud = await this.cloudService.checkCloudConnection();
const cloudError = cloud.error ? `NETWORK: ${cloud.error}` : '';
const miniGraphError = minigraphql.error ? `CLOUD: ${minigraphql.error}` : '';
let error = cloudError || miniGraphError || undefined;
if (cloudError && miniGraphError) {
error = `${cloudError}\n${miniGraphError}`;
}
return {
relay: {
// Left in for UPC backwards compat.
error: undefined,
status: 'connected',
timeout: undefined,
},
apiKey: { valid: true },
minigraphql,
cloud,
allowedOrigins: this.networkService.getAllowedOrigins(),
error,
};
}
}