Skip to content

armgit / ente

Public Imported from GitHub
0

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

accessor

Manav Rathi3863591d261f
diff --git a/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx b/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx
index a4468f3b2d..9f224c1187 100644
--- a/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PreviewCard.tsx
@@ -2,6 +2,7 @@ import { Overlay } from "@/base/components/containers";
import { formatDateRelative } from "@/base/i18n-date";
import log from "@/base/log";
import { downloadManager } from "@/gallery/services/download";
+import { enteFileDeletionDate } from "@/media/file";
import { FileType } from "@/media/file-type";
import {
GAP_BTW_TILES,
@@ -359,7 +360,7 @@ export default function PreviewCard(props: IProps) {
{props?.activeCollectionID === TRASH_SECTION && file.isTrashed && (
<FileAndCollectionNameOverlay>
- <p>{formatDateRelative(file.deleteBy / 1000)}</p>
+ <p>{formatDateRelative(enteFileDeletionDate(file))}</p>
</FileAndCollectionNameOverlay>
)}
</Cont>
diff --git a/web/packages/base/date.ts b/web/packages/base/date.ts
new file mode 100644
index 0000000000..f08084f79a
--- /dev/null
+++ b/web/packages/base/date.ts
@@ -0,0 +1,14 @@
+/**
+ * Convert an epoch microsecond value to a JavaScript date.
+ *
+ * This is a convenience API for dealing with optional epoch microseconds in
+ * various data structures. Remote talks in terms of epoch microseconds, but
+ * JavaScript dates are underlain by epoch milliseconds, and this does a
+ * conversion, with a convenience of short circuiting undefined values.
+ */
+export const dateFromEpochMicroseconds = (
+ epochMicroseconds: number | undefined,
+) =>
+ epochMicroseconds === undefined
+ ? undefined
+ : new Date(epochMicroseconds / 1000);
diff --git a/web/packages/base/i18n-date.ts b/web/packages/base/i18n-date.ts
index de99b12829..dcf04aca9c 100644
--- a/web/packages/base/i18n-date.ts
+++ b/web/packages/base/i18n-date.ts
@@ -4,12 +4,11 @@
* Note that we rely on the current behaviour of a full reload on changing the
* language. See: [Note: Changing locale causes a full reload].
*/
-
import i18n from "i18next";
let _relativeDateFormat: Intl.RelativeTimeFormat | undefined;
-export const formatDateRelative = (epochMilliseconds: number) => {
+export const formatDateRelative = (date: Date) => {
const units = {
year: 24 * 60 * 60 * 1000 * 365,
month: (24 * 60 * 60 * 1000 * 365) / 12,
@@ -22,11 +21,11 @@ export const formatDateRelative = (epochMilliseconds: number) => {
new Intl.RelativeTimeFormat(i18n.language, {
localeMatcher: "best fit",
numeric: "always",
- style: "long",
+ style: "short",
}));
// "Math.abs" accounts for both past and future scenarios.
- const elapsed = Math.abs(epochMilliseconds - Date.now());
+ const elapsed = Math.abs(date.getTime() - Date.now());
for (const u in units)
if (elapsed > units[u] || u === "second")
diff --git a/web/packages/media/file.ts b/web/packages/media/file.ts
index 142e5a632f..767c86f5ef 100644
--- a/web/packages/media/file.ts
+++ b/web/packages/media/file.ts
@@ -1,4 +1,5 @@
import { sharedCryptoWorker } from "@/base/crypto";
+import { dateFromEpochMicroseconds } from "@/base/date";
import log from "@/base/log";
import { type Metadata, ItemVisibility } from "./file-metadata";
@@ -172,7 +173,15 @@ export interface EnteFile
* But its presence is not guaranteed.
*/
pubMagicMetadata?: FilePublicMagicMetadata;
+ /**
+ * `true` if this file is in trash (i.e. it has been deleted by the user,
+ * and will be permanently deleted after 30 days of being moved to trash).
+ */
isTrashed?: boolean;
+ /**
+ * If this is a file in trash, then {@link deleteBy} contains the epoch
+ * microseconds when this file will be permanently deleted.
+ */
deleteBy?: number;
/**
* The base64 representation of the decrypted encryption key associated with
@@ -285,6 +294,16 @@ export const fileLogID = (file: EnteFile) =>
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
`file ${file.metadata.title ?? "-"} (${file.id})`;
+/**
+ * Return the date when the file will be deleted permanently. Only valid for
+ * files that are in the user's trash.
+ *
+ * This is a convenience wrapper over the {@link deleteBy} property of a file,
+ * converting that epoch microsecond value into a JavaScript date.
+ */
+export const enteFileDeletionDate = (file: EnteFile) =>
+ dateFromEpochMicroseconds(file.deleteBy);
+
export async function decryptFile(
file: EncryptedEnteFile,
collectionKey: string,