Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Sketch

Manav Rathidc3f0be186c7
diff --git a/web/packages/new/albums/services/public-albums-fdb.ts b/web/packages/new/albums/services/public-albums-fdb.ts
index 93feb9bd1a..8303faa795 100644
--- a/web/packages/new/albums/services/public-albums-fdb.ts
+++ b/web/packages/new/albums/services/public-albums-fdb.ts
@@ -10,6 +10,7 @@ import {
import { type Collection } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import localForage from "ente-shared/storage/localForage";
+import { nullToUndefined } from "ente-utils/transform";
import { z } from "zod/v4";
/**
@@ -36,6 +37,34 @@ export const savedPublicCollections = async (): Promise<Collection[]> =>
export const savePublicCollections = (collections: Collection[]) =>
localForage.setItem("public-collections", collections);
+const LocalReferralCode = z.string().nullish().transform(nullToUndefined);
+
+/**
+ * Return the last saved referral code present in our local database.
+ *
+ * See: [Note: Public albums referral code]. A few more details specific to the
+ * persistence of the referral code:
+ *
+ * 1. The public albums app persists only the referral code for the latest
+ * public album that was fetched.
+ *
+ * 2. This saved value can be read by {@link savedLastPublicAlbumReferralCode}.
+ *
+ * 3. It gets updated as part of {@link publicAlbumsRemotePull}, which writes
+ * out a new value using {@link saveLastPublicAlbumReferralCode}.
+ */
+export const savedLastPublicAlbumReferralCode = async () =>
+ LocalReferralCode.parse(await localForage.getItem("public-referral-code"));
+
+/**
+ * Update the referral code present in our local database.
+ *
+ * This is the setter corresponding to {@link savedLastPublicAlbumReferralCode}.
+ */
+export const saveLastPublicAlbumReferralCode = async (referralCode: string) => {
+ await localForage.setItem("public-referral-code", referralCode);
+};
+
const LocalSavedPublicCollectionFilesEntry = z.object({
/**
* The collection, identified by its access token.
diff --git a/web/packages/new/albums/services/public-collection.ts b/web/packages/new/albums/services/public-collection.ts
index e8f808ada7..83100af109 100644
--- a/web/packages/new/albums/services/public-collection.ts
+++ b/web/packages/new/albums/services/public-collection.ts
@@ -4,7 +4,7 @@ import {
ensureOk,
} from "ente-base/http";
import { apiURL } from "ente-base/origins";
-import type { PublicURL } from "ente-media/collection";
+import { RemoteCollection, type PublicURL } from "ente-media/collection";
import { z } from "zod/v4";
/**
@@ -53,3 +53,18 @@ export const verifyPublicAlbumPassword = async (
ensureOk(res);
return z.object({ jwtToken: z.string() }).parse(await res.json()).jwtToken;
};
+
+// TODO(RE): Use me
+export const PublicCollectionInfo = z.object({
+ collection: RemoteCollection,
+ /**
+ * A referral code of the owner of the public album.
+ *
+ * [Note: Public albums referral code]
+ *
+ * The information of a public collection contains the referral code of the
+ * person who shared the album. This allows both the viewer and the sharer
+ * to gain storage bonus.
+ */
+ referralCode: z.string(),
+});