How to use the netlify-cms-lib-util.getBlobSHA function in netlify-cms-lib-util

To help you get started, we’ve selected a few netlify-cms-lib-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github netlify / netlify-cms / packages / netlify-cms-core / src / actions / mediaLibrary.ts View on Github external
} else {
        const entry = state.entryDraft.get('entry');
        const entryPath = entry?.get('path');
        const collection = state.collections.get(entry?.get('collection'));
        const path = selectMediaFilePath(state.config, collection, entryPath, file.name);
        assetProxy = createAssetProxy({
          file,
          path,
        });
      }

      dispatch(addAsset(assetProxy));

      let mediaFile: MediaFile;
      if (integration) {
        const id = await getBlobSHA(file);
        // integration assets are persisted immediately, thus draft is false
        mediaFile = createMediaFileFromAsset({ id, file, assetProxy, draft: false });
      } else if (editingDraft) {
        const id = await getBlobSHA(file);
        mediaFile = createMediaFileFromAsset({ id, file, assetProxy, draft: editingDraft });
        return dispatch(addDraftEntryMediaFile(mediaFile));
      } else {
        mediaFile = await backend.persistMedia(state.config, assetProxy);
      }

      return dispatch(mediaPersisted(mediaFile, { privateUpload }));
    } catch (error) {
      console.error(error);
      dispatch(
        notifSend({
          message: `Failed to persist media: ${error}`,
github netlify / netlify-cms / packages / netlify-cms-backend-bitbucket / src / implementation.js View on Github external
async persistMedia(mediaFile, options = {}) {
    const { fileObj } = mediaFile;

    const [sha] = await Promise.all([
      getBlobSHA(fileObj),
      this.api.persistFiles([mediaFile], options),
    ]);

    const url = URL.createObjectURL(fileObj);

    return {
      displayURL: url,
      path: trimStart(mediaFile.path, '/k'),
      name: fileObj.name,
      size: fileObj.size,
      id: sha,
      file: fileObj,
      url,
    };
  }
github netlify / netlify-cms / packages / netlify-cms-backend-git-gateway / src / implementation.js View on Github external
async getPointerFileForMediaFileObj(fileObj) {
    const client = await this.getLargeMediaClient();
    const { name, size } = fileObj;
    const sha = await getBlobSHA(fileObj);
    await client.uploadResource({ sha, size }, fileObj);
    const pointerFileString = createPointerFile({ sha, size });
    const pointerFileBlob = new Blob([pointerFileString]);
    const pointerFile = new File([pointerFileBlob], name, { type: 'text/plain' });
    const pointerFileSHA = await getBlobSHA(pointerFile);
    return {
      file: pointerFile,
      blob: pointerFileBlob,
      sha: pointerFileSHA,
      raw: pointerFileString,
    };
  }
github netlify / netlify-cms / packages / netlify-cms-backend-git-gateway / src / implementation.js View on Github external
async getPointerFileForMediaFileObj(fileObj) {
    const client = await this.getLargeMediaClient();
    const { name, size } = fileObj;
    const sha = await getBlobSHA(fileObj);
    await client.uploadResource({ sha, size }, fileObj);
    const pointerFileString = createPointerFile({ sha, size });
    const pointerFileBlob = new Blob([pointerFileString]);
    const pointerFile = new File([pointerFileBlob], name, { type: 'text/plain' });
    const pointerFileSHA = await getBlobSHA(pointerFile);
    return {
      file: pointerFile,
      blob: pointerFileBlob,
      sha: pointerFileSHA,
      raw: pointerFileString,
    };
  }