Socket
Socket
Sign inDemoInstall

@flownet/lib-upload-files-to-gcs

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flownet/lib-upload-files-to-gcs - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

readme.md

104

dist/cli/esm/index.js

@@ -51,71 +51,71 @@ #!/usr/bin/env node

var Node = async ({
projectId,
keyFilename,
bucketName,
dir,
pattern,
destDir = "/",
dryRun = false,
metadata = {},
domain,
verbose = false
projectId,
keyFilename,
bucketName,
dir,
pattern,
destDir = "/",
dryRun = false,
metadata = {},
domain,
verbose = false
}) => {
if (!projectId) throw new Error('projectId is required.');
if (!projectId) throw new Error('projectId is required.');
if (!keyFilename) throw new Error('keyFilename is required.');
if (!keyFilename) throw new Error('keyFilename is required.');
if (!bucketName) throw new Error('bucketName is required.');
if (!bucketName) throw new Error('bucketName is required.');
if (!pattern) throw new Error('pattern is required.');
const storage = new Storage({
projectId,
keyFilename
});
if (!pattern) throw new Error('pattern is required.');
const bucket = storage.bucket(bucketName);
const storage = new Storage({
projectId,
keyFilename
});
// source files
dir = dir || process.cwd();
const bucket = storage.bucket(bucketName);
const files = await listFiles({ pattern, dir, nodir: true });
// source files
dir = dir || process.cwd();
destDir = destDir || "/";
const files = await listFiles({ pattern, dir, nodir: true });
const uploadedFiles = [];
destDir = destDir || "/";
for await (const file of files) {
const uploadedFiles = [];
const srcFile = path.resolve(dir, file);
const destFile = path.join(destDir, file);
for await (const file of files) {
let defaultUrl = `https://${bucketName}.storage.googleapis.com/${destFile}`;
if (domain) defaultUrl = `https://${domain}/${destFile}`;
const srcFile = path.resolve(dir, file);
const destFile = path.join(destDir, file);
const uploadedFile = { from: srcFile, to: destFile, url: defaultUrl };
uploadedFiles.push(uploadedFile);
let defaultUrl = `https://${bucketName}.storage.googleapis.com/${destFile}`;
if (domain) defaultUrl = `https://${domain}/${destFile}`;
const metadataFinal = {
"surrogate-key": "gcs",
contentType: mime.contentType(path.extname(file)) || 'application/octet-stream',
...metadata
};
const uploadedFile = { from: srcFile, to: destFile, url: defaultUrl };
uploadedFiles.push(uploadedFile);
dryRun = dryRun === true;
const metadataFinal = {
"surrogate-key": "gcs",
contentType: mime.contentType(path.extname(file)) || 'application/octet-stream',
...metadata
};
if (!dryRun) {
await bucket.upload(srcFile, {
destination: destFile,
gzip: true,
metadata:metadataFinal,
});
}
dryRun = (dryRun === true);
if (verbose) console.log(uploadedFile);
if (!dryRun) {
await bucket.upload(srcFile, {
destination: destFile,
gzip: true,
metadata: metadataFinal,
});
}
return {
files: uploadedFiles
};
if (verbose) console.log(uploadedFile);
}
return {
files: uploadedFiles
};
};

@@ -128,3 +128,7 @@

.then((result) => {
if (typeof result !== "undefined") console.log(result);
if (typeof result !== "undefined") {
if (argv.stdout_format === "json")
console.log(JSON.stringify(result, null, 2));
else console.log(result);
}
process.exit(0);

@@ -131,0 +135,0 @@ })

@@ -7,73 +7,73 @@ import { Storage } from '@google-cloud/storage';

var index = async ({
projectId,
keyFilename,
bucketName,
dir,
pattern,
destDir = "/",
dryRun = false,
metadata = {},
domain,
verbose = false
projectId,
keyFilename,
bucketName,
dir,
pattern,
destDir = "/",
dryRun = false,
metadata = {},
domain,
verbose = false
}) => {
if (!projectId) throw new Error('projectId is required.');
if (!projectId) throw new Error('projectId is required.');
if (!keyFilename) throw new Error('keyFilename is required.');
if (!keyFilename) throw new Error('keyFilename is required.');
if (!bucketName) throw new Error('bucketName is required.');
if (!bucketName) throw new Error('bucketName is required.');
if (!pattern) throw new Error('pattern is required.');
const storage = new Storage({
projectId,
keyFilename
});
if (!pattern) throw new Error('pattern is required.');
const bucket = storage.bucket(bucketName);
const storage = new Storage({
projectId,
keyFilename
});
// source files
dir = dir || process.cwd();
const bucket = storage.bucket(bucketName);
const files = await listFiles({ pattern, dir, nodir: true });
// source files
dir = dir || process.cwd();
destDir = destDir || "/";
const files = await listFiles({ pattern, dir, nodir: true });
const uploadedFiles = [];
destDir = destDir || "/";
for await (const file of files) {
const uploadedFiles = [];
const srcFile = path.resolve(dir, file);
const destFile = path.join(destDir, file);
for await (const file of files) {
let defaultUrl = `https://${bucketName}.storage.googleapis.com/${destFile}`;
if (domain) defaultUrl = `https://${domain}/${destFile}`;
const srcFile = path.resolve(dir, file);
const destFile = path.join(destDir, file);
const uploadedFile = { from: srcFile, to: destFile, url: defaultUrl };
uploadedFiles.push(uploadedFile);
let defaultUrl = `https://${bucketName}.storage.googleapis.com/${destFile}`;
if (domain) defaultUrl = `https://${domain}/${destFile}`;
const metadataFinal = {
"surrogate-key": "gcs",
contentType: mime.contentType(path.extname(file)) || 'application/octet-stream',
...metadata
};
const uploadedFile = { from: srcFile, to: destFile, url: defaultUrl };
uploadedFiles.push(uploadedFile);
dryRun = dryRun === true;
const metadataFinal = {
"surrogate-key": "gcs",
contentType: mime.contentType(path.extname(file)) || 'application/octet-stream',
...metadata
};
if (!dryRun) {
await bucket.upload(srcFile, {
destination: destFile,
gzip: true,
metadata:metadataFinal,
});
}
dryRun = (dryRun === true);
if (verbose) console.log(uploadedFile);
if (!dryRun) {
await bucket.upload(srcFile, {
destination: destFile,
gzip: true,
metadata: metadataFinal,
});
}
return {
files: uploadedFiles
};
if (verbose) console.log(uploadedFile);
}
return {
files: uploadedFiles
};
};
export { index as default };
{
"name": "@flownet/lib-upload-files-to-gcs",
"version": "0.3.2",
"version": "0.3.3",
"files": [

@@ -16,2 +16,6 @@ "dist/*"

},
"repository": {
"type": "git",
"url": "https://gitlab.com/fnetai/files-to-gcs.git"
},
"license": "MIT",

@@ -21,3 +25,2 @@ "dependencies": {

"@google-cloud/storage": "^7.7",
"chalk": "^4",
"mime-types": "^2.1",

@@ -28,3 +31,3 @@ "yargs": "^17"

"fnet-upload-files-to-gcs": "dist/cli/esm/index.js",
"lib-upload-files-to-gcs": "dist/cli/esm/index.js"
"files-to-gcs": "dist/cli/esm/index.js"
},

@@ -31,0 +34,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc