Skip to content

Commit

Permalink
rename added
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshrvel committed Feb 10, 2019
1 parent 7dbd4cc commit 3063a8c
Showing 1 changed file with 44 additions and 11 deletions.
55 changes: 44 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class MTP {
return this.device;
}

getStorageDevices() {
listStorageDevices() {
if (this.device === null) {
return Promise.resolve(null);
}
Expand All @@ -132,6 +132,10 @@ class MTP {
}
}

setStorageDevices() {

}

releaseDevice() {
if (this.device === null) {
return Promise.resolve(null);
Expand Down Expand Up @@ -171,6 +175,22 @@ class MTP {
return Promise.resolve(this.mtpHelper.Destroy_file(this.device, fileId));
}

renameFile({ fileId, currentFileName, newfileName, storageId, parentId }) {
if (this.device === null) {
return Promise.resolve(null);
}

const file = new this.mtpHelper.file_t();
file.id = fileId;
file.type = this.mtpHelper.FILETYPE_UNKNOWN;
file.parentId = parentId;
file.storageId = storageId;

return Promise.resolve(
this.mtpHelper.Set_File_Name(this.device, file, newfileName)
);
}

createFolder({ folderPath, parentId, storageId }) {
if (this.device === null) {
return Promise.resolve(null);
Expand Down Expand Up @@ -407,6 +427,8 @@ class MTP {
size: item.size
});
}

return Promise.resolve(true);
}
}

Expand All @@ -417,7 +439,7 @@ mtpObj.init();
async function run(resetmtp = false, searchDir = null) {
const detectedDevices = await mtpObj.detectMtp();
//todo: handle error here
const getStorageDevices = await mtpObj.getStorageDevices();
const listStorageDevices = await mtpObj.listStorageDevices();
//todo: handle error here

if (resetmtp) {
Expand All @@ -438,41 +460,52 @@ async function run(resetmtp = false, searchDir = null) {

const parentPath = '/aak';

/*
const listMtpFileTree = await mtpObj.listMtpFileTree({
storageId: storageId, //todo: change
folderId: 49,
recursive: true,
parentPath: parentPath
});
*/

// console.log(listMtpFileTree);
//todo: handle error here

//mtpObj.deleteFile({ fileId: 46 });
//todo: handle error here

console.log(
/* console.log(
await mtpObj.downloadFileTree({
nodes: listMtpFileTree,
destinationFilePath: `/Users/ganeshr/Desktop/2`
})
);
);*/
//todo: handle error here

/* const listLocalFileTree = await mtpObj.listLocalFileTree({
/* const listLocalFileTree = await mtpObj.listLocalFileTree({
folderPath: '/Users/ganeshr/Desktop/2',
recursive: true
});*/
});
/* await mtpObj.uploadFileTree({
nodes: listLocalFileTree,
parentId: 49,
storageId: storageId //todo: change
});*/
console.log(
await mtpObj.uploadFileTree({
nodes: listLocalFileTree,
parentId: 49,
storageId: storageId //todo: change
})
);*/
//todo: handle error here

// console.log(mtpObj.pathToId('/WhatsApp'));

mtpObj.renameFile({
fileId: 11212345,
newfileName: 'test__',
parentId: mtpHelper.FILES_AND_FOLDERS_ROOT,
storageId: storageId
});

const releaseDevice = await mtpObj.releaseDevice();
}

Expand Down

0 comments on commit 3063a8c

Please sign in to comment.