72 lines
1.5 KiB
TypeScript
72 lines
1.5 KiB
TypeScript
/**
|
|
* rPhotos Automerge document schemas.
|
|
*
|
|
* Syncs shared album curation and photo annotations across space members.
|
|
* Actual photo files remain on the Immich server; this doc manages
|
|
* which albums are shared and any collaborative annotations.
|
|
*
|
|
* DocId format: {space}:photos:albums
|
|
*/
|
|
|
|
import type { DocSchema } from '../../shared/local-first/document';
|
|
|
|
// ── Document types ──
|
|
|
|
export interface SharedAlbum {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
sharedBy: string | null;
|
|
sharedAt: number;
|
|
}
|
|
|
|
export interface PhotoAnnotation {
|
|
assetId: string;
|
|
note: string;
|
|
authorDid: string;
|
|
createdAt: number;
|
|
}
|
|
|
|
export interface PhotosDoc {
|
|
meta: {
|
|
module: string;
|
|
collection: string;
|
|
version: number;
|
|
spaceSlug: string;
|
|
createdAt: number;
|
|
};
|
|
sharedAlbums: Record<string, SharedAlbum>;
|
|
annotations: Record<string, PhotoAnnotation>;
|
|
}
|
|
|
|
// ── Schema registration ──
|
|
|
|
export const photosSchema: DocSchema<PhotosDoc> = {
|
|
module: 'photos',
|
|
collection: 'albums',
|
|
version: 1,
|
|
init: (): PhotosDoc => ({
|
|
meta: {
|
|
module: 'photos',
|
|
collection: 'albums',
|
|
version: 1,
|
|
spaceSlug: '',
|
|
createdAt: Date.now(),
|
|
},
|
|
sharedAlbums: {},
|
|
annotations: {},
|
|
}),
|
|
migrate: (doc: any, _fromVersion: number) => {
|
|
if (!doc.sharedAlbums) doc.sharedAlbums = {};
|
|
if (!doc.annotations) doc.annotations = {};
|
|
doc.meta.version = 1;
|
|
return doc;
|
|
},
|
|
};
|
|
|
|
// ── Helpers ──
|
|
|
|
export function photosDocId(space: string) {
|
|
return `${space}:photos:albums` as const;
|
|
}
|