π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove unused individual comment and reaction diff endpoints
Anand Baburajan63d813911ccb
diff --git a/web/packages/new/albums/services/public-comment.ts b/web/packages/new/albums/services/public-comment.tsindex f03590c96a..8fbbfde51b 100644--- a/web/packages/new/albums/services/public-comment.ts+++ b/web/packages/new/albums/services/public-comment.ts@@ -76,53 +76,6 @@ export const addPublicComment = async (return id;};-/**- * Update a comment in a public album (as an anonymous user).- *- * @param credentials Public album credentials (access token).- * @param collectionID The collection ID for looking up stored identity.- * @param commentID The ID of the comment to update.- * @param text The new comment text.- * @param collectionKey The decrypted collection key (base64 encoded).- * @param anonIdentity Optional anonymous identity. If not provided, will use stored identity.- */-export const updatePublicComment = async (- credentials: PublicAlbumsCredentials,- collectionID: number,- commentID: string,- text: string,- collectionKey: string,- anonIdentity?: AnonIdentity,-): Promise<void> => {- const identity = anonIdentity ?? getStoredAnonIdentity(collectionID);- if (!identity) {- throw new Error("No anonymous identity available");- }-- const { encryptedData: cipher, nonce } = await encryptBox(- new TextEncoder().encode(text),- collectionKey,- );-- const res = await fetch(- await apiURL(`/public-collection/comments/${commentID}`),- {- method: "PATCH",- headers: {- ...authenticatedPublicAlbumsRequestHeaders(credentials),- "Content-Type": "application/json",- },- body: JSON.stringify({- cipher,- nonce,- anonUserID: identity.anonUserID,- anonToken: identity.token,- }),- },- );- ensureOk(res);-};-/*** Delete a comment from a public album (as an anonymous user).*diff --git a/web/packages/new/photos/services/comment.ts b/web/packages/new/photos/services/comment.tsindex 24661ebeab..e6a182acb2 100644--- a/web/packages/new/photos/services/comment.ts+++ b/web/packages/new/photos/services/comment.ts@@ -1,4 +1,4 @@-import { decryptBox, encryptBox } from "ente-base/crypto";+import { encryptBox } from "ente-base/crypto";import { authenticatedRequestHeaders, ensureOk } from "ente-base/http";import { apiURL } from "ente-base/origins";import { z } from "zod";@@ -22,78 +22,6 @@ export interface Comment {updatedAt: number;}-/**- * Get comments for a file in a collection.- *- * @param collectionID The ID of the collection containing the file.- * @param fileID The ID of the file to get comments for.- * @param collectionKey The decrypted collection key (base64 encoded).- * @returns Array of decrypted comments for the file.- */-export const getFileComments = async (- collectionID: number,- fileID: number,- collectionKey: string,-): Promise<Comment[]> => {- const res = await fetch(- await apiURL("/comments/diff", {- collectionID,- fileID,- sinceTime: 0,- limit: 1000,- }),- { headers: await authenticatedRequestHeaders() },- );- ensureOk(res);- const { comments } = GetCommentsResponse.parse(await res.json());-- const decryptedComments: Comment[] = [];- for (const comment of comments) {- // Skip deleted comments (they have null cipher/nonce)- if (comment.isDeleted || !comment.cipher || !comment.nonce) {- decryptedComments.push({- id: comment.id,- collectionID: comment.collectionID,- fileID: comment.fileID ?? undefined,- parentCommentID: comment.parentCommentID ?? undefined,- userID: comment.userID,- anonUserID: comment.anonUserID ?? undefined,- text: "",- isDeleted: comment.isDeleted,- createdAt: comment.createdAt,- updatedAt: comment.updatedAt,- });- continue;- }- try {- const decryptedB64 = await decryptBox(- { encryptedData: comment.cipher, nonce: comment.nonce },- collectionKey,- );- const text = new TextDecoder().decode(- Uint8Array.from(atob(decryptedB64), (c) => c.charCodeAt(0)),- );- const decryptedComment = {- id: comment.id,- collectionID: comment.collectionID,- fileID: comment.fileID ?? undefined,- parentCommentID: comment.parentCommentID ?? undefined,- userID: comment.userID,- anonUserID: comment.anonUserID ?? undefined,- text,- isDeleted: comment.isDeleted,- createdAt: comment.createdAt,- updatedAt: comment.updatedAt,- };- decryptedComments.push(decryptedComment);- } catch (e) {- // Log and skip comments that fail to decrypt- console.error("Failed to decrypt comment", comment.id, e);- }- }- return decryptedComments;-};-/*** Add a comment to a file in a collection.*@@ -135,34 +63,6 @@ export const addComment = async (return id;};-/**- * Update a comment's content.- *- * @param commentID The ID of the comment to update.- * @param text The new comment text.- * @param collectionKey The decrypted collection key (base64 encoded).- */-export const updateComment = async (- commentID: string,- text: string,- collectionKey: string,-): Promise<void> => {- const { encryptedData: cipher, nonce } = await encryptBox(- new TextEncoder().encode(text),- collectionKey,- );-- const res = await fetch(await apiURL(`/comments/${commentID}`), {- method: "PATCH",- headers: {- ...(await authenticatedRequestHeaders()),- "Content-Type": "application/json",- },- body: JSON.stringify({ cipher, nonce }),- });- ensureOk(res);-};-/*** Delete a comment by its ID.*@@ -177,23 +77,3 @@ export const deleteComment = async (commentID: string): Promise<void> => {};const CreateCommentResponse = z.object({ id: z.string() });--const RemoteComment = z.object({- id: z.string(),- collectionID: z.number(),- fileID: z.number().nullish(),- parentCommentID: z.string().nullish(),- userID: z.number(),- anonUserID: z.string().nullish(),- // cipher and nonce are missing/null for deleted comments- cipher: z.string().nullish(),- nonce: z.string().nullish(),- isDeleted: z.boolean(),- createdAt: z.number(),- updatedAt: z.number(),-});--const GetCommentsResponse = z.object({- comments: z.array(RemoteComment),- hasMore: z.boolean(),-});diff --git a/web/packages/new/photos/services/reaction.ts b/web/packages/new/photos/services/reaction.tsindex d86212e5f0..0ba64e7f3e 100644--- a/web/packages/new/photos/services/reaction.ts+++ b/web/packages/new/photos/services/reaction.ts@@ -1,4 +1,4 @@-import { decryptBox, encryptBox } from "ente-base/crypto";+import { encryptBox } from "ente-base/crypto";import { authenticatedRequestHeaders, ensureOk } from "ente-base/http";import { apiURL } from "ente-base/origins";import { z } from "zod";@@ -17,23 +17,6 @@ const paddedReactionLength = 100;const padReaction = (reactionType: string): string =>reactionType.padEnd(paddedReactionLength, "\0");-/**- * Remove null byte padding from a decrypted reaction type.- */-const unpadReaction = (paddedReaction: string): string =>- paddedReaction.replace(/\0+$/, "");--/**- * A decrypted reaction.- */-export interface Reaction {- id: string;- fileID: number;- reactionType: string;- userID: number;- isDeleted: boolean;-}-/*** Add a reaction to a file in a collection.*@@ -100,161 +83,8 @@ export const addCommentReaction = async (return id;};-/**- * Get reactions for a file in a collection.- *- * @param collectionID The ID of the collection containing the file.- * @param fileID The ID of the file to get reactions for.- * @param collectionKey The decrypted collection key (base64 encoded).- * @returns Array of decrypted reactions for the file.- */-export const getFileReactions = async (- collectionID: number,- fileID: number,- collectionKey: string,-): Promise<Reaction[]> => {- const res = await fetch(- await apiURL("/reactions/diff", {- collectionID,- fileID,- sinceTime: 0,- limit: 100,- }),- { headers: await authenticatedRequestHeaders() },- );- ensureOk(res);- const { reactions } = GetReactionsResponse.parse(await res.json());-- const decryptedReactions: Reaction[] = [];- for (const reaction of reactions) {- // Skip deleted reactions (they have null cipher/nonce)- if (reaction.isDeleted || !reaction.cipher || !reaction.nonce) continue;- try {- const decryptedB64 = await decryptBox(- { encryptedData: reaction.cipher, nonce: reaction.nonce },- collectionKey,- );- const reactionType = unpadReaction(- new TextDecoder().decode(- Uint8Array.from(atob(decryptedB64), (c) => c.charCodeAt(0)),- ),- );- decryptedReactions.push({- id: reaction.id,- fileID: reaction.fileID,- reactionType,- userID: reaction.userID,- isDeleted: reaction.isDeleted,- });- } catch {- // Skip reactions that fail to decrypt- }- }- return decryptedReactions;-};--/**- * A decrypted comment reaction.- */-export interface CommentReaction {- id: string;- commentID: string;- reactionType: string;- userID: number;- isDeleted: boolean;-}--/**- * Get reactions for a comment in a collection.- *- * @param collectionID The ID of the collection containing the comment.- * @param commentID The ID of the comment to get reactions for.- * @param collectionKey The decrypted collection key (base64 encoded).- * @returns Array of decrypted reactions for the comment.- */-export const getCommentReactions = async (- collectionID: number,- commentID: string,- collectionKey: string,-): Promise<CommentReaction[]> => {- const res = await fetch(- await apiURL("/reactions/diff", {- collectionID,- commentID,- sinceTime: 0,- limit: 100,- }),- { headers: await authenticatedRequestHeaders() },- );- ensureOk(res);- const { reactions } = GetCommentReactionsResponse.parse(await res.json());-- const decryptedReactions: CommentReaction[] = [];- for (const reaction of reactions) {- // Skip deleted reactions (they have null cipher/nonce)- if (reaction.isDeleted || !reaction.cipher || !reaction.nonce) continue;- try {- const decryptedB64 = await decryptBox(- { encryptedData: reaction.cipher, nonce: reaction.nonce },- collectionKey,- );- const reactionType = unpadReaction(- new TextDecoder().decode(- Uint8Array.from(atob(decryptedB64), (c) => c.charCodeAt(0)),- ),- );- decryptedReactions.push({- id: reaction.id,- commentID: reaction.commentID,- reactionType,- userID: reaction.userID,- isDeleted: reaction.isDeleted,- });- } catch {- // Skip reactions that fail to decrypt- }- }- return decryptedReactions;-};-const UpsertReactionResponse = z.object({ id: z.string() });-const RemoteReaction = z.object({- id: z.string(),- collectionID: z.number(),- fileID: z.number(),- userID: z.number(),- // cipher and nonce are missing/null for deleted reactions- cipher: z.string().nullish(),- nonce: z.string().nullish(),- isDeleted: z.boolean(),- createdAt: z.number(),- updatedAt: z.number(),-});--const GetReactionsResponse = z.object({- reactions: z.array(RemoteReaction),- hasMore: z.boolean(),-});--const RemoteCommentReaction = z.object({- id: z.string(),- collectionID: z.number(),- commentID: z.string(),- userID: z.number(),- // cipher and nonce are missing/null for deleted reactions- cipher: z.string().nullish(),- nonce: z.string().nullish(),- isDeleted: z.boolean(),- createdAt: z.number(),- updatedAt: z.number(),-});--const GetCommentReactionsResponse = z.object({- reactions: z.array(RemoteCommentReaction),- hasMore: z.boolean(),-});-/*** Delete a reaction by its ID.*