From cc9f774f92d72ac8921d86d78bb77847e1bc6569 Mon Sep 17 00:00:00 2001 From: Philippe Faist Date: Sun, 13 Aug 2023 00:12:05 +0200 Subject: [PATCH] preview tool updates --- previewtool/previewApp.jsx | 46 ++++++++++++++++++++++++++++++++------ previewtool/runPreview.js | 3 +++ site/site_data/eczoodb.js | 30 +++++++++++++++++++------ yarn.lock | 10 ++++----- 4 files changed, 70 insertions(+), 19 deletions(-) diff --git a/previewtool/previewApp.jsx b/previewtool/previewApp.jsx index c441f80..5b884d3 100644 --- a/previewtool/previewApp.jsx +++ b/previewtool/previewApp.jsx @@ -152,14 +152,41 @@ window.addEventListener('load', async () => { const fs = fsRemoteCreateClient(); // - // load ZooDb + // Prepare the ZooDb default options + // + + let defaultAppZooDbOptions = get_eczoo_full_options(); + + // + // load any existing citations cache to help our citations resolver + // because we don't have access to DOI & arXiv APIs due to their strict + // CORS settings + // + + let loadedCitationsCache = {}; + const fnameCitationsInfoCache = path.join(serverData.citationsinfo_cache_dir_default, + 'cache_compiled_citations.json'); + try { + loadedCitationsCache = JSON.parse( + await fs.promises.readFile(fnameCitationsInfoCache) + ); + debug(`Loaded citations cache file ‘${fnameCitationsInfoCache}’`, + loadedCitationsCache); + } catch (error) { + console.warn(`Failed to load citations cache file ‘${fnameCitationsInfoCache}’, ` + + `will proceed without cached info.`, error); + } + + + // + // Finalize the ZooDb Options & load ! // let appZooDbOptions = loMerge( // // our built-in default options/settings // - get_eczoo_full_options(), + defaultAppZooDbOptions, // // custom options & settings @@ -180,19 +207,23 @@ window.addEventListener('load', async () => { // their public APIs seem to have strict CORS settings // meaning we can't call them from other web apps doi: new CitationSourceApiPlaceholder({ - title: "DOI citation", + title: (doi) => `[DOI \\verbcode{${doi}}; citation text will appear on production zoo website]`, cite_prefix: 'doi', test_url: (_, cite_key) => `https://doi.org/${cite_key}`, + search_in_compiled_cache: loadedCitationsCache, }), arxiv: new CitationSourceApiPlaceholder({ - title: "arXiv [& DOI?] citation", + title: (arxivid) => `[arXiv:${arxivid}; citation text will appear on production zoo website (& via DOI if published)]`, cite_prefix: 'arxiv', test_url: (_, cite_key) => `https://arxiv.org/abs/${cite_key}`, + search_in_compiled_cache: loadedCitationsCache, }), }, - citation_manager_options: { - skip_save_cache: true, - } + + cache_dir: '_zoodb_live_preview_dummy_cache_shouldnt_be_created', + cache_dir_create: false, + + skip_save_cache: true, }, allow_unresolved_references: true, allow_unresolved_citations: true, @@ -209,6 +240,7 @@ window.addEventListener('load', async () => { ); let zoodb = new EcZooDb( appZooDbOptions ); + zoodb.install_zoo_loader(new EcZooDbYamlDataLoader({ schema_root: `file://${serverData.schema_root_dir}/`, throw_reload_errors: true, diff --git a/previewtool/runPreview.js b/previewtool/runPreview.js index c527b7a..52d7d40 100644 --- a/previewtool/runPreview.js +++ b/previewtool/runPreview.js @@ -3,6 +3,8 @@ import path from 'path'; import { PreviewAppServer } from '@phfaist/zoodbtools_previewremote/startRemotePreviewApp.js'; +import { citationsinfo_cache_dir_default } from '../eczoodb/dirs_defaults.js'; + const __filename = (new URL('', import.meta.url)).pathname; const __dirname = (new URL('.', import.meta.url)).pathname; @@ -21,6 +23,7 @@ const settings = { 'appData.json': { eczoo_data_dir: path.join(__dirname, '../../eczoo_data/'), schema_root_dir: path.join(__dirname, '../eczoodb/'), + citationsinfo_cache_dir_default, } }, diff --git a/site/site_data/eczoodb.js b/site/site_data/eczoodb.js index 427c69d..053197b 100644 --- a/site/site_data/eczoodb.js +++ b/site/site_data/eczoodb.js @@ -15,15 +15,31 @@ module.exports = async (configData) => { const { EcZooDbYamlDataLoader } = await import('@errorcorrectionzoo/eczoodb/load_yamldb.js'); - cached_eczoodb = new EcZooDb({ - fs, - fs_data_dir: eczoo_config.data_dir, - ... get_eczoo_full_options() - }); - cached_eczoodb.install_zoo_loader(new EcZooDbYamlDataLoader({ })); + try { + + cached_eczoodb = new EcZooDb({ + fs, + fs_data_dir: eczoo_config.data_dir, + ... get_eczoo_full_options() + }); + cached_eczoodb.install_zoo_loader(new EcZooDbYamlDataLoader({ })); + + } catch (err) { + console.error(err); + console.err(`ERROR INITIALIZING ZOO: ${err}`); + throw err; + } } - await cached_eczoodb.load(); + try { + + await cached_eczoodb.load(); + + } catch (err) { + console.error(err); + console.err(`ERROR LOADING ZOO: ${err}`); + throw err; + } return cached_eczoodb; }; diff --git a/yarn.lock b/yarn.lock index 8365fb2..d361a90 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1893,7 +1893,7 @@ __metadata: "@phfaist/zoodb@https://github.com/phfaist/zoodb.git#main": version: 0.1.1 - resolution: "@phfaist/zoodb@https://github.com/phfaist/zoodb.git#commit=05d73422d87d8cd07e0d92825785a46e684e8dc2" + resolution: "@phfaist/zoodb@https://github.com/phfaist/zoodb.git#commit=1cbbfd090565b92d6eaa4b4d53c7e9661f90e18f" dependencies: "@apidevtools/json-schema-ref-parser": ^10.1.0 base32-encode: ^2.0.0 @@ -1915,13 +1915,13 @@ __metadata: stream-parser: ^0.3.1 tippy.js: ^6.3.7 url: ^0.11.0 - checksum: 934416aaa0ffa462ec96a44ea459aad58f39bf26dcd7799170ec50b0bae206d6f21a1d7ca38cdfaecb60d58a68eb4bc8a9ec00b305824ec1d9242ece5ccb6449 + checksum: 2852ab130bbe35afd63e872c61f6420f506d9a60ec903f0dd4aa87bd07e055f7e9a799a4fc194e2afc1d0f21f773586183a9cbc602ff9ca84da8645c57976537 languageName: node linkType: hard "@phfaist/zoodbtools_preview@https://github.com/phfaist/zoodbtools.git#head=main&workspace=zoodbtools_preview": version: 0.1.0 - resolution: "@phfaist/zoodbtools_preview@https://github.com/phfaist/zoodbtools.git#workspace=zoodbtools_preview&commit=513f049b5969768c404778636a9aa5ae8a977615" + resolution: "@phfaist/zoodbtools_preview@https://github.com/phfaist/zoodbtools.git#workspace=zoodbtools_preview&commit=9f2c86132a64569e4772e6603b2491c7c7359c2f" dependencies: debug: ^4.3.4 escape-html: ^1.0.3 @@ -1931,13 +1931,13 @@ __metadata: react-select: ^5.7.4 peerDependencies: "@phfaist/zoodb": "*" - checksum: 16dc7f4084b1c46a1f817ff4604cb14a7de34e2afa38639abff7cd4bca4241c32ab545c702980965b9b5c6ae39c7c6da3e012cb843c6ab7d3a71e9c17048cc56 + checksum: 73cbd526fb7749e0576fd61b76978f6b3d968796652c4b68455514c22a5f55eb871cff53efd36a25505f0095e2140ecaae5eb7a080af1b424cac504331788a6a languageName: node linkType: hard "@phfaist/zoodbtools_previewremote@https://github.com/phfaist/zoodbtools.git#head=main&workspace=zoodbtools_previewremote": version: 0.1.0 - resolution: "@phfaist/zoodbtools_previewremote@https://github.com/phfaist/zoodbtools.git#workspace=zoodbtools_previewremote&commit=513f049b5969768c404778636a9aa5ae8a977615" + resolution: "@phfaist/zoodbtools_previewremote@https://github.com/phfaist/zoodbtools.git#workspace=zoodbtools_previewremote&commit=9f2c86132a64569e4772e6603b2491c7c7359c2f" dependencies: debug: ^4.3.4 fs-remote: ^0.1.9