Skip to content

Commit

Permalink
Merge pull request #193 from magestrio/bug/browser_cache
Browse files Browse the repository at this point in the history
Cache for browser is not supported
  • Loading branch information
SangTran-127 authored Oct 14, 2024
2 parents 2ef3a41 + 5e91f87 commit 492245b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/smart-contract/src/cache/cache-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Cache } from 'o1js';
import { CacheType } from '@types';
import { join } from 'path';
import { downloadCache } from './cache-downloader';
import { isNode } from '../helper/environment';

export const DOWNLOADS = 'downloads';

Expand All @@ -10,12 +11,16 @@ export class CacheManager {
type: CacheType,
merkleHeight: number
): Promise<Cache> {
// TODO: Check cache to avoid redownloaded
const identifier = join(type, merkleHeight.toString());
await downloadCache(DOWNLOADS, identifier);
if (isNode()) {
// TODO: Check cache to avoid redownloaded
const identifier = join(type, merkleHeight.toString());
await downloadCache(DOWNLOADS, identifier);

const cachePath = join(DOWNLOADS, identifier);
const cachePath = join(DOWNLOADS, identifier);

return Cache.FileSystem(cachePath);
return Cache.FileSystem(cachePath);
} else {
return Cache.None;
}
}
}
7 changes: 7 additions & 0 deletions packages/smart-contract/src/helper/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function isNode(): boolean {
return (
typeof process !== 'undefined' &&
process.versions != null &&
process.versions.node != null
);
}

0 comments on commit 492245b

Please sign in to comment.