Natnael B. Haile
Cursor
feat: complete IR Studio with Git LFS tracking for all binary assets and NFCorpus index
fbad523 Download src/utils/storage.ts from NathyB/ir-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.38 kB
-
https://huggingface.co/spaces/NathyB/ir-studio/resolve/main/src/utils/storage.ts
- Command line
-
hf download hf://spaces/NathyB/ir-studio/src/utils/storage.ts
-
curl -L -o storage.ts https://huggingface.co/spaces/NathyB/ir-studio/resolve/main/src/utils/storage.ts
2.38 kB
| import type { CorpusDataset } from '../types/corpus'; | |
| const STORAGE_KEY_CUSTOM_DATASETS = 'castorini_ir_custom_datasets'; | |
| const STORAGE_KEY_ACTIVE_DATASET = 'castorini_ir_active_dataset_id'; | |
| export function loadStoredCustomDatasets(): CorpusDataset[] { | |
| if (typeof window === 'undefined' || !window.localStorage) { | |
| return []; | |
| } | |
| try { | |
| const raw = window.localStorage.getItem(STORAGE_KEY_CUSTOM_DATASETS); | |
| if (!raw) return []; | |
| const parsed = JSON.parse(raw); | |
| if (Array.isArray(parsed)) { | |
| return parsed; | |
| } | |
| } catch (err) { | |
| console.error('Failed to load custom datasets from storage:', err); | |
| } | |
| return []; | |
| } | |
| export function saveStoredCustomDataset(dataset: CorpusDataset): boolean { | |
| if (typeof window === 'undefined' || !window.localStorage) { | |
| return false; | |
| } | |
| try { | |
| const existing = loadStoredCustomDatasets(); | |
| const index = existing.findIndex((d) => d.id === dataset.id); | |
| if (index >= 0) { | |
| existing[index] = dataset; | |
| } else { | |
| existing.unshift(dataset); | |
| } | |
| window.localStorage.setItem(STORAGE_KEY_CUSTOM_DATASETS, JSON.stringify(existing)); | |
| return true; | |
| } catch (err) { | |
| console.error('Failed to save custom dataset to storage:', err); | |
| return false; | |
| } | |
| } | |
| export function deleteStoredCustomDataset(datasetId: string): boolean { | |
| if (typeof window === 'undefined' || !window.localStorage) { | |
| return false; | |
| } | |
| try { | |
| const existing = loadStoredCustomDatasets(); | |
| const filtered = existing.filter((d) => d.id !== datasetId); | |
| window.localStorage.setItem(STORAGE_KEY_CUSTOM_DATASETS, JSON.stringify(filtered)); | |
| return true; | |
| } catch (err) { | |
| console.error('Failed to delete custom dataset from storage:', err); | |
| return false; | |
| } | |
| } | |
| export function getStoredActiveDatasetId(): string { | |
| if (typeof window === 'undefined' || !window.localStorage) { | |
| return 'msmarco-subset'; | |
| } | |
| try { | |
| const active = window.localStorage.getItem(STORAGE_KEY_ACTIVE_DATASET); | |
| return active || 'msmarco-subset'; | |
| } catch { | |
| return 'msmarco-subset'; | |
| } | |
| } | |
| export function setStoredActiveDatasetId(id: string): void { | |
| if (typeof window === 'undefined' || !window.localStorage) { | |
| return; | |
| } | |
| try { | |
| window.localStorage.setItem(STORAGE_KEY_ACTIVE_DATASET, id); | |
| } catch (err) { | |
| console.error('Failed to save active dataset id:', err); | |
| } | |
| } | |