github.com/hernad/nomad@v1.6.112/ui/app/routes/allocations/allocation/task/fs.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import Route from '@ember/routing/route';
     7  import RSVP from 'rsvp';
     8  import notifyError from 'nomad-ui/utils/notify-error';
     9  
    10  export default class FsRoute extends Route {
    11    model({ path = '/' }) {
    12      const decodedPath = decodeURIComponent(path);
    13      const taskState = this.modelFor('allocations.allocation.task');
    14  
    15      if (!taskState || !taskState.allocation) return;
    16  
    17      const allocation = taskState.allocation;
    18      const pathWithTaskName = `${taskState.name}${
    19        decodedPath.startsWith('/') ? '' : '/'
    20      }${decodedPath}`;
    21  
    22      return RSVP.all([
    23        allocation.stat(pathWithTaskName),
    24        taskState.get('allocation.node'),
    25      ])
    26        .then(([statJson]) => {
    27          if (statJson.IsDir) {
    28            return RSVP.hash({
    29              path: decodedPath,
    30              taskState,
    31              directoryEntries: allocation
    32                .ls(pathWithTaskName)
    33                .catch(notifyError(this)),
    34              isFile: false,
    35            });
    36          } else {
    37            return {
    38              path: decodedPath,
    39              taskState,
    40              isFile: true,
    41              stat: statJson,
    42            };
    43          }
    44        })
    45        .catch(notifyError(this));
    46    }
    47  
    48    setupController(
    49      controller,
    50      { path, taskState, directoryEntries, isFile, stat } = {}
    51    ) {
    52      super.setupController(...arguments);
    53      controller.setProperties({
    54        path,
    55        taskState,
    56        directoryEntries,
    57        isFile,
    58        stat,
    59      });
    60    }
    61  }