fix(core): update
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import * as plugins from './smartdrive.plugins'
|
||||
import * as plugins from './smartdrive.plugins';
|
||||
|
||||
export * from './smartdrive.classes.localdrivelist'
|
||||
export * from './smartdrive.interfaces'
|
||||
export * from './smartdrive.classes.localdrivelist';
|
||||
export * from './smartdrive.interfaces';
|
||||
|
11
ts/smartdrive.classes.drivelistresult.ts
Normal file
11
ts/smartdrive.classes.drivelistresult.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import * as plugins from './smartdrive.plugins';
|
||||
import * as interfaces from './smartdrive.interfaces';
|
||||
|
||||
export class DriveListResult {
|
||||
result: interfaces.IDrive;
|
||||
|
||||
/**
|
||||
* tries to determine the best mounting candidate from a physical drive
|
||||
*/
|
||||
public getBestMountCandidate() {}
|
||||
}
|
@ -1,20 +1,36 @@
|
||||
import * as plugins from './smartdrive.plugins'
|
||||
import { IDrive } from './smartdrive.interfaces'
|
||||
import * as plugins from './smartdrive.plugins';
|
||||
import * as paths from './smartdrive.paths';
|
||||
import * as interfaces from './smartdrive.interfaces';
|
||||
|
||||
let promisifiedDrivelist = plugins.smartq.promisify(plugins.drivelist.list)
|
||||
export class SmartDrive {
|
||||
private smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash'
|
||||
});
|
||||
|
||||
export class LocalDriveList {
|
||||
private _list: IDrive[] = null
|
||||
public async getLocalDriveList(): Promise<interfaces.IDrive[]> {
|
||||
const list = await plugins.drivelist.list();
|
||||
const lsblkExecResult = await this.smartshellInstance.execSilent(`lsblk --json --bytes`);
|
||||
const lsblkJson: interfaces.ILsBlkJson = JSON.parse(lsblkExecResult.stdout);
|
||||
console.log(lsblkJson);
|
||||
const extendedList: interfaces.IDrive[] = list.map(driveItemArg => {
|
||||
const deviceName = driveItemArg.device.replace('/dev/', '');
|
||||
const blockDeviceLsBlk = lsblkJson.blockdevices.find((deviceArg) => {
|
||||
return deviceArg.name === deviceName;
|
||||
})
|
||||
const result: interfaces.IDrive = {
|
||||
...driveItemArg,
|
||||
children: blockDeviceLsBlk.children,
|
||||
}
|
||||
return result;
|
||||
});
|
||||
return extendedList;
|
||||
};
|
||||
|
||||
async getList (): Promise<IDrive[]> {
|
||||
if (!this._list) {
|
||||
this._list = await promisifiedDrivelist()
|
||||
}
|
||||
return this._list
|
||||
}
|
||||
|
||||
async getUpdatedList (): Promise<IDrive[]> {
|
||||
this._list = null
|
||||
return await this.getList()
|
||||
/**
|
||||
* tries to mount a device to the corresponding name in /mnt/smartdrive/${devicename}
|
||||
* @param devNameArg
|
||||
*/
|
||||
public async mountDeviceByName(devNameArg: string) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,30 @@
|
||||
import * as plugins from './smartdrive.plugins'
|
||||
import * as plugins from './smartdrive.plugins';
|
||||
|
||||
export interface IDrive {
|
||||
device: string
|
||||
description: string
|
||||
size: number,
|
||||
mountpoints: IMountpoint[]
|
||||
raw: string
|
||||
protected: boolean
|
||||
system: boolean
|
||||
export interface ILsBlkJson {
|
||||
blockdevices: {
|
||||
name: string;
|
||||
'maj:min': string;
|
||||
rm: boolean;
|
||||
size: number;
|
||||
ro: boolean;
|
||||
type: 'disk' | 'part';
|
||||
mountpoint: null;
|
||||
children: {
|
||||
name: string;
|
||||
'maj:min': string;
|
||||
rm: boolean;
|
||||
size: string;
|
||||
ro: boolean;
|
||||
type: 'disk' | 'part';
|
||||
mountpoint: string;
|
||||
}[];
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface IDrive extends plugins.drivelist.Drive {
|
||||
children: ILsBlkJson['blockdevices'][0]['children'];
|
||||
}
|
||||
|
||||
export interface IMountpoint {
|
||||
path: string
|
||||
path: string;
|
||||
}
|
||||
|
3
ts/smartdrive.paths.ts
Normal file
3
ts/smartdrive.paths.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import * as plugins from './smartdrive.plugins';
|
||||
|
||||
export const baseMountPoint = `/dev/smartdrive`
|
@ -1,8 +1,6 @@
|
||||
import 'typings-global'
|
||||
import * as drivelist from 'drivelist'
|
||||
import * as smartq from 'smartq'
|
||||
import * as drivelist from 'drivelist';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartshell from '@pushrocks/smartshell';
|
||||
|
||||
export {
|
||||
drivelist,
|
||||
smartq
|
||||
}
|
||||
export { drivelist, smartfile, smartpromise, smartshell };
|
||||
|
Reference in New Issue
Block a user