Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)(
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(
retrieveMetadata(key: string): Promise
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;
});
});
}
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;
});
});
}