mirror of
https://github.com/immich-app/immich.git
synced 2025-12-09 17:23:13 +03:00
Compare commits
1 Commits
renovate/t
...
push-xqttk
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c291c4c522 |
@@ -1,5 +1,5 @@
|
||||
[tools]
|
||||
terragrunt = "0.93.12"
|
||||
terragrunt = "0.93.10"
|
||||
opentofu = "1.10.7"
|
||||
|
||||
[tasks."tg:fmt"]
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"eslint-plugin-unicorn": "^62.0.0",
|
||||
"exiftool-vendored": "^34.0.0",
|
||||
"exiftool-vendored": "^33.0.0",
|
||||
"globals": "^16.0.0",
|
||||
"jose": "^5.6.3",
|
||||
"luxon": "^3.4.4",
|
||||
|
||||
@@ -4,7 +4,7 @@ experimental_monorepo_root = true
|
||||
node = "24.11.1"
|
||||
flutter = "3.35.7"
|
||||
pnpm = "10.24.0"
|
||||
terragrunt = "0.93.12"
|
||||
terragrunt = "0.93.10"
|
||||
opentofu = "1.10.7"
|
||||
java = "25.0.1"
|
||||
|
||||
|
||||
39
pnpm-lock.yaml
generated
39
pnpm-lock.yaml
generated
@@ -244,8 +244,8 @@ importers:
|
||||
specifier: ^62.0.0
|
||||
version: 62.0.0(eslint@9.39.1(jiti@2.6.1))
|
||||
exiftool-vendored:
|
||||
specifier: ^34.0.0
|
||||
version: 34.0.0
|
||||
specifier: ^33.0.0
|
||||
version: 33.5.0
|
||||
globals:
|
||||
specifier: ^16.0.0
|
||||
version: 16.5.0
|
||||
@@ -428,8 +428,8 @@ importers:
|
||||
specifier: 4.3.3
|
||||
version: 4.3.3
|
||||
exiftool-vendored:
|
||||
specifier: ^34.0.0
|
||||
version: 34.0.0
|
||||
specifier: ^33.0.0
|
||||
version: 33.5.0
|
||||
express:
|
||||
specifier: ^5.1.0
|
||||
version: 5.2.0
|
||||
@@ -3236,7 +3236,6 @@ packages:
|
||||
'@koa/router@14.0.0':
|
||||
resolution: {integrity: sha512-LBSu5K0qAaaQcXX/0WIB9PGDevyCxxpnc1uq13vV/CgObaVxuis5hKl3Eboq/8gcb6ebnkAStW9NB/Em2eYyFA==}
|
||||
engines: {node: '>= 20'}
|
||||
deprecated: Please upgrade to v15 or higher. All reported bugs in this version are fixed in newer releases, dependencies have been updated, and security has been improved.
|
||||
|
||||
'@koddsson/eslint-plugin-tscompat@0.2.0':
|
||||
resolution: {integrity: sha512-Oqd4kWSX0LiO9wWHjcmDfXZNC7TotFV/tLRhwCFU3XUeb//KYvJ75c9OmeSJ+vBv5lkCeB+xYsqyNrBc5j18XA==}
|
||||
@@ -5504,8 +5503,8 @@ packages:
|
||||
resolution: {integrity: sha512-a28v2eWrrRWPpJSzxc+mKwm0ZtVx/G8SepdQZDArnXYU/XS+IF6mp8aB/4E+hH1tyGCoDo3KlUCdlSxGDsRkAw==}
|
||||
hasBin: true
|
||||
|
||||
batch-cluster@16.0.0:
|
||||
resolution: {integrity: sha512-+T7Ho09ikx/kP4P8M+GEnpuePzRQa4gTUhtPIu6ApFC8+0GY0sri1y1PuB+yfXlQWl5DkHC/e58z3U6g0qCz/A==}
|
||||
batch-cluster@15.0.1:
|
||||
resolution: {integrity: sha512-eUmh0ld1AUPKTEmdzwGF9QTSexXAyt9rA1F5zDfW1wUi3okA3Tal4NLdCeFI6aiKpBenQhR6NmK9bW9tBHTGPQ==}
|
||||
engines: {node: '>=20'}
|
||||
|
||||
batch@0.6.1:
|
||||
@@ -6849,17 +6848,17 @@ packages:
|
||||
resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
exiftool-vendored.exe@13.43.0:
|
||||
resolution: {integrity: sha512-EENHNz86tYY5yHGPtGB2mto3FIGstQvEhrcU34f7fm4RMxBKNfTWYOGkhU1jzvjOi+V4575LQX/FUES1TwgUbQ==}
|
||||
exiftool-vendored.exe@13.42.0:
|
||||
resolution: {integrity: sha512-6AFybe5IakduMWleuQBfep9OWGSVZSedt2uKL+LzufRsATp+beOF7tZyKtMztjb6VRH1GF/4F9EvBVam6zm70w==}
|
||||
os: [win32]
|
||||
|
||||
exiftool-vendored.pl@13.43.0:
|
||||
resolution: {integrity: sha512-0ApWaQ/pxaliPK7HzTxVA0sg/wZ8vl7UtFVhCyWhGQg01WfZkFrKwKmELB0Bnn01WTfgIuMadba8ccmFvpmJag==}
|
||||
exiftool-vendored.pl@13.42.0:
|
||||
resolution: {integrity: sha512-EF5IdxQNIJIvZjHf4bG4jnwAHVVSLkYZToo2q+Mm89kSuppKfRvHz/lngIxN0JALE8rFdC4zt6NWY/PKqRdCcg==}
|
||||
os: ['!win32']
|
||||
hasBin: true
|
||||
|
||||
exiftool-vendored@34.0.0:
|
||||
resolution: {integrity: sha512-rhIe4XGE7kh76nwytwHtq6qK/pc1mpOBHRV++gudFeG2PfAp3XIVQbFWCLK3S4l9I4AWYOe4mxk8mW8l1oHRTw==}
|
||||
exiftool-vendored@33.5.0:
|
||||
resolution: {integrity: sha512-7cCh6izwdmC5ZaCxpHFehnExIr2Yp7CJuxHg4WFiGcm81yyxXLtvSE+85ep9VsNwhlOtSpk+XxiqrlddjY5lAw==}
|
||||
engines: {node: '>=20.0.0'}
|
||||
|
||||
expect-type@1.2.1:
|
||||
@@ -17581,7 +17580,7 @@ snapshots:
|
||||
|
||||
baseline-browser-mapping@2.8.31: {}
|
||||
|
||||
batch-cluster@16.0.0: {}
|
||||
batch-cluster@15.0.1: {}
|
||||
|
||||
batch@0.6.1: {}
|
||||
|
||||
@@ -19129,21 +19128,21 @@ snapshots:
|
||||
signal-exit: 3.0.7
|
||||
strip-final-newline: 2.0.0
|
||||
|
||||
exiftool-vendored.exe@13.43.0:
|
||||
exiftool-vendored.exe@13.42.0:
|
||||
optional: true
|
||||
|
||||
exiftool-vendored.pl@13.43.0: {}
|
||||
exiftool-vendored.pl@13.42.0: {}
|
||||
|
||||
exiftool-vendored@34.0.0:
|
||||
exiftool-vendored@33.5.0:
|
||||
dependencies:
|
||||
'@photostructure/tz-lookup': 11.3.0
|
||||
'@types/luxon': 3.7.1
|
||||
batch-cluster: 16.0.0
|
||||
exiftool-vendored.pl: 13.43.0
|
||||
batch-cluster: 15.0.1
|
||||
exiftool-vendored.pl: 13.42.0
|
||||
he: 1.2.0
|
||||
luxon: 3.7.2
|
||||
optionalDependencies:
|
||||
exiftool-vendored.exe: 13.43.0
|
||||
exiftool-vendored.exe: 13.42.0
|
||||
|
||||
expect-type@1.2.1: {}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
"cookie": "^1.0.2",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"cron": "4.3.3",
|
||||
"exiftool-vendored": "^34.0.0",
|
||||
"exiftool-vendored": "^33.0.0",
|
||||
"express": "^5.1.0",
|
||||
"fast-glob": "^3.3.2",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
|
||||
225
web/src/lib/stores/ocr.svelte.spec.ts
Normal file
225
web/src/lib/stores/ocr.svelte.spec.ts
Normal file
@@ -0,0 +1,225 @@
|
||||
import { ocrManager, type OcrBoundingBox } from '$lib/stores/ocr.svelte';
|
||||
import { getAssetOcr } from '@immich/sdk';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
// Mock the SDK
|
||||
vi.mock('@immich/sdk', () => ({
|
||||
getAssetOcr: vi.fn(),
|
||||
}));
|
||||
|
||||
const createMockOcrData = (overrides?: Partial<OcrBoundingBox>): OcrBoundingBox[] => [
|
||||
{
|
||||
id: '1',
|
||||
assetId: 'asset-123',
|
||||
x1: 0,
|
||||
y1: 0,
|
||||
x2: 100,
|
||||
y2: 0,
|
||||
x3: 100,
|
||||
y3: 50,
|
||||
x4: 0,
|
||||
y4: 50,
|
||||
boxScore: 0.95,
|
||||
textScore: 0.98,
|
||||
text: 'Hello World',
|
||||
...overrides,
|
||||
},
|
||||
];
|
||||
|
||||
describe('OcrManager', () => {
|
||||
beforeEach(() => {
|
||||
// Reset the singleton state before each test
|
||||
ocrManager.clear();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('initial state', () => {
|
||||
it('should initialize with empty data', () => {
|
||||
expect(ocrManager.data).toEqual([]);
|
||||
});
|
||||
|
||||
it('should initialize with showOverlay as false', () => {
|
||||
expect(ocrManager.showOverlay).toBe(false);
|
||||
});
|
||||
|
||||
it('should initialize with hasOcrData as false', () => {
|
||||
expect(ocrManager.hasOcrData).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAssetOcr', () => {
|
||||
it('should load OCR data for an asset', async () => {
|
||||
const mockData = createMockOcrData();
|
||||
vi.mocked(getAssetOcr).mockResolvedValue(mockData);
|
||||
|
||||
await ocrManager.getAssetOcr('asset-123');
|
||||
|
||||
expect(getAssetOcr).toHaveBeenCalledWith({ id: 'asset-123' });
|
||||
expect(ocrManager.data).toEqual(mockData);
|
||||
expect(ocrManager.hasOcrData).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle empty OCR data', async () => {
|
||||
vi.mocked(getAssetOcr).mockResolvedValue([]);
|
||||
|
||||
await ocrManager.getAssetOcr('asset-456');
|
||||
|
||||
expect(ocrManager.data).toEqual([]);
|
||||
expect(ocrManager.hasOcrData).toBe(false);
|
||||
});
|
||||
|
||||
it('should reset the loader when previously cleared', async () => {
|
||||
const mockData = createMockOcrData();
|
||||
vi.mocked(getAssetOcr).mockResolvedValue(mockData);
|
||||
|
||||
// First clear
|
||||
ocrManager.clear();
|
||||
expect(ocrManager.data).toEqual([]);
|
||||
|
||||
// Then load new data
|
||||
await ocrManager.getAssetOcr('asset-789');
|
||||
|
||||
expect(ocrManager.data).toEqual(mockData);
|
||||
expect(ocrManager.hasOcrData).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle concurrent requests safely', async () => {
|
||||
const firstData = createMockOcrData({ id: '1', text: 'First' });
|
||||
const secondData = createMockOcrData({ id: '2', text: 'Second' });
|
||||
|
||||
vi.mocked(getAssetOcr)
|
||||
.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => resolve(firstData), 100);
|
||||
}),
|
||||
)
|
||||
.mockResolvedValueOnce(secondData);
|
||||
|
||||
// Start first request
|
||||
const promise1 = ocrManager.getAssetOcr('asset-1');
|
||||
// Start second request immediately (should wait for first to complete)
|
||||
const promise2 = ocrManager.getAssetOcr('asset-2');
|
||||
|
||||
await Promise.all([promise1, promise2]);
|
||||
|
||||
// CancellableTask waits for first request, so second request is ignored
|
||||
// The data should be from the first request that completed
|
||||
expect(ocrManager.data).toEqual(firstData);
|
||||
});
|
||||
|
||||
it('should handle errors gracefully', async () => {
|
||||
const error = new Error('Network error');
|
||||
vi.mocked(getAssetOcr).mockRejectedValue(error);
|
||||
|
||||
// The error should be handled by CancellableTask
|
||||
await expect(ocrManager.getAssetOcr('asset-error')).resolves.not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('clear', () => {
|
||||
it('should clear OCR data', async () => {
|
||||
const mockData = createMockOcrData({ text: 'Test' });
|
||||
vi.mocked(getAssetOcr).mockResolvedValue(mockData);
|
||||
await ocrManager.getAssetOcr('asset-123');
|
||||
|
||||
ocrManager.clear();
|
||||
|
||||
expect(ocrManager.data).toEqual([]);
|
||||
expect(ocrManager.hasOcrData).toBe(false);
|
||||
});
|
||||
|
||||
it('should reset showOverlay to false', () => {
|
||||
ocrManager.showOverlay = true;
|
||||
|
||||
ocrManager.clear();
|
||||
|
||||
expect(ocrManager.showOverlay).toBe(false);
|
||||
});
|
||||
|
||||
it('should mark as cleared for next load', async () => {
|
||||
const mockData = createMockOcrData({ text: 'Test' });
|
||||
vi.mocked(getAssetOcr).mockResolvedValue(mockData);
|
||||
|
||||
ocrManager.clear();
|
||||
await ocrManager.getAssetOcr('asset-123');
|
||||
|
||||
// Should successfully load after clear
|
||||
expect(ocrManager.data).toEqual(mockData);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggleOcrBoundingBox', () => {
|
||||
it('should toggle showOverlay from false to true', () => {
|
||||
expect(ocrManager.showOverlay).toBe(false);
|
||||
|
||||
ocrManager.toggleOcrBoundingBox();
|
||||
|
||||
expect(ocrManager.showOverlay).toBe(true);
|
||||
});
|
||||
|
||||
it('should toggle showOverlay from true to false', () => {
|
||||
ocrManager.showOverlay = true;
|
||||
|
||||
ocrManager.toggleOcrBoundingBox();
|
||||
|
||||
expect(ocrManager.showOverlay).toBe(false);
|
||||
});
|
||||
|
||||
it('should toggle multiple times', () => {
|
||||
ocrManager.toggleOcrBoundingBox();
|
||||
expect(ocrManager.showOverlay).toBe(true);
|
||||
|
||||
ocrManager.toggleOcrBoundingBox();
|
||||
expect(ocrManager.showOverlay).toBe(false);
|
||||
|
||||
ocrManager.toggleOcrBoundingBox();
|
||||
expect(ocrManager.showOverlay).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasOcrData derived state', () => {
|
||||
it('should be false when data is empty', () => {
|
||||
expect(ocrManager.hasOcrData).toBe(false);
|
||||
});
|
||||
|
||||
it('should be true when data is present', async () => {
|
||||
const mockData = createMockOcrData({ text: 'Test' });
|
||||
vi.mocked(getAssetOcr).mockResolvedValue(mockData);
|
||||
await ocrManager.getAssetOcr('asset-123');
|
||||
|
||||
expect(ocrManager.hasOcrData).toBe(true);
|
||||
});
|
||||
|
||||
it('should update when data is cleared', async () => {
|
||||
const mockData = createMockOcrData({ text: 'Test' });
|
||||
vi.mocked(getAssetOcr).mockResolvedValue(mockData);
|
||||
await ocrManager.getAssetOcr('asset-123');
|
||||
expect(ocrManager.hasOcrData).toBe(true);
|
||||
|
||||
ocrManager.clear();
|
||||
expect(ocrManager.hasOcrData).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('data immutability', () => {
|
||||
it('should return the same reference when data does not change', () => {
|
||||
const firstReference = ocrManager.data;
|
||||
const secondReference = ocrManager.data;
|
||||
|
||||
expect(firstReference).toBe(secondReference);
|
||||
});
|
||||
|
||||
it('should return a new reference when data changes', async () => {
|
||||
const firstReference = ocrManager.data;
|
||||
const mockData = createMockOcrData({ text: 'Test' });
|
||||
|
||||
vi.mocked(getAssetOcr).mockResolvedValue(mockData);
|
||||
await ocrManager.getAssetOcr('asset-123');
|
||||
|
||||
const secondReference = ocrManager.data;
|
||||
|
||||
expect(firstReference).not.toBe(secondReference);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CancellableTask } from '$lib/utils/cancellable-task';
|
||||
import { getAssetOcr } from '@immich/sdk';
|
||||
|
||||
export type OcrBoundingBox = {
|
||||
@@ -20,6 +21,8 @@ class OcrManager {
|
||||
#data = $state<OcrBoundingBox[]>([]);
|
||||
showOverlay = $state(false);
|
||||
#hasOcrData = $derived(this.#data.length > 0);
|
||||
#ocrLoader = new CancellableTask();
|
||||
#cleared = false;
|
||||
|
||||
get data() {
|
||||
return this.#data;
|
||||
@@ -30,10 +33,17 @@ class OcrManager {
|
||||
}
|
||||
|
||||
async getAssetOcr(id: string) {
|
||||
this.#data = await getAssetOcr({ id });
|
||||
if (this.#cleared) {
|
||||
await this.#ocrLoader.reset();
|
||||
this.#cleared = false;
|
||||
}
|
||||
await this.#ocrLoader.execute(async () => {
|
||||
this.#data = await getAssetOcr({ id });
|
||||
}, false);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.#cleared = true;
|
||||
this.#data = [];
|
||||
this.showOverlay = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user