One album or file quak cannot decrypt no longer stops a refresh or a backup (closes #181)
collectionsSince and filesSince put a row that does not decrypt or parse in an undecryptable list with the reason instead of throwing. The refresh leaves it out, an album with its files, and the store keeps the list in metadata.json until the server sends a copy that decrypts or deletes it, since the next refresh asks only for changes. lib.backup() records each such file in failures.json as "could not be decrypted: <reason>", unless a copy in another album decrypted, logs one line per such album and lists their IDs in undecryptableAlbums; quak backup exits 1 while any remain. Tests use a stand-in Ente server with real encryption. Model: opus-5-5
This commit is contained in:
+53
-26
@@ -44,20 +44,28 @@ export interface ClientSnapshot {
|
||||
|
||||
// The result of a resumable enumeration. Live decrypted records and deleted
|
||||
// ids are kept apart on purpose: a tombstone carries no key or metadata to
|
||||
// decrypt, so it is a bare id rather than a hollowed-out record. `cursor` is
|
||||
// the max `updationTime` seen, to pass back into the next call.
|
||||
// decrypt, so it is a bare id rather than a hollowed-out record. A live row
|
||||
// that cannot be decrypted, or whose metadata cannot be parsed, is in
|
||||
// `undecryptable` with the reason instead, so one bad row does not fail the
|
||||
// call; absent means there was none. `cursor` is the max `updationTime` seen,
|
||||
// those rows included, to pass back into the next call.
|
||||
export interface CollectionsPage {
|
||||
collections: Collection[];
|
||||
deleted: number[];
|
||||
undecryptable?: { id: number; error: string }[];
|
||||
cursor: number;
|
||||
}
|
||||
|
||||
export interface FilesPage {
|
||||
files: EnteFile[];
|
||||
deleted: number[];
|
||||
undecryptable?: { id: number; error: string }[];
|
||||
cursor: number;
|
||||
}
|
||||
|
||||
const errorMessage = (err: unknown): string =>
|
||||
err instanceof Error ? err.message : String(err);
|
||||
|
||||
export class Client {
|
||||
private readonly api: ApiClient;
|
||||
private readonly email: string;
|
||||
@@ -237,11 +245,12 @@ export class Client {
|
||||
}
|
||||
|
||||
// Enumerate collections changed since `sinceTime`. Live collections are
|
||||
// decrypted; tombstoned ones (isDeleted) are surfaced as bare ids. The
|
||||
// returned cursor is the max `updationTime` seen — including tombstones, so
|
||||
// the next sync resumes past them — falling back to `sinceTime` when the
|
||||
// response is empty. `/collections/v2` returns the whole changed set in one
|
||||
// response, so there is no pagination here.
|
||||
// decrypted; tombstoned ones (isDeleted) are surfaced as bare ids, and
|
||||
// ones that do not decrypt as ids with the reason. The returned cursor is
|
||||
// the max `updationTime` seen — including tombstones, so the next sync
|
||||
// resumes past them — falling back to `sinceTime` when the response is
|
||||
// empty. `/collections/v2` returns the whole changed set in one response,
|
||||
// so there is no pagination here.
|
||||
async collectionsSince(args: {
|
||||
sinceTime: number;
|
||||
}): Promise<CollectionsPage> {
|
||||
@@ -254,31 +263,40 @@ export class Client {
|
||||
|
||||
const collections: Collection[] = [];
|
||||
const deleted: number[] = [];
|
||||
const undecryptable: { id: number; error: string }[] = [];
|
||||
let cursor = args.sinceTime;
|
||||
for (const raw of raws) {
|
||||
if (raw.isDeleted) {
|
||||
deleted.push(raw.id);
|
||||
} else {
|
||||
collections.push(
|
||||
decryptCollection(
|
||||
raw,
|
||||
{
|
||||
masterKey: this.masterKey,
|
||||
publicKey: this.publicKey,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
this.userID,
|
||||
),
|
||||
);
|
||||
try {
|
||||
collections.push(
|
||||
decryptCollection(
|
||||
raw,
|
||||
{
|
||||
masterKey: this.masterKey,
|
||||
publicKey: this.publicKey,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
this.userID,
|
||||
),
|
||||
);
|
||||
} catch (err) {
|
||||
undecryptable.push({
|
||||
id: raw.id,
|
||||
error: errorMessage(err),
|
||||
});
|
||||
}
|
||||
}
|
||||
if (raw.updationTime > cursor) cursor = raw.updationTime;
|
||||
}
|
||||
return { collections, deleted, cursor };
|
||||
return { collections, deleted, undecryptable, cursor };
|
||||
}
|
||||
|
||||
// Enumerate a collection's files changed since `sinceTime`, paginating the
|
||||
// diff from that cursor. Live rows are decrypted; tombstoned ones are
|
||||
// surfaced as bare ids. Returns the final cursor to resume from.
|
||||
// surfaced as bare ids, and ones that do not decrypt or parse as ids with
|
||||
// the reason. Returns the final cursor to resume from.
|
||||
async filesSince(args: {
|
||||
collectionID: number;
|
||||
collectionKey: Uint8Array;
|
||||
@@ -288,6 +306,7 @@ export class Client {
|
||||
const { collectionID, collectionKey } = args;
|
||||
const files: EnteFile[] = [];
|
||||
const deleted: number[] = [];
|
||||
const undecryptable: { id: number; error: string }[] = [];
|
||||
let cursor = args.sinceTime;
|
||||
for (;;) {
|
||||
const { diff, hasMore } = await this.api.getJSON<{
|
||||
@@ -300,7 +319,14 @@ export class Client {
|
||||
if (raw.isDeleted) {
|
||||
deleted.push(raw.id);
|
||||
} else {
|
||||
files.push(decryptFile(raw, collectionKey));
|
||||
try {
|
||||
files.push(decryptFile(raw, collectionKey));
|
||||
} catch (err) {
|
||||
undecryptable.push({
|
||||
id: raw.id,
|
||||
error: errorMessage(err),
|
||||
});
|
||||
}
|
||||
}
|
||||
if (raw.updationTime > pageMax) pageMax = raw.updationTime;
|
||||
}
|
||||
@@ -321,18 +347,19 @@ export class Client {
|
||||
}
|
||||
cursor = pageMax;
|
||||
}
|
||||
return { files, deleted, cursor };
|
||||
return { files, deleted, undecryptable, cursor };
|
||||
}
|
||||
|
||||
// Whole-account listing: every live collection, deletions hidden. A thin
|
||||
// wrapper over `collectionsSince` from the beginning of time.
|
||||
// Whole-account listing: every live collection that decrypts, deletions
|
||||
// hidden. A thin wrapper over `collectionsSince` from the beginning of
|
||||
// time.
|
||||
async listCollections(): Promise<Collection[]> {
|
||||
const { collections } = await this.collectionsSince({ sinceTime: 0 });
|
||||
return collections;
|
||||
}
|
||||
|
||||
// Every live file in a collection, deletions hidden. A thin wrapper over
|
||||
// `filesSince` from the beginning of time.
|
||||
// Every live file in a collection that decrypts, deletions hidden. A thin
|
||||
// wrapper over `filesSince` from the beginning of time.
|
||||
async listFiles(
|
||||
collectionID: number,
|
||||
collectionKey: Uint8Array,
|
||||
|
||||
Reference in New Issue
Block a user