n8n-nodes-base
Version:
Base nodes of n8n
104 lines • 3.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.description = void 0;
exports.execute = execute;
const utilities_1 = require("../../../../../../utils/utilities");
const utils_1 = require("../../helpers/utils");
const transport_1 = require("../../transport");
const common_descriptions_1 = require("../common.descriptions");
const properties = [
{
...common_descriptions_1.fileRLC,
description: 'The file to copy',
},
{
displayName: 'File Name',
name: 'name',
type: 'string',
default: '',
placeholder: 'e.g. My File',
description: 'The name of the new file. If not set, “Copy of {original file name}” will be used.',
},
{
displayName: 'Copy In The Same Folder',
name: 'sameFolder',
type: 'boolean',
default: true,
description: 'Whether to copy the file in the same folder as the original file',
},
{
...common_descriptions_1.driveRLC,
displayName: 'Parent Drive',
description: 'The drive where to save the copied file',
displayOptions: { show: { sameFolder: [false] } },
},
{
...common_descriptions_1.folderRLC,
displayName: 'Parent Folder',
description: 'The folder where to save the copied file',
displayOptions: { show: { sameFolder: [false] } },
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add option',
default: {},
options: [
{
displayName: 'Copy Requires Writer Permission',
name: 'copyRequiresWriterPermission',
type: 'boolean',
default: false,
description: 'Whether the options to copy, print, or download this file, should be disabled for readers and commenters',
},
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: 'A short description of the file',
},
],
},
];
const displayOptions = {
show: {
resource: ['file'],
operation: ['copy'],
},
};
exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, properties);
async function execute(i) {
const file = this.getNodeParameter('fileId', i);
const fileId = file.value;
const options = this.getNodeParameter('options', i, {});
let name = this.getNodeParameter('name', i);
name = name ? name : `Copy of ${file.cachedResultName}`;
const copyRequiresWriterPermission = options.copyRequiresWriterPermission || false;
const qs = {
includeItemsFromAllDrives: true,
supportsAllDrives: true,
spaces: 'appDataFolder, drive',
corpora: 'allDrives',
};
const parents = [];
const sameFolder = this.getNodeParameter('sameFolder', i);
if (!sameFolder) {
const driveId = this.getNodeParameter('driveId', i, undefined, {
extractValue: true,
});
const folderId = this.getNodeParameter('folderId', i, undefined, {
extractValue: true,
});
parents.push((0, utils_1.setParentFolder)(folderId, driveId));
}
const body = { copyRequiresWriterPermission, parents, name };
if (options.description) {
body.description = options.description;
}
const response = await transport_1.googleApiRequest.call(this, 'POST', `/drive/v3/files/${fileId}/copy`, body, qs);
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(response), { itemData: { item: i } });
return executionData;
}
//# sourceMappingURL=copy.operation.js.map