moved collection related types to types/collection

This commit is contained in:
Abhinav 2022-01-04 14:17:38 +05:30
parent 1a1c4d145c
commit 2aba5cb058
22 changed files with 122 additions and 113 deletions

View file

@ -7,14 +7,11 @@ import FormControl from 'react-bootstrap/FormControl';
import { Button, Col, Table } from 'react-bootstrap'; import { Button, Col, Table } from 'react-bootstrap';
import { DeadCenter } from 'pages/gallery'; import { DeadCenter } from 'pages/gallery';
import { User } from 'services/userService'; import { User } from 'services/userService';
import { import { shareCollection, unshareCollection } from 'services/collectionService';
Collection,
shareCollection,
unshareCollection,
} from 'services/collectionService';
import { getData, LS_KEYS } from 'utils/storage/localStorage'; import { getData, LS_KEYS } from 'utils/storage/localStorage';
import SubmitButton from './SubmitButton'; import SubmitButton from './SubmitButton';
import MessageDialog from './MessageDialog'; import MessageDialog from './MessageDialog';
import { Collection } from 'types/collection';
interface Props { interface Props {
show: boolean; show: boolean;

View file

@ -19,7 +19,7 @@ import LocationIcon from './icons/LocationIcon';
import DateIcon from './icons/DateIcon'; import DateIcon from './icons/DateIcon';
import SearchIcon from './icons/SearchIcon'; import SearchIcon from './icons/SearchIcon';
import CloseIcon from './icons/CloseIcon'; import CloseIcon from './icons/CloseIcon';
import { Collection } from 'services/collectionService'; import { Collection } from 'types/collection';
import CollectionIcon from './icons/CollectionIcon'; import CollectionIcon from './icons/CollectionIcon';
import { File, FILE_TYPE } from 'services/fileService'; import { File, FILE_TYPE } from 'services/fileService';
import ImageIcon from './icons/ImageIcon'; import ImageIcon from './icons/ImageIcon';

View file

@ -16,7 +16,7 @@ import {
} from 'utils/billing'; } from 'utils/billing';
import isElectron from 'is-electron'; import isElectron from 'is-electron';
import { Collection } from 'services/collectionService'; import { Collection } from 'types/collection';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import LinkButton from './pages/gallery/LinkButton'; import LinkButton from './pages/gallery/LinkButton';
import { downloadApp } from 'utils/common'; import { downloadApp } from 'utils/common';

View file

@ -1,16 +1,13 @@
import React from 'react'; import React from 'react';
import { SetDialogMessage } from 'components/MessageDialog'; import { SetDialogMessage } from 'components/MessageDialog';
import { ListGroup, Popover } from 'react-bootstrap'; import { ListGroup, Popover } from 'react-bootstrap';
import { import { deleteCollection, renameCollection } from 'services/collectionService';
Collection,
deleteCollection,
renameCollection,
} from 'services/collectionService';
import { downloadCollection, getSelectedCollection } from 'utils/collection'; import { downloadCollection, getSelectedCollection } from 'utils/collection';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import { SetCollectionNamerAttributes } from './CollectionNamer'; import { SetCollectionNamerAttributes } from './CollectionNamer';
import LinkButton, { ButtonVariant, LinkButtonProps } from './LinkButton'; import LinkButton, { ButtonVariant, LinkButtonProps } from './LinkButton';
import { sleep } from 'utils/common'; import { sleep } from 'utils/common';
import { Collection } from 'types/collection';
interface CollectionOptionsProps { interface CollectionOptionsProps {
syncWithRemote: () => Promise<void>; syncWithRemote: () => Promise<void>;

View file

@ -1,15 +1,16 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Card, Modal } from 'react-bootstrap'; import { Card, Modal } from 'react-bootstrap';
import styled from 'styled-components'; import styled from 'styled-components';
import { import {} from 'services/collectionService';
Collection,
CollectionAndItsLatestFile,
CollectionType,
} from 'services/collectionService';
import AddCollectionButton from './AddCollectionButton'; import AddCollectionButton from './AddCollectionButton';
import PreviewCard from './PreviewCard'; import PreviewCard from './PreviewCard';
import { getData, LS_KEYS } from 'utils/storage/localStorage'; import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { User } from 'services/userService'; import { User } from 'services/userService';
import {
Collection,
CollectionAndItsLatestFile,
CollectionType,
} from 'types/collection';
export const CollectionIcon = styled.div` export const CollectionIcon = styled.div`
width: 200px; width: 200px;

View file

@ -2,7 +2,7 @@ import { IconButton } from 'components/Container';
import SortIcon from 'components/icons/SortIcon'; import SortIcon from 'components/icons/SortIcon';
import React from 'react'; import React from 'react';
import { OverlayTrigger } from 'react-bootstrap'; import { OverlayTrigger } from 'react-bootstrap';
import { COLLECTION_SORT_BY } from 'services/collectionService'; import { COLLECTION_SORT_BY } from 'types/collection';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import CollectionSortOptions from './CollectionSortOptions'; import CollectionSortOptions from './CollectionSortOptions';
import { IconWithMessage } from './SelectedFileOptions'; import { IconWithMessage } from './SelectedFileOptions';

View file

@ -2,7 +2,7 @@ import { Value } from 'components/Container';
import TickIcon from 'components/icons/TickIcon'; import TickIcon from 'components/icons/TickIcon';
import React from 'react'; import React from 'react';
import { ListGroup, Popover, Row } from 'react-bootstrap'; import { ListGroup, Popover, Row } from 'react-bootstrap';
import { COLLECTION_SORT_BY } from 'services/collectionService'; import { COLLECTION_SORT_BY } from 'types/collection';
import styled from 'styled-components'; import styled from 'styled-components';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import { MenuItem, MenuLink } from './CollectionOptions'; import { MenuItem, MenuLink } from './CollectionOptions';

View file

@ -5,16 +5,16 @@ import NavigationButton, {
} from 'components/NavigationButton'; } from 'components/NavigationButton';
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import { OverlayTrigger, Tooltip } from 'react-bootstrap'; import { OverlayTrigger, Tooltip } from 'react-bootstrap';
import { import { sortCollections } from 'services/collectionService';
Collection,
CollectionAndItsLatestFile,
CollectionType,
COLLECTION_SORT_BY,
sortCollections,
} from 'services/collectionService';
import { User } from 'services/userService'; import { User } from 'services/userService';
import styled from 'styled-components'; import styled from 'styled-components';
import { IMAGE_CONTAINER_MAX_WIDTH } from 'types'; import { IMAGE_CONTAINER_MAX_WIDTH } from 'types';
import {
Collection,
CollectionAndItsLatestFile,
COLLECTION_SORT_BY,
CollectionType,
} from 'types/collection';
import { getSelectedCollection } from 'utils/collection'; import { getSelectedCollection } from 'utils/collection';
import { getData, LS_KEYS } from 'utils/storage/localStorage'; import { getData, LS_KEYS } from 'utils/storage/localStorage';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';

View file

@ -14,7 +14,7 @@ import { COLLECTION_OPS_TYPE } from 'utils/collection';
import { ALL_SECTION, ARCHIVE_SECTION, TRASH_SECTION } from './Collections'; import { ALL_SECTION, ARCHIVE_SECTION, TRASH_SECTION } from './Collections';
import UnArchive from 'components/icons/UnArchive'; import UnArchive from 'components/icons/UnArchive';
import { OverlayTrigger } from 'react-bootstrap'; import { OverlayTrigger } from 'react-bootstrap';
import { Collection } from 'services/collectionService'; import { Collection } from 'types/collection';
import RemoveIcon from 'components/icons/RemoveIcon'; import RemoveIcon from 'components/icons/RemoveIcon';
import RestoreIcon from 'components/icons/RestoreIcon'; import RestoreIcon from 'components/icons/RestoreIcon';
import ClockIcon from 'components/icons/ClockIcon'; import ClockIcon from 'components/icons/ClockIcon';

View file

@ -1,10 +1,6 @@
import React, { useContext, useEffect, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
import { import { syncCollections, createAlbum } from 'services/collectionService';
Collection,
syncCollections,
createAlbum,
} from 'services/collectionService';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import { SetDialogMessage } from 'components/MessageDialog'; import { SetDialogMessage } from 'components/MessageDialog';
import UploadProgress from './UploadProgress'; import UploadProgress from './UploadProgress';
@ -23,6 +19,7 @@ import UploadManager, {
import uploadManager from 'services/upload/uploadManager'; import uploadManager from 'services/upload/uploadManager';
import { METADATA_FOLDER_NAME } from 'services/exportService'; import { METADATA_FOLDER_NAME } from 'services/exportService';
import { getUserFacingErrorMessage } from 'utils/common/errorUtil'; import { getUserFacingErrorMessage } from 'utils/common/errorUtil';
import { Collection } from 'types/collection';
const FIRST_ALBUM_NAME = 'My First Album'; const FIRST_ALBUM_NAME = 'My First Album';

View file

@ -19,15 +19,12 @@ import {
import styled from 'styled-components'; import styled from 'styled-components';
import LoadingBar from 'react-top-loading-bar'; import LoadingBar from 'react-top-loading-bar';
import { import {
Collection,
syncCollections, syncCollections,
CollectionAndItsLatestFile,
getCollectionsAndTheirLatestFile, getCollectionsAndTheirLatestFile,
getFavItemIds, getFavItemIds,
getLocalCollections, getLocalCollections,
getNonEmptyCollections, getNonEmptyCollections,
createCollection, createCollection,
CollectionType,
} from 'services/collectionService'; } from 'services/collectionService';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import billingService from 'services/billingService'; import billingService from 'services/billingService';
@ -98,6 +95,11 @@ import DeleteBtn from 'components/DeleteBtn';
import FixCreationTime, { import FixCreationTime, {
FixCreationTimeAttributes, FixCreationTimeAttributes,
} from 'components/FixCreationTime'; } from 'components/FixCreationTime';
import {
Collection,
CollectionAndItsLatestFile,
CollectionType,
} from 'types/collection';
export const DeadCenter = styled.div` export const DeadCenter = styled.div`
flex: 1; flex: 1;

View file

@ -6,80 +6,28 @@ import { getActualKey, getToken } from 'utils/common/key';
import CryptoWorker from 'utils/crypto'; import CryptoWorker from 'utils/crypto';
import { SetDialogMessage } from 'components/MessageDialog'; import { SetDialogMessage } from 'components/MessageDialog';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import { getPublicKey, User } from './userService'; import { getPublicKey } from './userService';
import { B64EncryptionResult } from 'utils/crypto'; import { B64EncryptionResult } from 'utils/crypto';
import HTTPService from './HTTPService'; import HTTPService from './HTTPService';
import { File } from './fileService'; import { File } from './fileService';
import { logError } from 'utils/sentry'; import { logError } from 'utils/sentry';
import { CustomError } from 'utils/common/errorUtil'; import { CustomError } from 'utils/common/errorUtil';
import { sortFiles } from 'utils/file'; import { sortFiles } from 'utils/file';
import {
Collection,
COLLECTION_UPDATION_TIME,
COLLECTION_SORT_BY,
CollectionAndItsLatestFile,
CollectionType,
AddToCollectionRequest,
MoveToCollectionRequest,
EncryptedFileKey,
RemoveFromCollectionRequest,
COLLECTION_TABLE,
} from 'types/collection';
const ENDPOINT = getEndpoint(); const ENDPOINT = getEndpoint();
export enum CollectionType {
folder = 'folder',
favorites = 'favorites',
album = 'album',
}
const COLLECTION_UPDATION_TIME = 'collection-updation-time';
const COLLECTIONS = 'collections';
export interface Collection {
id: number;
owner: User;
key?: string;
name?: string;
encryptedName?: string;
nameDecryptionNonce?: string;
type: CollectionType;
attributes: collectionAttributes;
sharees: User[];
updationTime: number;
encryptedKey: string;
keyDecryptionNonce: string;
isDeleted: boolean;
isSharedCollection?: boolean;
}
interface EncryptedFileKey {
id: number;
encryptedKey: string;
keyDecryptionNonce: string;
}
interface AddToCollectionRequest {
collectionID: number;
files: EncryptedFileKey[];
}
interface MoveToCollectionRequest {
fromCollectionID: number;
toCollectionID: number;
files: EncryptedFileKey[];
}
interface collectionAttributes {
encryptedPath?: string;
pathDecryptionNonce?: string;
}
export interface CollectionAndItsLatestFile {
collection: Collection;
file: File;
}
export enum COLLECTION_SORT_BY {
LATEST_FILE,
MODIFICATION_TIME,
NAME,
}
interface RemoveFromCollectionRequest {
collectionID: number;
fileIDs: number[];
}
const getCollectionWithSecrets = async ( const getCollectionWithSecrets = async (
collection: Collection, collection: Collection,
masterKey: string masterKey: string
@ -164,7 +112,7 @@ const getCollections = async (
export const getLocalCollections = async (): Promise<Collection[]> => { export const getLocalCollections = async (): Promise<Collection[]> => {
const collections: Collection[] = const collections: Collection[] =
(await localForage.getItem(COLLECTIONS)) ?? []; (await localForage.getItem(COLLECTION_TABLE)) ?? [];
return collections; return collections;
}; };
@ -212,7 +160,7 @@ export const syncCollections = async () => {
[], [],
COLLECTION_SORT_BY.MODIFICATION_TIME COLLECTION_SORT_BY.MODIFICATION_TIME
); );
await localForage.setItem(COLLECTIONS, collections); await localForage.setItem(COLLECTION_TABLE, collections);
await localForage.setItem(COLLECTION_UPDATION_TIME, updationTime); await localForage.setItem(COLLECTION_UPDATION_TIME, updationTime);
return collections; return collections;
}; };
@ -365,7 +313,7 @@ export const addToFavorites = async (file: File) => {
CollectionType.favorites CollectionType.favorites
); );
const localCollections = await getLocalCollections(); const localCollections = await getLocalCollections();
await localForage.setItem(COLLECTIONS, [ await localForage.setItem(COLLECTION_TABLE, [
...localCollections, ...localCollections,
favCollection, favCollection,
]); ]);

View file

@ -23,7 +23,6 @@ import { retryAsyncFunction } from 'utils/network';
import { logError } from 'utils/sentry'; import { logError } from 'utils/sentry';
import { getData, LS_KEYS } from 'utils/storage/localStorage'; import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { import {
Collection,
getLocalCollections, getLocalCollections,
getNonEmptyCollections, getNonEmptyCollections,
} from './collectionService'; } from './collectionService';
@ -42,6 +41,7 @@ import { User } from './userService';
import { updateFileCreationDateInEXIF } from './upload/exifService'; import { updateFileCreationDateInEXIF } from './upload/exifService';
import { MetadataObject } from 'types/upload'; import { MetadataObject } from 'types/upload';
import QueueProcessor from './upload/queueProcessor'; import QueueProcessor from './upload/queueProcessor';
import { Collection } from 'types/collection';
export type CollectionIDPathMap = Map<number, string>; export type CollectionIDPathMap = Map<number, string>;
export interface ExportProgress { export interface ExportProgress {

View file

@ -3,7 +3,7 @@ import localForage from 'utils/storage/localForage';
import { getToken } from 'utils/common/key'; import { getToken } from 'utils/common/key';
import { DataStream, EncryptionResult, MetadataObject } from 'types/upload'; import { DataStream, EncryptionResult, MetadataObject } from 'types/upload';
import { Collection } from './collectionService'; import { Collection } from 'types/collection';
import HTTPService from './HTTPService'; import HTTPService from './HTTPService';
import { logError } from 'utils/sentry'; import { logError } from 'utils/sentry';
import { decryptFile, mergeMetadata, sortFiles } from 'utils/file'; import { decryptFile, mergeMetadata, sortFiles } from 'utils/file';

View file

@ -3,7 +3,7 @@ import { getEndpoint } from 'utils/common/apiUtil';
import { getToken } from 'utils/common/key'; import { getToken } from 'utils/common/key';
import { DateValue, Suggestion, SuggestionType } from 'components/SearchBar'; import { DateValue, Suggestion, SuggestionType } from 'components/SearchBar';
import HTTPService from './HTTPService'; import HTTPService from './HTTPService';
import { Collection } from './collectionService'; import { Collection } from 'types/collection';
import { File } from './fileService'; import { File } from './fileService';
import { logError } from 'utils/sentry'; import { logError } from 'utils/sentry';

View file

@ -1,10 +1,11 @@
import { SetFiles } from 'pages/gallery'; import { SetFiles } from 'pages/gallery';
import { Collection } from 'types/collection';
import { getEndpoint } from 'utils/common/apiUtil'; import { getEndpoint } from 'utils/common/apiUtil';
import { getToken } from 'utils/common/key'; import { getToken } from 'utils/common/key';
import { decryptFile, mergeMetadata, sortFiles } from 'utils/file'; import { decryptFile, mergeMetadata, sortFiles } from 'utils/file';
import { logError } from 'utils/sentry'; import { logError } from 'utils/sentry';
import localForage from 'utils/storage/localForage'; import localForage from 'utils/storage/localForage';
import { Collection, getCollection } from './collectionService'; import { getCollection } from './collectionService';
import { File } from './fileService'; import { File } from './fileService';
import HTTPService from './HTTPService'; import HTTPService from './HTTPService';

View file

@ -1,5 +1,5 @@
import { File, getLocalFiles, setLocalFiles } from '../fileService'; import { File, getLocalFiles, setLocalFiles } from '../fileService';
import { Collection, getLocalCollections } from '../collectionService'; import { getLocalCollections } from '../collectionService';
import { SetFiles } from 'pages/gallery'; import { SetFiles } from 'pages/gallery';
import { ComlinkWorker, getDedicatedCryptoWorker } from 'utils/crypto'; import { ComlinkWorker, getDedicatedCryptoWorker } from 'utils/crypto';
import { import {
@ -19,6 +19,7 @@ import uploader from './uploader';
import UIService from './uiService'; import UIService from './uiService';
import UploadService from './uploadService'; import UploadService from './uploadService';
import { CustomError } from 'utils/common/errorUtil'; import { CustomError } from 'utils/common/errorUtil';
import { Collection } from 'types/collection';
const MAX_CONCURRENT_UPLOADS = 4; const MAX_CONCURRENT_UPLOADS = 4;
const FILE_UPLOAD_COMPLETED = 100; const FILE_UPLOAD_COMPLETED = 100;

View file

@ -1,5 +1,5 @@
import { fileAttribute } from '../fileService'; import { fileAttribute } from '../fileService';
import { Collection } from '../collectionService'; import { Collection } from 'types/collection';
import { logError } from 'utils/sentry'; import { logError } from 'utils/sentry';
import UploadHttpClient from './uploadHttpClient'; import UploadHttpClient from './uploadHttpClient';
import { import {

View file

@ -0,0 +1,66 @@
import { User } from 'services/userService';
import { File } from 'services/fileService';
export const COLLECTION_UPDATION_TIME = 'collection-updation-time';
export const COLLECTION_TABLE = 'collections';
export enum CollectionType {
folder = 'folder',
favorites = 'favorites',
album = 'album',
}
export interface Collection {
id: number;
owner: User;
key?: string;
name?: string;
encryptedName?: string;
nameDecryptionNonce?: string;
type: CollectionType;
attributes: collectionAttributes;
sharees: User[];
updationTime: number;
encryptedKey: string;
keyDecryptionNonce: string;
isDeleted: boolean;
isSharedCollection?: boolean;
}
export interface EncryptedFileKey {
id: number;
encryptedKey: string;
keyDecryptionNonce: string;
}
export interface AddToCollectionRequest {
collectionID: number;
files: EncryptedFileKey[];
}
export interface MoveToCollectionRequest {
fromCollectionID: number;
toCollectionID: number;
files: EncryptedFileKey[];
}
export interface collectionAttributes {
encryptedPath?: string;
pathDecryptionNonce?: string;
}
export interface CollectionAndItsLatestFile {
collection: Collection;
file: File;
}
export enum COLLECTION_SORT_BY {
LATEST_FILE,
MODIFICATION_TIME,
NAME,
}
export interface RemoveFromCollectionRequest {
collectionID: number;
fileIDs: number[];
}

View file

@ -1,7 +1,5 @@
import { import {
addToCollection, addToCollection,
Collection,
CollectionType,
moveToCollection, moveToCollection,
removeFromCollection, removeFromCollection,
restoreToCollection, restoreToCollection,
@ -15,6 +13,7 @@ import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { SetDialogMessage } from 'components/MessageDialog'; import { SetDialogMessage } from 'components/MessageDialog';
import { logError } from 'utils/sentry'; import { logError } from 'utils/sentry';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import { Collection, CollectionType } from 'types/collection';
export enum COLLECTION_OPS_TYPE { export enum COLLECTION_OPS_TYPE {
ADD, ADD,

View file

@ -1,4 +1,4 @@
import { Collection } from 'services/collectionService'; import { Collection } from 'types/collection';
import exportService, { import exportService, {
CollectionIDPathMap, CollectionIDPathMap,
ExportRecord, ExportRecord,

View file

@ -1,5 +1,5 @@
import { SelectedState } from 'pages/gallery'; import { SelectedState } from 'pages/gallery';
import { Collection } from 'services/collectionService'; import { Collection } from 'types/collection';
import { import {
File, File,
fileAttribute, fileAttribute,