云功能急剧的软件包部署错误

时间:2019-12-06 15:01:04

标签: node.js typescript firebase google-cloud-functions sharp

我正在使用Sharp相机通过云功能转换图像。 Visual Studio代码,打字稿。

我将其导入为:

import * as sharp from 'sharp';

我这样使用它:

     export const generateThumbs = functions.storage
  .object()
  .onFinalize(async object => {
    const bucket = gcs.bucket(object.bucket);
    const filePath = object.name;
    const fileName = filePath.split('/').pop();
    const bucketDir = dirname(filePath);

    const workingDir = join(tmpdir(), 'thumbs');
    const tmpFilePath = join(workingDir, 'source.png');

    if (fileName.includes('thumb@') || !object.contentType.includes('image')) {
      console.log('exiting function');
      return false;
    }

    // 1. Ensure thumbnail dir exists
    await fs.ensureDir(workingDir);

    // 2. Download Source File
    await bucket.file(filePath).download({
      destination: tmpFilePath
    });

    // 3. Resize the images and define an array of upload promises
    const sizes = [64, 128, 256];

    const uploadPromises = sizes.map(async size => {
      const thumbName = `thumb@${size}_${fileName}`;
      const thumbPath = join(workingDir, thumbName);

      // Resize source image
      await sharp(tmpFilePath)
        .resize(size, size)
        .toFile(thumbPath);

      // Upload to GCS
      return bucket.upload(thumbPath, {
        destination: join(bucketDir, thumbName)
      });
    });

    // 4. Run the upload operations
    await Promise.all(uploadPromises);

    // 5. Cleanup remove the tmp/thumbs from the filesystem
    return fs.remove(workingDir);
  });

(fireship.io中的代码)

这是我的package.json文件

"dependencies": {
    "@firebase/app": "^0.4.22",
    "@firebase/app-types": "^0.4.7",
    "@google-cloud/storage": "^4.1.0",
    "@sendgrid/client": "^6.4.0",
    "@sendgrid/contact-importer": "^6.4.0",
    "@sendgrid/mail": "^6.4.0",
    "@std/esm": "^0.26.0",
    "@types/algoliasearch": "^3.34.5",
    "@types/react": "^16.9.11",
    "@types/react-dom": "^16.9.3",
    "algolia-firebase-functions": "^3.2.0",
    "algoliasearch": "^3.35.1",
    "async.ensureasync": "^0.5.2",
    "async.queue": "^0.5.2",
    "bottleneck": "^2.19.5",
    "debug": "^4.1.1",
    "express": "^4.17.1",
    "firebase": "^7.2.3",
    "firebase-admin": "^8.7.0",
    "firebase-functions": "^3.3.0",
    "flag": "^4.4.0",
    "fs-extra": "^8.1.0",
    "geofirex": "0.0.6",
    "images-downloader": "^1.0.3",
    "lodash.chunk": "^4.2.0",
    "react-redux": "^7.1.1",
    "request": "^2.88.0",
    "rxfire": "^3.8.8",
    "rxjs": "^6.5.3",
    "sharp": "^0.23.2",
    "tmp": "^0.1.0"
  },

由于我使用了Sharp软件包,因此我在运行时收到以下消息:firebase deploy --only functions:myFunctionName

There was an unknown problem while trying to parse function triggers. Please ensure you are using Node.js v6 or greater.

我正在使用节点12.3.1

感谢您的帮助!

0 个答案:

没有答案
相关问题