mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-18 00:21:41 -07:00
fix(dictionary): stop large character dictionaries from timing out (#189)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as path from 'path';
|
||||
import { writeStoredZip } from '../../shared/stored-zip';
|
||||
import { readStoredZipFirstFile, writeStoredZip } from '../../shared/stored-zip';
|
||||
import { ensureDir } from './fs-utils';
|
||||
import type { CharacterDictionarySnapshotImage, CharacterDictionaryTermEntry } from './types';
|
||||
|
||||
@@ -31,6 +31,23 @@ function createTagBank(): Array<[string, string, number, string, number]> {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Revision recorded inside a built dictionary ZIP, or null when the archive is missing, truncated,
|
||||
* or not one of ours. `index.json` is always the first entry written by {@link buildDictionaryZip}.
|
||||
*/
|
||||
export function readDictionaryZipRevision(zipPath: string): string | null {
|
||||
const firstFile = readStoredZipFirstFile(zipPath);
|
||||
if (!firstFile || firstFile.name !== 'index.json') {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const index = JSON.parse(firstFile.data.toString('utf8')) as { revision?: unknown };
|
||||
return typeof index.revision === 'string' && index.revision.length > 0 ? index.revision : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function buildDictionaryZip(
|
||||
outputPath: string,
|
||||
dictionaryTitle: string,
|
||||
|
||||
Reference in New Issue
Block a user