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 { DeadCenter } from 'pages/gallery';
import { User } from 'services/userService';
import {
Collection,
shareCollection,
unshareCollection,
} from 'services/collectionService';
import { shareCollection, unshareCollection } from 'services/collectionService';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
import SubmitButton from './SubmitButton';
import MessageDialog from './MessageDialog';
import { Collection } from 'types/collection';
interface Props {
show: boolean;

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@ import { IconButton } from 'components/Container';
import SortIcon from 'components/icons/SortIcon';
import React from 'react';
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 CollectionSortOptions from './CollectionSortOptions';
import { IconWithMessage } from './SelectedFileOptions';

View file

@ -2,7 +2,7 @@ import { Value } from 'components/Container';
import TickIcon from 'components/icons/TickIcon';
import React from 'react';
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 constants from 'utils/strings/constants';
import { MenuItem, MenuLink } from './CollectionOptions';

View file

@ -5,16 +5,16 @@ import NavigationButton, {
} from 'components/NavigationButton';
import React, { useEffect, useRef, useState } from 'react';
import { OverlayTrigger, Tooltip } from 'react-bootstrap';
import {
Collection,
CollectionAndItsLatestFile,
CollectionType,
COLLECTION_SORT_BY,
sortCollections,
} from 'services/collectionService';
import { sortCollections } from 'services/collectionService';
import { User } from 'services/userService';
import styled from 'styled-components';
import { IMAGE_CONTAINER_MAX_WIDTH } from 'types';
import {
Collection,
CollectionAndItsLatestFile,
COLLECTION_SORT_BY,
CollectionType,
} from 'types/collection';
import { getSelectedCollection } from 'utils/collection';
import { getData, LS_KEYS } from 'utils/storage/localStorage';
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 UnArchive from 'components/icons/UnArchive';
import { OverlayTrigger } from 'react-bootstrap';
import { Collection } from 'services/collectionService';
import { Collection } from 'types/collection';
import RemoveIcon from 'components/icons/RemoveIcon';
import RestoreIcon from 'components/icons/RestoreIcon';
import ClockIcon from 'components/icons/ClockIcon';

View file

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

View file

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

View file

@ -6,80 +6,28 @@ import { getActualKey, getToken } from 'utils/common/key';
import CryptoWorker from 'utils/crypto';
import { SetDialogMessage } from 'components/MessageDialog';
import constants from 'utils/strings/constants';
import { getPublicKey, User } from './userService';
import { getPublicKey } from './userService';
import { B64EncryptionResult } from 'utils/crypto';
import HTTPService from './HTTPService';
import { File } from './fileService';
import { logError } from 'utils/sentry';
import { CustomError } from 'utils/common/errorUtil';
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();
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 (
collection: Collection,
masterKey: string
@ -164,7 +112,7 @@ const getCollections = async (
export const getLocalCollections = async (): Promise<Collection[]> => {
const collections: Collection[] =
(await localForage.getItem(COLLECTIONS)) ?? [];
(await localForage.getItem(COLLECTION_TABLE)) ?? [];
return collections;
};
@ -212,7 +160,7 @@ export const syncCollections = async () => {
[],
COLLECTION_SORT_BY.MODIFICATION_TIME
);
await localForage.setItem(COLLECTIONS, collections);
await localForage.setItem(COLLECTION_TABLE, collections);
await localForage.setItem(COLLECTION_UPDATION_TIME, updationTime);
return collections;
};
@ -365,7 +313,7 @@ export const addToFavorites = async (file: File) => {
CollectionType.favorites
);
const localCollections = await getLocalCollections();
await localForage.setItem(COLLECTIONS, [
await localForage.setItem(COLLECTION_TABLE, [
...localCollections,
favCollection,
]);

View file

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

View file

@ -3,7 +3,7 @@ import localForage from 'utils/storage/localForage';
import { getToken } from 'utils/common/key';
import { DataStream, EncryptionResult, MetadataObject } from 'types/upload';
import { Collection } from './collectionService';
import { Collection } from 'types/collection';
import HTTPService from './HTTPService';
import { logError } from 'utils/sentry';
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 { DateValue, Suggestion, SuggestionType } from 'components/SearchBar';
import HTTPService from './HTTPService';
import { Collection } from './collectionService';
import { Collection } from 'types/collection';
import { File } from './fileService';
import { logError } from 'utils/sentry';

View file

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

View file

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

View file

@ -1,5 +1,5 @@
import { fileAttribute } from '../fileService';
import { Collection } from '../collectionService';
import { Collection } from 'types/collection';
import { logError } from 'utils/sentry';
import UploadHttpClient from './uploadHttpClient';
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 {
addToCollection,
Collection,
CollectionType,
moveToCollection,
removeFromCollection,
restoreToCollection,
@ -15,6 +13,7 @@ import { getData, LS_KEYS } from 'utils/storage/localStorage';
import { SetDialogMessage } from 'components/MessageDialog';
import { logError } from 'utils/sentry';
import constants from 'utils/strings/constants';
import { Collection, CollectionType } from 'types/collection';
export enum COLLECTION_OPS_TYPE {
ADD,

View file

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

View file

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