π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move
Manav Rathiaaadffa61300
diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.tsindex 01a3289d93..3736327e7e 100644--- a/web/apps/photos/src/services/searchService.ts+++ b/web/apps/photos/src/services/searchService.ts@@ -7,15 +7,17 @@ import {isMLSupported,mlStatusSnapshot,} from "@/new/photos/services/ml";-import type { SearchPerson } from "@/new/photos/services/search";+import { parsePotentialDate } from "@/new/photos/services/search";+import type {+ DateValue,+ SearchPerson,+} from "@/new/photos/services/search/types";import { EnteFile } from "@/new/photos/types/file";-import * as chrono from "chrono-node";import { t } from "i18next";import { Collection } from "types/collection";import { EntityType, LocationTag, LocationTagData } from "types/entity";import {ClipSearchScores,- DateValue,Search,SearchOption,Suggestion,@@ -23,12 +25,9 @@ import {} from "types/search";import ComlinkSearchWorker from "utils/comlink/ComlinkSearchWorker";import { getUniqueFiles } from "utils/file";-import { getFormattedDate } from "utils/search";import { getLatestEntities } from "./entityService";import locationSearchService, { City } from "./locationSearchService";-const DIGITS = new Set(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);-export const getDefaultOptions = async () => {return [await getMLStatusSuggestion(),@@ -209,7 +208,7 @@ export async function getMLStatusSuggestion(): Promise<Suggestion> {}function getDateSuggestion(searchPhrase: string): Suggestion[] {- const searchedDates = parseHumanDate(searchPhrase);+ const searchedDates = parsePotentialDate(searchPhrase);return searchedDates.map((searchedDate) => ({type: SuggestionType.DATE,@@ -218,6 +217,16 @@ function getDateSuggestion(searchPhrase: string): Suggestion[] {}));}+export function getFormattedDate(date: DateValue) {+ const options = {};+ date.date && (options["day"] = "numeric");+ (date.month || date.month === 0) && (options["month"] = "long");+ date.year && (options["year"] = "numeric");+ return new Intl.DateTimeFormat("en-IN", options).format(+ new Date(date.year ?? 1, date.month ?? 1, date.date ?? 1),+ );+}+function getCollectionSuggestion(searchPhrase: string,collections: Collection[],@@ -332,31 +341,6 @@ function searchFilesByCaption(searchPhrase: string, files: EnteFile[]) {);}-function parseHumanDate(humanDate: string): DateValue[] {- const date = chrono.parseDate(humanDate);- const date1 = chrono.parseDate(`${humanDate} 1`);- if (date !== null) {- const dates = [- { month: date.getMonth() },- { date: date.getDate(), month: date.getMonth() },- ];- let reverse = false;- humanDate.split("").forEach((c) => {- if (DIGITS.has(c)) {- reverse = true;- }- });- if (reverse) {- return dates.reverse();- }- return dates;- }- if (date1) {- return [{ month: date1.getMonth() }];- }- return [];-}-async function searchLocationTag(searchPhrase: string): Promise<LocationTag[]> {const locationTags = await getLatestEntities<LocationTagData>(EntityType.LOCATION_TAG,diff --git a/web/apps/photos/src/types/search/index.ts b/web/apps/photos/src/types/search/index.tsindex 5c9158958a..ffa26fdd5e 100644--- a/web/apps/photos/src/types/search/index.ts+++ b/web/apps/photos/src/types/search/index.ts@@ -1,6 +1,9 @@import { FileType } from "@/media/file-type";import type { MLStatus } from "@/new/photos/services/ml";-import type { SearchPerson } from "@/new/photos/services/search";+import type {+ DateValue,+ SearchPerson,+} from "@/new/photos/services/search/types";import { EnteFile } from "@/new/photos/types/file";import { City } from "services/locationSearchService";import { LocationTagData } from "types/entity";@@ -18,12 +21,6 @@ export enum SuggestionType {CITY = "CITY",}-export interface DateValue {- date?: number;- month?: number;- year?: number;-}-export interface Suggestion {type: SuggestionType;label: string;diff --git a/web/apps/photos/src/utils/search/index.ts b/web/apps/photos/src/utils/search/index.tsdeleted file mode 100644index 392211ca3e..0000000000--- a/web/apps/photos/src/utils/search/index.ts+++ /dev/null@@ -1,28 +0,0 @@-import { DateValue } from "types/search";--export const isSameDayAnyYear =- (baseDate: DateValue) => (compareDate: Date) => {- let same = true;-- if (baseDate.month || baseDate.month === 0) {- same = baseDate.month === compareDate.getMonth();- }- if (same && baseDate.date) {- same = baseDate.date === compareDate.getDate();- }- if (same && baseDate.year) {- same = baseDate.year === compareDate.getFullYear();- }-- return same;- };--export function getFormattedDate(date: DateValue) {- const options = {};- date.date && (options["day"] = "numeric");- (date.month || date.month === 0) && (options["month"] = "long");- date.year && (options["year"] = "numeric");- return new Intl.DateTimeFormat("en-IN", options).format(- new Date(date.year ?? 1, date.month ?? 1, date.date ?? 1),- );-}diff --git a/web/apps/photos/src/worker/search.worker.ts b/web/apps/photos/src/worker/search.worker.tsindex f81aecfb96..3f30216852 100644--- a/web/apps/photos/src/worker/search.worker.ts+++ b/web/apps/photos/src/worker/search.worker.ts@@ -1,3 +1,4 @@+import type { DateValue } from "@/new/photos/services/search/types";import { EnteFile } from "@/new/photos/types/file";import * as Comlink from "comlink";import {@@ -5,7 +6,6 @@ import {isInsideLocationTag,} from "services/locationSearchService";import { Search } from "types/search";-import { isSameDayAnyYear } from "utils/search";export class DedicatedSearchWorker {private files: EnteFile[] = [];@@ -65,3 +65,19 @@ function isSearchedFile(file: EnteFile, search: Search) {}return false;}++const isSameDayAnyYear = (baseDate: DateValue) => (compareDate: Date) => {+ let same = true;++ if (baseDate.month || baseDate.month === 0) {+ same = baseDate.month === compareDate.getMonth();+ }+ if (same && baseDate.date) {+ same = baseDate.date === compareDate.getDate();+ }+ if (same && baseDate.year) {+ same = baseDate.year === compareDate.getFullYear();+ }++ return same;+};diff --git a/web/packages/new/photos/services/search.ts b/web/packages/new/photos/services/search.tsdeleted file mode 100644index 587485d571..0000000000--- a/web/packages/new/photos/services/search.ts+++ /dev/null@@ -1,13 +0,0 @@-import type { EnteFile } from "@/new/photos/types/file";--/**- * A massaged version of {@link CGroup} suitable for being shown in search- * results.- */-export interface SearchPerson {- id: string;- name?: string;- files: number[];- displayFaceID: string;- displayFaceFile: EnteFile;-}diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.tsnew file mode 100644index 0000000000..b20256d932--- /dev/null+++ b/web/packages/new/photos/services/search/index.ts@@ -0,0 +1,30 @@+import * as chrono from "chrono-node";+import type { DateValue } from "./types";++const DIGITS = new Set(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);++export const parsePotentialDate = (humanDate: string): DateValue[] => {+ const date = chrono.parseDate(humanDate);+ const date1 = chrono.parseDate(`${humanDate} 1`);+ if (date !== null) {+ const dates = [+ { month: date.getMonth() },+ { date: date.getDate(), month: date.getMonth() },+ ];+ let reverse = false;+ humanDate.split("").forEach((c) => {+ if (DIGITS.has(c)) {+ reverse = true;+ }+ });+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition+ if (reverse) {+ return dates.reverse();+ }+ return dates;+ }+ if (date1) {+ return [{ month: date1.getMonth() }];+ }+ return [];+};diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.tsnew file mode 100644index 0000000000..924b7a78df--- /dev/null+++ b/web/packages/new/photos/services/search/types.ts@@ -0,0 +1,24 @@+/**+ * @file types shared between the main thread interface to search (`index.ts`)+ * and the search worker (`worker.ts`)+ */++import type { EnteFile } from "../../types/file";++export interface DateValue {+ date?: number;+ month?: number;+ year?: number;+}++/**+ * A massaged version of {@link CGroup} suitable for being shown in search+ * results.+ */+export interface SearchPerson {+ id: string;+ name?: string;+ files: number[];+ displayFaceID: string;+ displayFaceFile: EnteFile;+}