fix(core): update

This commit is contained in:
2021-12-03 16:39:50 +01:00
parent 770c5a2b67
commit b5bd1a7c9d
28 changed files with 28590 additions and 614 deletions

View File

@ -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';

View 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() {}
}

View File

@ -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) {
}
}

View File

@ -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
View File

@ -0,0 +1,3 @@
import * as plugins from './smartdrive.plugins';
export const baseMountPoint = `/dev/smartdrive`

View File

@ -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 };