From 45567fe972e6695efb37c65dcef734c771b97edc Mon Sep 17 00:00:00 2001 From: Thibaut Sardan Date: Mon, 27 Sep 2021 15:14:02 +0200 Subject: [PATCH] run lint --fix --- .eslintrc.json | 2 +- .../common-components/src/Icons/types.d.ts | 2 +- .../src/MenuDropdown/MenuDropdown.tsx | 12 +- .../src/Typography/Typography.tsx | 24 +-- .../src/stories/Typography.stories.tsx | 22 +-- .../src/Create/CreateBreakpoints.ts | 26 +-- .../common-theme/src/Hooks/useDoubleClick.ts | 12 +- .../src/Components/Elements/MnemonicForm.tsx | 4 +- .../Elements/ShareTransferRequestModal.tsx | 2 +- .../src/Components/Elements/SharedUsers.tsx | 2 +- .../FileBrowsers/SharedFileBrowser.tsx | 62 +++---- .../Modules/FileBrowsers/views/FilesList.tsx | 56 +++--- .../Modules/LoginModule/InitializeAccount.tsx | 26 +-- .../src/Components/SharingExplainerModal.tsx | 104 +++++------ .../files-ui/src/Components/SurveyBanner.tsx | 2 +- .../files-ui/src/Contexts/FilesApiContext.tsx | 2 +- .../files-ui/src/Contexts/FilesContext.tsx | 18 +- .../src/Contexts/ThresholdKeyContext.tsx | 56 +++--- packages/files-ui/src/Themes/Constants.ts | 2 +- packages/files-ui/src/UI-components/Menu.tsx | 20 +- packages/files-ui/src/Utils/MimeMatcher.ts | 60 +++--- .../files-ui/src/Utils/contentTypeGuesser.ts | 38 ++-- .../src/Components/Elements/SecretField.tsx | 2 +- .../src/Contexts/GamingApiContext.tsx | 62 +++---- packages/gaming-ui/src/Themes/Constants.ts | 2 +- .../src/Components/Elements/CidRow.tsx | 2 +- .../src/Components/Elements/SecretField.tsx | 4 +- .../Modules/FilesList/FilesList.tsx | 38 ++-- .../src/Components/Modules/SurveyBanner.tsx | 2 +- .../src/Components/Pages/CidsPage.tsx | 16 +- .../src/Contexts/FileOperationsReducers.tsx | 172 +++++++++--------- .../src/Contexts/StorageApiContext.tsx | 62 +++---- packages/storage-ui/src/Themes/Constants.ts | 2 +- packages/storage-ui/src/Utils/MimeMatcher.ts | 60 +++--- .../src/Utils/contentTypeGuesser.ts | 36 ++-- 35 files changed, 507 insertions(+), 507 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 210af778d3..d046b33919 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,7 +25,7 @@ "rules": { "comma-spacing": ["error", { "before": false, "after": true }], "cypress/no-pause": "error", - "indent": ["error", 2], + "@typescript-eslint/indent": ["error", 2], "linebreak-style": ["error", "unix"], "quotes": ["error", "double"], "semi": ["error", "never"], diff --git a/packages/common-components/src/Icons/types.d.ts b/packages/common-components/src/Icons/types.d.ts index af2915b8ae..6a6c6adddb 100644 --- a/packages/common-components/src/Icons/types.d.ts +++ b/packages/common-components/src/Icons/types.d.ts @@ -4,7 +4,7 @@ type fontSizeProp = "inherit" | "small" | "medium" | "large" declare module "*.svg" { import React = require("react") export const ReactComponent: React.FunctionComponent> const src: string export default src diff --git a/packages/common-components/src/MenuDropdown/MenuDropdown.tsx b/packages/common-components/src/MenuDropdown/MenuDropdown.tsx index eaffb61646..f42b97f24a 100644 --- a/packages/common-components/src/MenuDropdown/MenuDropdown.tsx +++ b/packages/common-components/src/MenuDropdown/MenuDropdown.tsx @@ -162,12 +162,12 @@ interface IMenuDropdownProps { indicator?: typeof SvgIcon animation?: "rotate" | "flip" | "none" anchor?: - | "top-left" - | "top-center" - | "top-right" - | "bottom-left" - | "bottom-center" - | "bottom-right" + | "top-left" + | "top-center" + | "top-right" + | "bottom-left" + | "bottom-center" + | "bottom-right" menuItems: IMenuItem[] title?: string classNames?: { diff --git a/packages/common-components/src/Typography/Typography.tsx b/packages/common-components/src/Typography/Typography.tsx index cae0cd156e..31e1b025cc 100644 --- a/packages/common-components/src/Typography/Typography.tsx +++ b/packages/common-components/src/Typography/Typography.tsx @@ -78,18 +78,18 @@ interface OwnProps extends React.HTMLProps { className?: string children?: ReactNode | ReactNode[] variant?: - | "h1" - | "h2" - | "h3" - | "h4" - | "h5" - | "h6" - | "subtitle1" - | "subtitle2" - | "body1" - | "body2" - | "caption" - | "button" + | "h1" + | "h2" + | "h3" + | "h4" + | "h5" + | "h6" + | "subtitle1" + | "subtitle2" + | "body1" + | "body2" + | "caption" + | "button" component?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "span" | "p" } diff --git a/packages/common-components/src/stories/Typography.stories.tsx b/packages/common-components/src/stories/Typography.stories.tsx index 4ad36e0e58..51c271d7e0 100644 --- a/packages/common-components/src/stories/Typography.stories.tsx +++ b/packages/common-components/src/stories/Typography.stories.tsx @@ -15,17 +15,17 @@ export const actionsData = { } type VariantOption = "h1" - |"h2" - |"h3" - |"h4" - |"h5" - |"h6" - |"subtitle1" - |"subtitle2" - |"body1" - |"body2" - |"caption" - |"button" +|"h2" +|"h3" +|"h4" +|"h5" +|"h6" +|"subtitle1" +|"subtitle2" +|"body1" +|"body2" +|"caption" +|"button" const variantOptions: VariantOption[] = [ "h1", diff --git a/packages/common-theme/src/Create/CreateBreakpoints.ts b/packages/common-theme/src/Create/CreateBreakpoints.ts index 3cb7901e33..42ce306827 100644 --- a/packages/common-theme/src/Create/CreateBreakpoints.ts +++ b/packages/common-theme/src/Create/CreateBreakpoints.ts @@ -6,10 +6,10 @@ export type Overwrite = Omit & U type GenerateStringUnion = Extract< - { - [Key in keyof T]: true extends T[Key] ? Key : never - }[keyof T], - string +{ + [Key in keyof T]: true extends T[Key] ? Key : never +}[keyof T], +string > /** @@ -22,18 +22,18 @@ type GenerateStringUnion = Extract< * @internal */ export type OverridableStringUnion> = GenerateStringUnion< - Overwrite +Overwrite > export type BreakpointDefaults = Record< - "xs" | "sm" | "md" | "lg" | "xl" | string, - true +"xs" | "sm" | "md" | "lg" | "xl" | string, +true > export interface BreakpointOverrides {[key: string]: unknown} export type Breakpoint = OverridableStringUnion< - BreakpointDefaults, - BreakpointOverrides +BreakpointDefaults, +BreakpointOverrides > export type BreakpointValues = { [key in Breakpoint]: number } export const keys: Breakpoint[] = [] @@ -49,10 +49,10 @@ export interface IBreakpoints { } export type BreakpointsOptions = Partial< - { - unit: string - step: number - } & IBreakpoints +{ + unit: string + step: number +} & IBreakpoints > // Keep in mind that @media is inclusive by the CSS specification. diff --git a/packages/common-theme/src/Hooks/useDoubleClick.ts b/packages/common-theme/src/Hooks/useDoubleClick.ts index 32ae768923..38ae8c1eb5 100644 --- a/packages/common-theme/src/Hooks/useDoubleClick.ts +++ b/packages/common-theme/src/Hooks/useDoubleClick.ts @@ -9,12 +9,12 @@ export function useDoubleClick( const onClick = useCallback((e?: React.MouseEvent) => { if (e) { switch (e.detail) { - case 1: - actionSingleClick && actionSingleClick(e) - break - case 2: - actionDoubleClick && actionDoubleClick(e) - break + case 1: + actionSingleClick && actionSingleClick(e) + break + case 2: + actionDoubleClick && actionDoubleClick(e) + break } } }, [actionSingleClick, actionDoubleClick]) diff --git a/packages/files-ui/src/Components/Elements/MnemonicForm.tsx b/packages/files-ui/src/Components/Elements/MnemonicForm.tsx index ae064dfca4..31e95cf972 100644 --- a/packages/files-ui/src/Components/Elements/MnemonicForm.tsx +++ b/packages/files-ui/src/Components/Elements/MnemonicForm.tsx @@ -92,8 +92,8 @@ const useStyles = makeStyles(({ animation, constants, palette, zIndex }: CSFThem ) interface Props { - buttonLabel?: string - onComplete: () => void + buttonLabel?: string + onComplete: () => void } const MnemonicForm = ({ buttonLabel, onComplete }: Props) => { diff --git a/packages/files-ui/src/Components/Elements/ShareTransferRequestModal.tsx b/packages/files-ui/src/Components/Elements/ShareTransferRequestModal.tsx index dab63e66ad..61c2a6094b 100644 --- a/packages/files-ui/src/Components/Elements/ShareTransferRequestModal.tsx +++ b/packages/files-ui/src/Components/Elements/ShareTransferRequestModal.tsx @@ -10,7 +10,7 @@ import clsx from "clsx" import { CSFTheme } from "../../Themes/types" interface Props { - requests: ShareTransferRequest[] + requests: ShareTransferRequest[] } const useStyles = makeStyles(({ constants }: CSFTheme) => diff --git a/packages/files-ui/src/Components/Elements/SharedUsers.tsx b/packages/files-ui/src/Components/Elements/SharedUsers.tsx index 30d44bfbda..6ea07668bb 100644 --- a/packages/files-ui/src/Components/Elements/SharedUsers.tsx +++ b/packages/files-ui/src/Components/Elements/SharedUsers.tsx @@ -12,7 +12,7 @@ const useStyles = makeStyles(() => { }) }) interface Props { - bucket: BucketKeyPermission + bucket: BucketKeyPermission } const SharedUsers = ({ bucket }: Props) => { diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFileBrowser.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFileBrowser.tsx index 2697dd1b98..f061203da6 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFileBrowser.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFileBrowser.tsx @@ -204,37 +204,37 @@ const SharedFileBrowser = () => { const itemOperations: IFilesTableBrowserProps["itemOperations"] = useMemo(() => { switch (access) { - case "owner": - return { - [CONTENT_TYPES.Audio]: ["preview"], - [CONTENT_TYPES.MP4]: ["preview"], - [CONTENT_TYPES.Image]: ["preview"], - [CONTENT_TYPES.Pdf]: ["preview"], - [CONTENT_TYPES.Text]: ["preview"], - [CONTENT_TYPES.File]: ["download", "info", "rename", "move", "delete", "share"], - [CONTENT_TYPES.Directory]: ["rename", "move", "delete"] - } - case "writer": - return { - [CONTENT_TYPES.Audio]: ["preview"], - [CONTENT_TYPES.MP4]: ["preview"], - [CONTENT_TYPES.Image]: ["preview"], - [CONTENT_TYPES.Pdf]: ["preview"], - [CONTENT_TYPES.Text]: ["preview"], - [CONTENT_TYPES.File]: ["download", "info", "rename", "move", "delete", "report", "share"], - [CONTENT_TYPES.Directory]: ["rename", "move", "delete"] - } - // case "reader": - default: - return { - [CONTENT_TYPES.Audio]: ["preview"], - [CONTENT_TYPES.MP4]: ["preview"], - [CONTENT_TYPES.Image]: ["preview"], - [CONTENT_TYPES.Pdf]: ["preview"], - [CONTENT_TYPES.Text]: ["preview"], - [CONTENT_TYPES.File]: ["download", "info", "report", "share"], - [CONTENT_TYPES.Directory]: [] - } + case "owner": + return { + [CONTENT_TYPES.Audio]: ["preview"], + [CONTENT_TYPES.MP4]: ["preview"], + [CONTENT_TYPES.Image]: ["preview"], + [CONTENT_TYPES.Pdf]: ["preview"], + [CONTENT_TYPES.Text]: ["preview"], + [CONTENT_TYPES.File]: ["download", "info", "rename", "move", "delete", "share"], + [CONTENT_TYPES.Directory]: ["rename", "move", "delete"] + } + case "writer": + return { + [CONTENT_TYPES.Audio]: ["preview"], + [CONTENT_TYPES.MP4]: ["preview"], + [CONTENT_TYPES.Image]: ["preview"], + [CONTENT_TYPES.Pdf]: ["preview"], + [CONTENT_TYPES.Text]: ["preview"], + [CONTENT_TYPES.File]: ["download", "info", "rename", "move", "delete", "report", "share"], + [CONTENT_TYPES.Directory]: ["rename", "move", "delete"] + } + // case "reader": + default: + return { + [CONTENT_TYPES.Audio]: ["preview"], + [CONTENT_TYPES.MP4]: ["preview"], + [CONTENT_TYPES.Image]: ["preview"], + [CONTENT_TYPES.Pdf]: ["preview"], + [CONTENT_TYPES.Text]: ["preview"], + [CONTENT_TYPES.File]: ["download", "info", "report", "share"], + [CONTENT_TYPES.Directory]: [] + } } }, [access]) diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FilesList.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FilesList.tsx index e46746314f..e90732029b 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FilesList.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FilesList.tsx @@ -356,26 +356,26 @@ const FilesList = ({ isShared = false }: Props) => { switch (column) { // defaults to name sorting - default: { - temp = sourceFiles.sort((a, b) => { - return a.name.localeCompare(b.name, selectedLocale, { - sensitivity: "base" + default: { + temp = sourceFiles.sort((a, b) => { + return a.name.localeCompare(b.name, selectedLocale, { + sensitivity: "base" + }) }) - }) - break - } - case "size": { - temp = sourceFiles - .sort((a, b) => (a.size < b.size ? -1 : 1)) - .sort(sortFoldersFirst) - break - } - case "date_uploaded": { - temp = sourceFiles - .sort((a, b) => (a.created_at < b.created_at ? -1 : 1)) - .sort(sortFoldersFirst) - break - } + break + } + case "size": { + temp = sourceFiles + .sort((a, b) => (a.size < b.size ? -1 : 1)) + .sort(sortFoldersFirst) + break + } + case "date_uploaded": { + temp = sourceFiles + .sort((a, b) => (a.created_at < b.created_at ? -1 : 1)) + .sort(sortFoldersFirst) + break + } } return direction === "descend" ? temp.reverse().sort(sortFoldersFirst) @@ -501,15 +501,15 @@ const FilesList = ({ isShared = false }: Props) => { if (!!permission && isShared) { switch(permission) { - case "owner": - fileOperations = ownerOperations - break - case "writer": - fileOperations = writerOperations - break - case "reader": - fileOperations = readerOperations - break + case "owner": + fileOperations = ownerOperations + break + case "writer": + fileOperations = writerOperations + break + case "reader": + fileOperations = readerOperations + break } } diff --git a/packages/files-ui/src/Components/Modules/LoginModule/InitializeAccount.tsx b/packages/files-ui/src/Components/Modules/LoginModule/InitializeAccount.tsx index f9aa2c18f4..cca6d89394 100644 --- a/packages/files-ui/src/Components/Modules/LoginModule/InitializeAccount.tsx +++ b/packages/files-ui/src/Components/Modules/LoginModule/InitializeAccount.tsx @@ -22,19 +22,19 @@ const InitializeAccount = ({ className }: IInitializeAccount) => { , [addPasswordShare, resetShouldInitialize]) switch (initializeState) { - case "explainer": - return setInitializeState("setUpPassword")} - /> - case "setUpPassword": - return setInitializeState("explainer")} - setPassword={onSetPassword} - /> - default: - return null + case "explainer": + return setInitializeState("setUpPassword")} + /> + case "setUpPassword": + return setInitializeState("explainer")} + setPassword={onSetPassword} + /> + default: + return null } } diff --git a/packages/files-ui/src/Components/SharingExplainerModal.tsx b/packages/files-ui/src/Components/SharingExplainerModal.tsx index b343186713..05e9544503 100644 --- a/packages/files-ui/src/Components/SharingExplainerModal.tsx +++ b/packages/files-ui/src/Components/SharingExplainerModal.tsx @@ -68,8 +68,8 @@ const useStyles = makeStyles( }) interface Props { - showModal: boolean - onHide: () => void + showModal: boolean + onHide: () => void } const STEP_NUMBER = 3 @@ -80,49 +80,49 @@ const SharingExplainerModal = ({ showModal, onHide }: Props) => { const [step, setStep] = useState(1) const Slides = useCallback(() => { switch (step) { - default: - return <> -
- You can now create shared folders to share a file.
-
- {"share -
- + default: + return <> +
+ You can now create shared folders to share a file.
+
+ {"share +
+ - case 2: - return <> -
Add viewers and editors by username, sharing id or Ethereum address.
-
- {"share -
- + case 2: + return <> +
Add viewers and editors by username, sharing id or Ethereum address.
+
+ {"share +
+ - case 3: - return <> -
- Create your public username in Settings! - -
-
- {"share -
- + case 3: + return <> +
+ Create your public username in Settings! + +
+
+ {"share +
+ } }, [classes.buttonLink, classes.image, classes.imageContainer, classes.title, step]) @@ -132,15 +132,15 @@ const SharingExplainerModal = ({ showModal, onHide }: Props) => { return } else { switch (next) { - case 3: - localStorageSet(DISMISSED_SHARING_EXPLAINER_KEY, "true") - setStep(3) - break - case STEP_NUMBER + 1: - onHide() - break - default: - break + case 3: + localStorageSet(DISMISSED_SHARING_EXPLAINER_KEY, "true") + setStep(3) + break + case STEP_NUMBER + 1: + onHide() + break + default: + break } } }, [localStorageSet, onHide]) diff --git a/packages/files-ui/src/Components/SurveyBanner.tsx b/packages/files-ui/src/Components/SurveyBanner.tsx index ea2cc52334..ed5ee8c4f0 100644 --- a/packages/files-ui/src/Components/SurveyBanner.tsx +++ b/packages/files-ui/src/Components/SurveyBanner.tsx @@ -50,7 +50,7 @@ const useStyles = makeStyles( }) interface Props { - onHide: () => void + onHide: () => void } const SurveyBanner = ({ onHide }: Props) => { diff --git a/packages/files-ui/src/Contexts/FilesApiContext.tsx b/packages/files-ui/src/Contexts/FilesApiContext.tsx index c438838790..9f8286cd52 100644 --- a/packages/files-ui/src/Contexts/FilesApiContext.tsx +++ b/packages/files-ui/src/Contexts/FilesApiContext.tsx @@ -64,7 +64,7 @@ const FilesApiProvider = ({ apiUrl, withLocalStorage = true, children }: FilesAp const [secured, setSecured] = useState(undefined) const [refreshToken, setRefreshToken] = useState(undefined) const [decodedRefreshToken, setDecodedRefreshToken] = useState< - { exp: number; enckey?: string; mps?: string; uuid: string } | undefined + { exp: number; enckey?: string; mps?: string; uuid: string } | undefined >(undefined) // returning user diff --git a/packages/files-ui/src/Contexts/FilesContext.tsx b/packages/files-ui/src/Contexts/FilesContext.tsx index 732899178a..8aeb8158a2 100644 --- a/packages/files-ui/src/Contexts/FilesContext.tsx +++ b/packages/files-ui/src/Contexts/FilesContext.tsx @@ -160,15 +160,15 @@ const FilesProvider = ({ children }: FilesContextProps) => { let encryptionKey = "" switch(bucket.type) { - case "csf": - case "trash": { - encryptionKey = personalEncryptionKey - break - } - case "share": { - encryptionKey = await getKeyForSharedBucket(bucket) - break - }} + case "csf": + case "trash": { + encryptionKey = personalEncryptionKey + break + } + case "share": { + encryptionKey = await getKeyForSharedBucket(bucket) + break + }} return encryptionKey }, [getKeyForSharedBucket, personalEncryptionKey, userId]) diff --git a/packages/files-ui/src/Contexts/ThresholdKeyContext.tsx b/packages/files-ui/src/Contexts/ThresholdKeyContext.tsx index 086bb98118..9ee4afe2fb 100644 --- a/packages/files-ui/src/Contexts/ThresholdKeyContext.tsx +++ b/packages/files-ui/src/Contexts/ThresholdKeyContext.tsx @@ -90,28 +90,28 @@ const ThresholdKeyContext = React.createContext { +{typeOfLogin: LOGIN_TYPE; clientId: string; verifier: string; jwtParams?: any} => { switch (loginType) { - case "google": { - return { - typeOfLogin: loginType, - clientId: process.env.REACT_APP_GOOGLE_CLIENT_ID || "", - verifier: "chainsafe-uuid-testnet" + case "google": { + return { + typeOfLogin: loginType, + clientId: process.env.REACT_APP_GOOGLE_CLIENT_ID || "", + verifier: "chainsafe-uuid-testnet" + } } - } - case "github":{ - return { - typeOfLogin: loginType, - clientId: process.env.REACT_APP_AUTH0_CLIENT_ID || "", - verifier: "chainsafe-uuid-testnet", - jwtParams: { - domain: process.env.REACT_APP_AUTH0_DOMAIN || "" + case "github":{ + return { + typeOfLogin: loginType, + clientId: process.env.REACT_APP_AUTH0_CLIENT_ID || "", + verifier: "chainsafe-uuid-testnet", + jwtParams: { + domain: process.env.REACT_APP_AUTH0_DOMAIN || "" + } } } - } - default:{ - throw new Error(`${loginType} is unsupported`) - } + default:{ + throw new Error(`${loginType} is unsupported`) + } } } @@ -382,16 +382,16 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f if (userInfo && loginType) { switch (loginType) { - case "jwt": - setLoggedinAs(t`Web3: ${centerEllipsis(String(address), 4)}`) - break - case "google": - case "github": - setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(userInfo.userInfo.email, 4)}`) - break - default: - setLoggedinAs(`${centerEllipsis(userInfo.publicAddress, 4)}`) - break + case "jwt": + setLoggedinAs(t`Web3: ${centerEllipsis(String(address), 4)}`) + break + case "google": + case "github": + setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(userInfo.userInfo.email, 4)}`) + break + default: + setLoggedinAs(`${centerEllipsis(userInfo.publicAddress, 4)}`) + break } } }, [userInfo, address]) diff --git a/packages/files-ui/src/Themes/Constants.ts b/packages/files-ui/src/Themes/Constants.ts index 11ddd93e5e..e36b09ecaa 100644 --- a/packages/files-ui/src/Themes/Constants.ts +++ b/packages/files-ui/src/Themes/Constants.ts @@ -160,7 +160,7 @@ export interface CsfColors extends IConstants { } } surveyBanner: { - color: string + color: string } menu: { backgroundColor: string diff --git a/packages/files-ui/src/UI-components/Menu.tsx b/packages/files-ui/src/UI-components/Menu.tsx index eca9deb4e6..6aef09ae4e 100644 --- a/packages/files-ui/src/UI-components/Menu.tsx +++ b/packages/files-ui/src/UI-components/Menu.tsx @@ -6,22 +6,22 @@ import { useCallback } from "react" import { CSFTheme } from "../Themes/types" interface Option { - contents: ReactNode - onClick?: () => void + contents: ReactNode + onClick?: () => void } interface CustomClasses { - iconContainer?: string - menuWrapper?: string - focusVisible?: string - root?: string + iconContainer?: string + menuWrapper?: string + focusVisible?: string + root?: string } interface Props { - icon?: ReactNode - options: Option[] - style?: CustomClasses - testId?: string + icon?: ReactNode + options: Option[] + style?: CustomClasses + testId?: string } const useStyles = makeStyles(({ constants }: CSFTheme) => { diff --git a/packages/files-ui/src/Utils/MimeMatcher.ts b/packages/files-ui/src/Utils/MimeMatcher.ts index d0466c7d73..c2c1186aec 100644 --- a/packages/files-ui/src/Utils/MimeMatcher.ts +++ b/packages/files-ui/src/Utils/MimeMatcher.ts @@ -46,48 +46,48 @@ function matcher(expected: string[]) { } class MimeMatcher { - expected = [] as { typeMatcher: (actual: string) => boolean; subTypeMatcher: (actual: string) => boolean }[] + expected = [] as { typeMatcher: (actual: string) => boolean; subTypeMatcher: (actual: string) => boolean }[] - constructor(expected: string | string[]) { - if (Array.isArray(expected)) { - this.expected = expected.map(mimeType => { - const { valid, type, subType } = parse(mimeType) - if (valid && type && subType) { - return ({ - typeMatcher: createMatcher(type), - subTypeMatcher: createMatcher(subType) - }) - } else { - const msg = `Value "${mimeType}" is not valid mime type.It should have format "type/subtype".` - throw new TypeError(msg) - } - }) - } - else { - const { valid, type, subType } = parse(expected) + constructor(expected: string | string[]) { + if (Array.isArray(expected)) { + this.expected = expected.map(mimeType => { + const { valid, type, subType } = parse(mimeType) if (valid && type && subType) { - this.expected = [{ + return ({ typeMatcher: createMatcher(type), subTypeMatcher: createMatcher(subType) - }] + }) } else { - const msg = `Value "${expected}" is not valid mime type.It should have format "type/subtype".` + const msg = `Value "${mimeType}" is not valid mime type.It should have format "type/subtype".` throw new TypeError(msg) } - } - + }) } - - match(actual: string) { - const { valid, type, subType } = parse(actual) + else { + const { valid, type, subType } = parse(expected) if (valid && type && subType) { - return this.expected.some(({ typeMatcher, subTypeMatcher }) => { - return typeMatcher(type) && subTypeMatcher(subType) - }) + this.expected = [{ + typeMatcher: createMatcher(type), + subTypeMatcher: createMatcher(subType) + }] } else { - return false + const msg = `Value "${expected}" is not valid mime type.It should have format "type/subtype".` + throw new TypeError(msg) } } + + } + + match(actual: string) { + const { valid, type, subType } = parse(actual) + if (valid && type && subType) { + return this.expected.some(({ typeMatcher, subTypeMatcher }) => { + return typeMatcher(type) && subTypeMatcher(subType) + }) + } else { + return false + } + } } export { isValid, parse, matcher } diff --git a/packages/files-ui/src/Utils/contentTypeGuesser.ts b/packages/files-ui/src/Utils/contentTypeGuesser.ts index 6f7af8db43..ae7b19cdd3 100644 --- a/packages/files-ui/src/Utils/contentTypeGuesser.ts +++ b/packages/files-ui/src/Utils/contentTypeGuesser.ts @@ -2,25 +2,25 @@ const guessContentType = (fileName: string) => { const { length, [length - 1]: ext } = fileName.split(".") switch (ext) { - case "pdf": - return "application/pdf" - case "jpg": - case "jpeg": - case "png": - case "gif": - case "bmp": - return `image/${ext}` - case "mp3": - case "m4a": - return `audio/${ext}` - case "mp4": - return `video/${ext}` - case "txt": - return "text/plain" - case "md": - return "text/markdown" - default: - return "application/octet-stream" + case "pdf": + return "application/pdf" + case "jpg": + case "jpeg": + case "png": + case "gif": + case "bmp": + return `image/${ext}` + case "mp3": + case "m4a": + return `audio/${ext}` + case "mp4": + return `video/${ext}` + case "txt": + return "text/plain" + case "md": + return "text/markdown" + default: + return "application/octet-stream" } } diff --git a/packages/gaming-ui/src/Components/Elements/SecretField.tsx b/packages/gaming-ui/src/Components/Elements/SecretField.tsx index f8f501bc8d..ba059aa666 100644 --- a/packages/gaming-ui/src/Components/Elements/SecretField.tsx +++ b/packages/gaming-ui/src/Components/Elements/SecretField.tsx @@ -3,7 +3,7 @@ import { EyeOpenIcon, EyeClosedIcon, Typography } from "@chainsafe/common-compon import { makeStyles, createStyles } from "@chainsafe/common-theme" interface Props { - value: string + value: string } const useStyles = makeStyles(() => diff --git a/packages/gaming-ui/src/Contexts/GamingApiContext.tsx b/packages/gaming-ui/src/Contexts/GamingApiContext.tsx index 8627939409..7923ac2b04 100644 --- a/packages/gaming-ui/src/Contexts/GamingApiContext.tsx +++ b/packages/gaming-ui/src/Contexts/GamingApiContext.tsx @@ -15,28 +15,28 @@ const isReturningUserStorageKey = "csg.isReturningUser" const TORUS_USERINFO_KEY = "csg.userInfo" const getProviderSpecificParams = (loginType: LOGIN_TYPE): - {typeOfLogin: LOGIN_TYPE; clientId: string; verifier: string; jwtParams?: any} => { +{typeOfLogin: LOGIN_TYPE; clientId: string; verifier: string; jwtParams?: any} => { switch (loginType) { - case "google": { - return { - typeOfLogin: loginType, - clientId: process.env.REACT_APP_GOOGLE_CLIENT_ID || "", - verifier: "chainsafe-uuid-testnet" + case "google": { + return { + typeOfLogin: loginType, + clientId: process.env.REACT_APP_GOOGLE_CLIENT_ID || "", + verifier: "chainsafe-uuid-testnet" + } } - } - case "github":{ - return { - typeOfLogin: loginType, - clientId: process.env.REACT_APP_AUTH0_CLIENT_ID || "", - verifier: "chainsafe-uuid-testnet", - jwtParams: { - domain: process.env.REACT_APP_AUTH0_DOMAIN || "" + case "github":{ + return { + typeOfLogin: loginType, + clientId: process.env.REACT_APP_AUTH0_CLIENT_ID || "", + verifier: "chainsafe-uuid-testnet", + jwtParams: { + domain: process.env.REACT_APP_AUTH0_DOMAIN || "" + } } } - } - default:{ - throw new Error(`${loginType} is unsupported`) - } + default:{ + throw new Error(`${loginType} is unsupported`) + } } } @@ -102,7 +102,7 @@ const GamingApiProvider = ({ apiUrl, withLocalStorage = true, children }: Gaming const [accessToken, setAccessToken] = useState(undefined) const [refreshToken, setRefreshToken] = useState(undefined) const [decodedRefreshToken, setDecodedRefreshToken] = useState< - { exp: number; enckey?: string; mps?: string; uuid: string } | undefined + { exp: number; enckey?: string; mps?: string; uuid: string } | undefined >(undefined) // returning user @@ -134,18 +134,18 @@ const GamingApiProvider = ({ apiUrl, withLocalStorage = true, children }: Gaming if (userInfo && loginType) { switch (loginType) { - case "jwt": - setLoggedinAs(t`Web3: ${centerEllipsis(String(address), 4)}`) - break - case "google": - setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(`${userInfo.email}`, 4)}`) - break - case "github": - setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(`${userInfo.email}`, 4)}`) - break - default: - setLoggedinAs(`${centerEllipsis(`${userInfo.publicAddress}`, 4)}`) - break + case "jwt": + setLoggedinAs(t`Web3: ${centerEllipsis(String(address), 4)}`) + break + case "google": + setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(`${userInfo.email}`, 4)}`) + break + case "github": + setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(`${userInfo.email}`, 4)}`) + break + default: + setLoggedinAs(`${centerEllipsis(`${userInfo.publicAddress}`, 4)}`) + break } } }, [userInfo, address]) diff --git a/packages/gaming-ui/src/Themes/Constants.ts b/packages/gaming-ui/src/Themes/Constants.ts index 28fabee2d5..b0c6c8ac13 100644 --- a/packages/gaming-ui/src/Themes/Constants.ts +++ b/packages/gaming-ui/src/Themes/Constants.ts @@ -156,6 +156,6 @@ export interface CsGColors extends IConstants { } } surveyBanner: { - color: string + color: string } } \ No newline at end of file diff --git a/packages/storage-ui/src/Components/Elements/CidRow.tsx b/packages/storage-ui/src/Components/Elements/CidRow.tsx index 74927f785d..e1bcc29086 100644 --- a/packages/storage-ui/src/Components/Elements/CidRow.tsx +++ b/packages/storage-ui/src/Components/Elements/CidRow.tsx @@ -56,7 +56,7 @@ const useStyles = makeStyles(({ animation, constants, breakpoints }: CSSTheme) = }) ) interface Props { - pinStatus: PinStatus + pinStatus: PinStatus } const IPFS_GATEWAY = process.env.REACT_APP_IPFS_GATEWAY || "" diff --git a/packages/storage-ui/src/Components/Elements/SecretField.tsx b/packages/storage-ui/src/Components/Elements/SecretField.tsx index 55ee36164e..7639455276 100644 --- a/packages/storage-ui/src/Components/Elements/SecretField.tsx +++ b/packages/storage-ui/src/Components/Elements/SecretField.tsx @@ -4,8 +4,8 @@ import { makeStyles, createStyles } from "@chainsafe/common-theme" import clsx from "clsx" interface Props { - value: string - className?: string + value: string + className?: string } const useStyles = makeStyles(() => diff --git a/packages/storage-ui/src/Components/Modules/FilesList/FilesList.tsx b/packages/storage-ui/src/Components/Modules/FilesList/FilesList.tsx index eb3c4b4e04..c998d85f81 100644 --- a/packages/storage-ui/src/Components/Modules/FilesList/FilesList.tsx +++ b/packages/storage-ui/src/Components/Modules/FilesList/FilesList.tsx @@ -323,27 +323,27 @@ const FilesList = () => { let temp = [] switch (column) { - default: { + default: { // case "name": { - temp = sourceFiles.sort((a, b) => { - return a.name.localeCompare(b.name, selectedLocale, { - sensitivity: "base" + temp = sourceFiles.sort((a, b) => { + return a.name.localeCompare(b.name, selectedLocale, { + sensitivity: "base" + }) }) - }) - break - } - case "size": { - temp = sourceFiles - .sort((a, b) => (a.size < b.size ? -1 : 1)) - .sort(sortFoldersFirst) - break - } - case "date_uploaded": { - temp = sourceFiles - .sort((a, b) => (a.created_at < b.created_at ? -1 : 1)) - .sort(sortFoldersFirst) - break - } + break + } + case "size": { + temp = sourceFiles + .sort((a, b) => (a.size < b.size ? -1 : 1)) + .sort(sortFoldersFirst) + break + } + case "date_uploaded": { + temp = sourceFiles + .sort((a, b) => (a.created_at < b.created_at ? -1 : 1)) + .sort(sortFoldersFirst) + break + } } return direction === "descend" ? temp.reverse().sort(sortFoldersFirst) diff --git a/packages/storage-ui/src/Components/Modules/SurveyBanner.tsx b/packages/storage-ui/src/Components/Modules/SurveyBanner.tsx index bb4530d34e..d0fa268290 100644 --- a/packages/storage-ui/src/Components/Modules/SurveyBanner.tsx +++ b/packages/storage-ui/src/Components/Modules/SurveyBanner.tsx @@ -54,7 +54,7 @@ const useStyles = makeStyles( }) interface Props { - onHide: () => void + onHide: () => void } const SurveyBanner = ({ onHide }: Props) => { diff --git a/packages/storage-ui/src/Components/Pages/CidsPage.tsx b/packages/storage-ui/src/Components/Pages/CidsPage.tsx index 5b03cb1363..11cb057135 100644 --- a/packages/storage-ui/src/Components/Pages/CidsPage.tsx +++ b/packages/storage-ui/src/Components/Pages/CidsPage.tsx @@ -79,14 +79,14 @@ const CidsPage = () => { let temp = [] switch (sortColumn) { - case "size": { - temp = pins.sort((a, b) => (a.info?.size < b.info?.size ? -1 : 1)) - break - } - default: { - temp = pins.sort((a, b) => (a.created < b.created ? -1 : 1)) - break - } + case "size": { + temp = pins.sort((a, b) => (a.info?.size < b.info?.size ? -1 : 1)) + break + } + default: { + temp = pins.sort((a, b) => (a.created < b.created ? -1 : 1)) + break + } } return sortDirection === "descend" ? temp.reverse() : temp }, [pins, sortDirection, sortColumn]) diff --git a/packages/storage-ui/src/Contexts/FileOperationsReducers.tsx b/packages/storage-ui/src/Contexts/FileOperationsReducers.tsx index fc5e8984b1..486b1fe8df 100644 --- a/packages/storage-ui/src/Contexts/FileOperationsReducers.tsx +++ b/packages/storage-ui/src/Contexts/FileOperationsReducers.tsx @@ -3,117 +3,117 @@ import { DownloadProgress, UploadProgress } from "./StorageContext" export function uploadsInProgressReducer( uploadsInProgress: UploadProgress[], action: - | { type: "add"; payload: UploadProgress } - | { type: "progress"; payload: { id: string; progress: number } } - | { type: "complete"; payload: { id: string } } - | { type: "error"; payload: { id: string; errorMessage?: string } } - | { type: "remove"; payload: { id: string } } + | { type: "add"; payload: UploadProgress } + | { type: "progress"; payload: { id: string; progress: number } } + | { type: "complete"; payload: { id: string } } + | { type: "error"; payload: { id: string; errorMessage?: string } } + | { type: "remove"; payload: { id: string } } ): UploadProgress[] { const getProgressIndex = () => uploadsInProgress.findIndex((progress) => progress.id === action.payload.id) switch (action.type) { - case "add": { - return [...uploadsInProgress, action.payload] - } - case "progress": { - const progressIndex = getProgressIndex() - if (progressIndex > -1) { - uploadsInProgress[progressIndex].progress = action.payload.progress - return [...uploadsInProgress] - } else { - return uploadsInProgress + case "add": { + return [...uploadsInProgress, action.payload] } - } - case "complete": { - const progressIndex = getProgressIndex() - if (progressIndex > -1) { - uploadsInProgress[progressIndex].complete = true - return [...uploadsInProgress] - } else { - return uploadsInProgress + case "progress": { + const progressIndex = getProgressIndex() + if (progressIndex > -1) { + uploadsInProgress[progressIndex].progress = action.payload.progress + return [...uploadsInProgress] + } else { + return uploadsInProgress + } } - } - case "error": { - const progressIndex = getProgressIndex() - if (progressIndex > -1) { - uploadsInProgress[progressIndex].error = true - uploadsInProgress[progressIndex].errorMessage = + case "complete": { + const progressIndex = getProgressIndex() + if (progressIndex > -1) { + uploadsInProgress[progressIndex].complete = true + return [...uploadsInProgress] + } else { + return uploadsInProgress + } + } + case "error": { + const progressIndex = getProgressIndex() + if (progressIndex > -1) { + uploadsInProgress[progressIndex].error = true + uploadsInProgress[progressIndex].errorMessage = action.payload.errorMessage - return [...uploadsInProgress] - } else { - return uploadsInProgress + return [...uploadsInProgress] + } else { + return uploadsInProgress + } } - } - case "remove": { - const progressIndex = getProgressIndex() - if (progressIndex > -1) { - uploadsInProgress.splice(progressIndex, 1) - return [...uploadsInProgress] - } else { - return uploadsInProgress + case "remove": { + const progressIndex = getProgressIndex() + if (progressIndex > -1) { + uploadsInProgress.splice(progressIndex, 1) + return [...uploadsInProgress] + } else { + return uploadsInProgress + } } - } - default: - return uploadsInProgress + default: + return uploadsInProgress } } export function downloadsInProgressReducer( downloadsInProgress: DownloadProgress[], action: - | { type: "add"; payload: DownloadProgress } - | { type: "progress"; payload: { id: string; progress: number } } - | { type: "complete"; payload: { id: string } } - | { type: "error"; payload: { id: string; errorMessage?: string } } - | { type: "remove"; payload: { id: string } } + | { type: "add"; payload: DownloadProgress } + | { type: "progress"; payload: { id: string; progress: number } } + | { type: "complete"; payload: { id: string } } + | { type: "error"; payload: { id: string; errorMessage?: string } } + | { type: "remove"; payload: { id: string } } ): DownloadProgress[] { const getProgressIndex = () => downloadsInProgress.findIndex( (download) => download.id === action.payload.id ) switch (action.type) { - case "add": { - return [...downloadsInProgress, action.payload] - } - case "progress": { - const progressIndex = getProgressIndex() - if (progressIndex > -1) { - downloadsInProgress[progressIndex].progress = action.payload.progress - return [...downloadsInProgress] - } else { - return downloadsInProgress + case "add": { + return [...downloadsInProgress, action.payload] } - } - case "complete": { - const progressIndex = getProgressIndex() - if (progressIndex > -1) { - downloadsInProgress[progressIndex].complete = true - return [...downloadsInProgress] - } else { - return downloadsInProgress + case "progress": { + const progressIndex = getProgressIndex() + if (progressIndex > -1) { + downloadsInProgress[progressIndex].progress = action.payload.progress + return [...downloadsInProgress] + } else { + return downloadsInProgress + } } - } - case "error": { - const progressIndex = getProgressIndex() - if (progressIndex > -1) { - downloadsInProgress[progressIndex].error = true - downloadsInProgress[progressIndex].errorMessage = + case "complete": { + const progressIndex = getProgressIndex() + if (progressIndex > -1) { + downloadsInProgress[progressIndex].complete = true + return [...downloadsInProgress] + } else { + return downloadsInProgress + } + } + case "error": { + const progressIndex = getProgressIndex() + if (progressIndex > -1) { + downloadsInProgress[progressIndex].error = true + downloadsInProgress[progressIndex].errorMessage = action.payload.errorMessage - return [...downloadsInProgress] - } else { - return downloadsInProgress + return [...downloadsInProgress] + } else { + return downloadsInProgress + } } - } - case "remove": { - const progressIndex = getProgressIndex() - if (progressIndex > -1) { - downloadsInProgress.splice(progressIndex, 1) - return [...downloadsInProgress] - } else { - return downloadsInProgress + case "remove": { + const progressIndex = getProgressIndex() + if (progressIndex > -1) { + downloadsInProgress.splice(progressIndex, 1) + return [...downloadsInProgress] + } else { + return downloadsInProgress + } } - } - default: - return downloadsInProgress + default: + return downloadsInProgress } } diff --git a/packages/storage-ui/src/Contexts/StorageApiContext.tsx b/packages/storage-ui/src/Contexts/StorageApiContext.tsx index eaa2e38631..deee4c4cc6 100644 --- a/packages/storage-ui/src/Contexts/StorageApiContext.tsx +++ b/packages/storage-ui/src/Contexts/StorageApiContext.tsx @@ -15,28 +15,28 @@ const isReturningUserStorageKey = "css.isReturningUser" const TORUS_USERINFO_KEY = "css.userInfo" const getProviderSpecificParams = (loginType: LOGIN_TYPE): - {typeOfLogin: LOGIN_TYPE; clientId: string; verifier: string; jwtParams?: any} => { +{typeOfLogin: LOGIN_TYPE; clientId: string; verifier: string; jwtParams?: any} => { switch (loginType) { - case "google": { - return { - typeOfLogin: loginType, - clientId: process.env.REACT_APP_GOOGLE_CLIENT_ID || "", - verifier: "chainsafe-uuid-testnet" + case "google": { + return { + typeOfLogin: loginType, + clientId: process.env.REACT_APP_GOOGLE_CLIENT_ID || "", + verifier: "chainsafe-uuid-testnet" + } } - } - case "github":{ - return { - typeOfLogin: loginType, - clientId: process.env.REACT_APP_AUTH0_CLIENT_ID || "", - verifier: "chainsafe-uuid-testnet", - jwtParams: { - domain: process.env.REACT_APP_AUTH0_DOMAIN || "" + case "github":{ + return { + typeOfLogin: loginType, + clientId: process.env.REACT_APP_AUTH0_CLIENT_ID || "", + verifier: "chainsafe-uuid-testnet", + jwtParams: { + domain: process.env.REACT_APP_AUTH0_DOMAIN || "" + } } } - } - default:{ - throw new Error(`${loginType} is unsupported`) - } + default:{ + throw new Error(`${loginType} is unsupported`) + } } } @@ -101,7 +101,7 @@ const StorageApiProvider = ({ apiUrl, withLocalStorage = true, children }: Stora const [accessToken, setAccessToken] = useState(undefined) const [refreshToken, setRefreshToken] = useState(undefined) const [decodedRefreshToken, setDecodedRefreshToken] = useState< - { exp: number; enckey?: string; mps?: string; uuid: string } | undefined + { exp: number; enckey?: string; mps?: string; uuid: string } | undefined >(undefined) // returning user @@ -133,18 +133,18 @@ const StorageApiProvider = ({ apiUrl, withLocalStorage = true, children }: Stora if (userInfo && loginType) { switch (loginType) { - case "jwt": - setLoggedinAs(t`Web3: ${centerEllipsis(String(address), 4)}`) - break - case "google": - setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(`${userInfo.email}`, 4)}`) - break - case "github": - setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(`${userInfo.email}`, 4)}`) - break - default: - setLoggedinAs(`${centerEllipsis(`${userInfo.publicAddress}`, 4)}`) - break + case "jwt": + setLoggedinAs(t`Web3: ${centerEllipsis(String(address), 4)}`) + break + case "google": + setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(`${userInfo.email}`, 4)}`) + break + case "github": + setLoggedinAs(`${capitalize(loginType)}: ${centerEllipsis(`${userInfo.email}`, 4)}`) + break + default: + setLoggedinAs(`${centerEllipsis(`${userInfo.publicAddress}`, 4)}`) + break } } }, [userInfo, address]) diff --git a/packages/storage-ui/src/Themes/Constants.ts b/packages/storage-ui/src/Themes/Constants.ts index 13d485b3db..844ac3663b 100644 --- a/packages/storage-ui/src/Themes/Constants.ts +++ b/packages/storage-ui/src/Themes/Constants.ts @@ -156,6 +156,6 @@ export interface CsSColors extends IConstants { } } surveyBanner: { - color: string + color: string } } \ No newline at end of file diff --git a/packages/storage-ui/src/Utils/MimeMatcher.ts b/packages/storage-ui/src/Utils/MimeMatcher.ts index d0466c7d73..c2c1186aec 100644 --- a/packages/storage-ui/src/Utils/MimeMatcher.ts +++ b/packages/storage-ui/src/Utils/MimeMatcher.ts @@ -46,48 +46,48 @@ function matcher(expected: string[]) { } class MimeMatcher { - expected = [] as { typeMatcher: (actual: string) => boolean; subTypeMatcher: (actual: string) => boolean }[] + expected = [] as { typeMatcher: (actual: string) => boolean; subTypeMatcher: (actual: string) => boolean }[] - constructor(expected: string | string[]) { - if (Array.isArray(expected)) { - this.expected = expected.map(mimeType => { - const { valid, type, subType } = parse(mimeType) - if (valid && type && subType) { - return ({ - typeMatcher: createMatcher(type), - subTypeMatcher: createMatcher(subType) - }) - } else { - const msg = `Value "${mimeType}" is not valid mime type.It should have format "type/subtype".` - throw new TypeError(msg) - } - }) - } - else { - const { valid, type, subType } = parse(expected) + constructor(expected: string | string[]) { + if (Array.isArray(expected)) { + this.expected = expected.map(mimeType => { + const { valid, type, subType } = parse(mimeType) if (valid && type && subType) { - this.expected = [{ + return ({ typeMatcher: createMatcher(type), subTypeMatcher: createMatcher(subType) - }] + }) } else { - const msg = `Value "${expected}" is not valid mime type.It should have format "type/subtype".` + const msg = `Value "${mimeType}" is not valid mime type.It should have format "type/subtype".` throw new TypeError(msg) } - } - + }) } - - match(actual: string) { - const { valid, type, subType } = parse(actual) + else { + const { valid, type, subType } = parse(expected) if (valid && type && subType) { - return this.expected.some(({ typeMatcher, subTypeMatcher }) => { - return typeMatcher(type) && subTypeMatcher(subType) - }) + this.expected = [{ + typeMatcher: createMatcher(type), + subTypeMatcher: createMatcher(subType) + }] } else { - return false + const msg = `Value "${expected}" is not valid mime type.It should have format "type/subtype".` + throw new TypeError(msg) } } + + } + + match(actual: string) { + const { valid, type, subType } = parse(actual) + if (valid && type && subType) { + return this.expected.some(({ typeMatcher, subTypeMatcher }) => { + return typeMatcher(type) && subTypeMatcher(subType) + }) + } else { + return false + } + } } export { isValid, parse, matcher } diff --git a/packages/storage-ui/src/Utils/contentTypeGuesser.ts b/packages/storage-ui/src/Utils/contentTypeGuesser.ts index d65fb94191..e6ec42156b 100644 --- a/packages/storage-ui/src/Utils/contentTypeGuesser.ts +++ b/packages/storage-ui/src/Utils/contentTypeGuesser.ts @@ -2,24 +2,24 @@ const guessContentType = (fileName: string) => { const { length, [length - 1]: ext } = fileName.split(".") switch (ext) { - case "pdf": - return "application/pdf" - case "jpg": - case "png": - case "gif": - case "bmp": - return `image/${ext}` - case "mp3": - case "m4a": - return `audio/${ext}` - case "mp4": - return `video/${ext}` - case "txt": - return "text/plain" - case "md": - return "text/markdown" - default: - return "application/octet-stream" + case "pdf": + return "application/pdf" + case "jpg": + case "png": + case "gif": + case "bmp": + return `image/${ext}` + case "mp3": + case "m4a": + return `audio/${ext}` + case "mp4": + return `video/${ext}` + case "txt": + return "text/plain" + case "md": + return "text/markdown" + default: + return "application/octet-stream" } }