How to use the netlify-cms-lib-util.localForage.getItem 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 / backend.ts View on Github external
async getLocalDraftBackup(collection: Collection, slug: string) {
    const key = getEntryBackupKey(collection.get('name'), slug);
    const backup = await localForage.getItem(key);
    if (!backup || !backup.raw.trim()) {
      return {};
    }
    const { raw, path } = backup;
    let { mediaFiles = [] } = backup;

    mediaFiles = mediaFiles.map(file => {
      // de-serialize the file object
      if (file.file) {
        return { ...file, url: URL.createObjectURL(file.file) };
      }
      return file;
    });

    const label = selectFileEntryLabel(collection, slug);
    const entry: EntryValue = this.entryWithFormat(collection)(
github netlify / netlify-cms / packages / netlify-cms-backend-github / src / API.js View on Github external
retrieveMetadata(key) {
    const cache = localForage.getItem(`gh.meta.${key}`);
    return cache.then(cached => {
      if (cached && cached.expires > Date.now()) {
        return cached.data;
      }
      console.log(
        '%c Checking for MetaData files',
        'line-height: 30px;text-align: center;font-weight: bold',
      );
      return this.request(`${this.repoURL}/contents/${key}.json`, {
        params: { ref: 'refs/meta/_netlify_cms' },
        headers: { Accept: 'application/vnd.github.VERSION.raw' },
        cache: 'no-store',
      })
        .then(response => JSON.parse(response))
        .catch(() =>
          console.log(
github netlify / netlify-cms / packages / netlify-cms-backend-github / src / API.ts View on Github external
getBlob({ sha, repoURL = this.repoURL, parseText = true }: BlobArgs) {
    const key = parseText ? `gh.${sha}` : `gh.${sha}.blob`;
    return localForage.getItem(key).then(cached => {
      if (cached) {
        return cached;
      }

      return this.fetchBlobContent({ sha, repoURL, parseText }).then(result => {
        localForage.setItem(key, result);
        return result;
      });
    });
  }
github netlify / netlify-cms / packages / netlify-cms-backend-github / src / API.js View on Github external
getBlob(sha) {
    return localForage.getItem(`gh.${sha}`).then(cached => {
      if (cached) {
        return cached;
      }

      return this.request(`${this.repoURL}/git/blobs/${sha}`, {
        headers: { Accept: 'application/vnd.github.VERSION.raw' },
      }).then(result => {
        localForage.setItem(`gh.${sha}`, result);
        return result;
      });
    });
  }