Skip to content

Instantly share code, notes, and snippets.

@groupdocscloud
Last active January 12, 2020 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocscloud/d42190d60101442ccba939ac4db41454 to your computer and use it in GitHub Desktop.
Save groupdocscloud/d42190d60101442ccba939ac4db41454 to your computer and use it in GitHub Desktop.
"use strict";
class Editor_Node_Copy_File {
static Run() {
var request = new groupdocs_Editor_cloud_1.CopyFileRequest("Editordocs/one-page1.docx", "Editordocs/one-page-copied.docx", myStorage, myStorage);
fileApi.copyFile(request)
.then(function (response) {
console.log("Expected response type is Void: 'Editordocs/one-page1.docx' file copied as 'Editordocs/one-page-copied.docx'.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Copy_File;
"use strict";
class Editor_Node_Copy_Folder {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_Editor_cloud_1.CopyFolderRequest("Editordocs", "Editordocs1", myStorage, myStorage);
folderApi.copyFolder(request)
.then(function () {
console.log("Expected response type is Void: 'Editordocs' folder copied as 'Editordocs1'.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Copy_Folder;
"use strict";
class Editor_Node_Create_Folder {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_Editor_cloud_1.CreateFolderRequest("Editordocs", myStorage);
folderApi.createFolder(request)
.then(function () {
console.log("Expected response type is Void: 'Editordocs' folder created.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Create_Folder;
"use strict";
class Editor_Node_Delete_File {
static Run() {
var request = new groupdocs_Editor_cloud_1.DeleteFileRequest("Editordocs1/one-page1.docx", myStorage);
fileApi.deleteFile(request)
.then(function (response) {
console.log("Expected response type is Void: 'Editordocs1/one-page1.docx' deleted.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Delete_File;
"use strict";
class Editor_Node_Delete_Folder {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_Editor_cloud_1.DeleteFolderRequest("Editordocs/Editordocs1", myStorage, true);
folderApi.deleteFolder(request)
.then(function () {
console.log("Expected response type is Void: 'Editordocs/Editordocs1' folder deleted recursively.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Delete_Folder;
"use strict";
class Editor_Node_Download_File {
static Run() {
var request = new groupdocs_Editor_cloud_1.DownloadFileRequest("Editordocs/one-page.docx", myStorage);
fileApi.downloadFile(request)
.then(function (response) {
console.log("Expected response type is Stream: " + response.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Download_File;
"use strict";
class Editor_Node_Get_Disc_Usage {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_Editor_cloud_1.GetDiscUsageRequest(myStorage);
storageApi.getDiscUsage(request)
.then(function (response) {
console.log("Expected response type is DiscUsage: " + response.usedSize);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Get_Disc_Usage;
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-node-samples
global.editor_cloud = require("groupdocs-editor-cloud");
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.infoApi = editor_cloud.InfoApi.fromKeys(appSid, appKey);
let response = await infoApi.getSupportedFileFormats();
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-node-samples
global.editor_cloud = require("groupdocs-editor-cloud");
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.infoApi = editor_cloud.InfoApi.fromKeys(appSid, appKey);
let fileInfo = new editor_cloud.FileInfo();
fileInfo.filePath = "WordProcessing/password-protected.docx";
fileInfo.password = "password";
let request = new editor_cloud.GetInfoRequest(fileInfo);
let response = await infoApi.getInfo(request);
console.log("GetDocumentInfo: Page Count = " + response.pageCount);
"use strict";
class Editor_Node_Get_File_Versions {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_Editor_cloud_1.GetFileVersionsRequest("Editordocs/one-page.docx", myStorage);
storageApi.getFileVersions(request)
.then(function (response) {
console.log("Expected response type is FileVersions: " + response.value.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Get_File_Versions;
"use strict";
class Editor_Node_Get_Files_List {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_Editor_cloud_1.GetFilesListRequest("Editordocs/sample.docx", myStorage);
folderApi.getFilesList(request)
.then(function (response) {
console.log("Expected response type is FilesList: " + response.value.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Get_Files_List;
"use strict";
class Editor_Node_Move_File {
static Run() {
var request = new groupdocs_Editor_cloud_1.MoveFileRequest("Editordocs/one-page1.docx", "Editordocs1/one-page1.docx", myStorage, myStorage);
fileApi.moveFile(request)
.then(function (response) {
console.log("Expected response type is Void: 'Editordocs/one-page1.docx' file moved to 'Editordocs1/one-page1.docx'.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Move_File;
"use strict";
class Editor_Node_Move_Folder {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_Editor_cloud_1.MoveFolderRequest("Editordocs1", "Editordocs/Editordocs1", myStorage, myStorage);
folderApi.moveFolder(request)
.then(function () {
console.log("Expected response type is Void: 'Editordocs1' folder moved to 'Editordocs/Editordocs1'.");
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Move_Folder;
"use strict";
class Editor_Node_Object_Exists {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_Editor_cloud_1.ObjectExistsRequest("Editordocs/one-page.docx", myStorage);
storageApi.objectExists(request)
.then(function (response) {
console.log("Expected response type is ObjectExist: " + response.exists);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Object_Exists;
"use strict";
class Editor_Node_Storage_Exist {
static Run() {
// retrieve supported file-formats
var request = new groupdocs_Editor_cloud_1.StorageExistsRequest(myStorage);
storageApi.storageExists(request)
.then(function (response) {
console.log("Expected response type is StorageExist: " + response.exists);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
}
}
module.exports = Editor_Node_Storage_Exist;
"use strict";
class Editor_Node_Upload_File {
static Run() {
// Open file in IOStream from local/disc.
var resourcesFolder = './Resources/Editordocs/one-page.docx';
fs.readFile(resourcesFolder, (err, fileStream) => {
var request = new groupdocs_Editor_cloud_1.UploadFileRequest("Editordocs/one-page1.docx", fileStream, myStorage);
fileApi.uploadFile(request)
.then(function (response) {
console.log("Expected response type is FilesUploadResult: " + response.uploaded.length);
})
.catch(function (error) {
console.log("Error: " + error.message);
});
});
}
}
module.exports = Editor_Node_Upload_File;
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-node-samples
global.editor_cloud = require("groupdocs-editor-cloud");
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.editApi = editor_cloud.EditApi.fromKeys(appSid, appKey);
global.fileApi = editor_cloud.FileApi.fromKeys(appSid, appKey);
// The document already uploaded into the storage.
// Load it into editable state
let fileInfo = new editor_cloud.FileInfo();
fileInfo.filePath = "Spreadsheet/sample.tsv";
let loadOptions = new editor_cloud.DelimitedTextLoadOptions();
loadOptions.fileInfo = fileInfo;
loadOptions.outputPath = "output";
let loadResult = await editApi.load(new editor_cloud.LoadRequest(loadOptions));
// Download html document
let buf = await fileApi.downloadFile(new editor_cloud.DownloadFileRequest(loadResult.htmlPath));
let htmlString = buf.toString("utf-8");
// Edit something...
htmlString = htmlString.replace("32", "66");
// Upload html back to storage
await fileApi.uploadFile(new editor_cloud.UploadFileRequest(loadResult.htmlPath, new Buffer(htmlString, "utf-8")));
// Save html back to docx
let saveOptions = new editor_cloud.DelimitedTextSaveOptions();
saveOptions.fileInfo = fileInfo;
saveOptions.outputPath = "output/edited.tsv";
saveOptions.htmlPath = loadResult.htmlPath;
saveOptions.resourcesPath = loadResult.resourcesPath;
let saveResult = await editApi.save(new editor_cloud.SaveRequest(saveOptions));
// Done.
console.log("Document edited: " + saveResult.path);
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-node-samples
global.editor_cloud = require("groupdocs-editor-cloud");
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.editApi = editor_cloud.EditApi.fromKeys(appSid, appKey);
global.fileApi = editor_cloud.FileApi.fromKeys(appSid, appKey);
// The document already uploaded into the storage.
// Load it into editable state
let fileInfo = new editor_cloud.FileInfo();
fileInfo.filePath = "Presentation/with-notes.pptx";
let loadOptions = new editor_cloud.PresentationLoadOptions();
loadOptions.fileInfo = fileInfo;
loadOptions.outputPath = "output";
let loadResult = await editApi.load(new editor_cloud.LoadRequest(loadOptions));
// Download html document
let buf = await fileApi.downloadFile(new editor_cloud.DownloadFileRequest(loadResult.htmlPath));
let htmlString = buf.toString("utf-8");
// Edit something...
htmlString = htmlString.replace("Slide sub-heading", "Hello world!");
// Upload html back to storage
await fileApi.uploadFile(new editor_cloud.UploadFileRequest(loadResult.htmlPath, new Buffer(htmlString, "utf-8")));
// Save html back to docx
let saveOptions = new editor_cloud.PresentationSaveOptions();
saveOptions.fileInfo = fileInfo;
saveOptions.outputPath = "output/edited.pptx";
saveOptions.htmlPath = loadResult.htmlPath;
saveOptions.resourcesPath = loadResult.resourcesPath;
let saveResult = await editApi.save(new editor_cloud.SaveRequest(saveOptions));
// Done.
console.log("Document edited: " + saveResult.path);
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-node-samples
global.editor_cloud = require("groupdocs-editor-cloud");
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.editApi = editor_cloud.EditApi.fromKeys(appSid, appKey);
global.fileApi = editor_cloud.FileApi.fromKeys(appSid, appKey);
// The document already uploaded into the storage.
// Load it into editable state
let fileInfo = new editor_cloud.FileInfo();
fileInfo.filePath = "Spreadsheet/four-sheets.xlsx";
let loadOptions = new editor_cloud.SpreadsheetLoadOptions();
loadOptions.fileInfo = fileInfo;
loadOptions.outputPath = "output";
loadOptions.worksheetIndex = 0;
let loadResult = await editApi.load(new editor_cloud.LoadRequest(loadOptions));
// Download html document
let buf = await fileApi.downloadFile(new editor_cloud.DownloadFileRequest(loadResult.htmlPath));
let htmlString = buf.toString("utf-8");
// Edit something...
htmlString = htmlString.replace("This is sample sheet", "This is sample sheep");
// Upload html back to storage
await fileApi.uploadFile(new editor_cloud.UploadFileRequest(loadResult.htmlPath, new Buffer(htmlString, "utf-8")));
// Save html back to docx
let saveOptions = new editor_cloud.SpreadsheetSaveOptions();
saveOptions.fileInfo = fileInfo;
saveOptions.outputPath = "output/edited.xlsx";
saveOptions.htmlPath = loadResult.htmlPath;
saveOptions.resourcesPath = loadResult.resourcesPath;
let saveResult = await editApi.save(new editor_cloud.SaveRequest(saveOptions));
// Done.
console.log("Document edited: " + saveResult.path);
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-node-samples
global.editor_cloud = require("groupdocs-editor-cloud");
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.editApi = editor_cloud.EditApi.fromKeys(appSid, appKey);
global.fileApi = editor_cloud.FileApi.fromKeys(appSid, appKey);
// The document already uploaded into the storage.
// Load it into editable state
let fileInfo = new editor_cloud.FileInfo();
fileInfo.filePath = "Text/document.txt";
let loadOptions = new editor_cloud.TextLoadOptions();
loadOptions.fileInfo = fileInfo;
loadOptions.outputPath = "output";
let loadResult = await editApi.load(new editor_cloud.LoadRequest(loadOptions));
// Download html document
let buf = await fileApi.downloadFile(new editor_cloud.DownloadFileRequest(loadResult.htmlPath));
let htmlString = buf.toString("utf-8");
// Edit something...
htmlString = htmlString.replace("Page Text", "New Text");
// Upload html back to storage
await fileApi.uploadFile(new editor_cloud.UploadFileRequest(loadResult.htmlPath, new Buffer(htmlString, "utf-8")));
// Save html back to docx
let saveOptions = new editor_cloud.TextSaveOptions();
saveOptions.fileInfo = fileInfo;
saveOptions.outputPath = "output/edited.txt";
saveOptions.htmlPath = loadResult.htmlPath;
saveOptions.resourcesPath = loadResult.resourcesPath;
let saveResult = await editApi.save(new editor_cloud.SaveRequest(saveOptions));
// Done.
console.log("Document edited: " + saveResult.path);
// For complete examples and data files, please go to https://github.com/groupdocs-editor-cloud/groupdocs-editor-cloud-node-samples
global.editor_cloud = require("groupdocs-editor-cloud");
global.appSid = "XXXX-XXXX-XXXX-XXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.appKey = "XXXXXXXXXXXXXXXX"; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud
global.editApi = editor_cloud.EditApi.fromKeys(appSid, appKey);
global.fileApi = editor_cloud.FileApi.fromKeys(appSid, appKey);
// The document already uploaded into the storage.
// Load it into editable state
let fileInfo = new editor_cloud.FileInfo();
fileInfo.filePath = "WordProcessing/password-protected.docx";
fileInfo.password = "password";
let loadOptions = new editor_cloud.WordProcessingLoadOptions();
loadOptions.fileInfo = fileInfo;
loadOptions.outputPath = "output";
let loadResult = await editApi.load(new editor_cloud.LoadRequest(loadOptions));
// Download html document
let buf = await fileApi.downloadFile(new editor_cloud.DownloadFileRequest(loadResult.htmlPath));
let htmlString = buf.toString("utf-8");
// Edit something...
htmlString = htmlString.replace("Sample test text", "Hello world");
// Upload html back to storage
await fileApi.uploadFile(new editor_cloud.UploadFileRequest(loadResult.htmlPath, new Buffer(htmlString, "utf-8")));
// Save html back to docx
let saveOptions = new editor_cloud.WordProcessingSaveOptions();
saveOptions.fileInfo = fileInfo;
saveOptions.outputPath = "output/edited.docx";
saveOptions.htmlPath = loadResult.htmlPath;
saveOptions.resourcesPath = loadResult.resourcesPath;
let saveResult = await editApi.save(new editor_cloud.SaveRequest(saveOptions));
// Done.
console.log("Document edited: " + saveResult.path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment