diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..7d6e7f89 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,5 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +prettier --config .prettierrc --write src '!**/*.{scss,css,json}' +git add -A src/ diff --git a/.husky/pre-push b/.husky/pre-push index b3d71da1..f45b957b 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,5 +1,5 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -npm test -- --watchAll=false eslint --max-warnings 0 src --ext .ts --ext .tsx --cache +npm test -- --watchAll=false diff --git a/.prettierrc b/.prettierrc index 6f01081c..f0fc68fa 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,15 +2,12 @@ "useTabs": false, "printWidth": 80, "tabWidth": 4, + "semi": false, "singleQuote": false, - - "trailingComma": "none", - - "jsxBracketSameLine": false, - + "jsxSingleQuote": false, + "trailingComma": "es5", + "bracketSpacing": true, + "bracketSameLine": false, + "arrowParens": "always", "parser": "typescript", - - "noSemi": true, - - "rcVerbose": true } diff --git a/src/__tests__/storybook.test.ts b/src/__tests__/storybook.test.ts index a97924b0..976be4a0 100644 --- a/src/__tests__/storybook.test.ts +++ b/src/__tests__/storybook.test.ts @@ -1,2 +1,2 @@ -import initStoryshots from "@storybook/addon-storyshots"; -initStoryshots(); +import initStoryshots from "@storybook/addon-storyshots" +initStoryshots() diff --git a/src/assets/images/icons/reactSvgIcons/SymbolFile.tsx b/src/assets/images/icons/reactSvgIcons/SymbolFile.tsx index 3effd4c9..cb8c3c5f 100644 --- a/src/assets/images/icons/reactSvgIcons/SymbolFile.tsx +++ b/src/assets/images/icons/reactSvgIcons/SymbolFile.tsx @@ -1,4 +1,4 @@ -import * as React from "react"; +import * as React from "react" //https://reactsvgicons.com/bootstrap export function FileEarmarkIcon(props: React.SVGProps) { @@ -13,7 +13,7 @@ export function FileEarmarkIcon(props: React.SVGProps) { - ); + ) } export function FileEarmarkMusicIcon(props: React.SVGProps) { @@ -32,7 +32,7 @@ export function FileEarmarkMusicIcon(props: React.SVGProps) { d="M9.757 5.67A1 1 0 0111 6.64v1.75l-2 .5v3.61c0 .495-.301.883-.662 1.123C7.974 13.866 7.499 14 7 14c-.5 0-.974-.134-1.338-.377-.36-.24-.662-.628-.662-1.123s.301-.883.662-1.123C6.026 11.134 6.501 11 7 11c.356 0 .7.068 1 .196V6.89a1 1 0 01.757-.97l1-.25z" /> - ); + ) } export function FileEarmarkPlayIcon(props: React.SVGProps) { @@ -48,7 +48,7 @@ export function FileEarmarkPlayIcon(props: React.SVGProps) { - ); + ) } export function FileEarmarkTextIcon(props: React.SVGProps) { @@ -67,7 +67,7 @@ export function FileEarmarkTextIcon(props: React.SVGProps) { d="M5 11.5a.5.5 0 01.5-.5h2a.5.5 0 010 1h-2a.5.5 0 01-.5-.5zm0-2a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5zm0-2a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5z" /> - ); + ) } export function FileEarmarkImageIcon(props: React.SVGProps) { @@ -88,7 +88,7 @@ export function FileEarmarkImageIcon(props: React.SVGProps) { d="M6.502 7a1.5 1.5 0 100-3 1.5 1.5 0 000 3z" /> - ); + ) } export function FileEarmarkRichtextIcon(props: React.SVGProps) { @@ -107,7 +107,7 @@ export function FileEarmarkRichtextIcon(props: React.SVGProps) { d="M4.5 12.5A.5.5 0 015 12h3a.5.5 0 010 1H5a.5.5 0 01-.5-.5zm0-2A.5.5 0 015 10h6a.5.5 0 010 1H5a.5.5 0 01-.5-.5zm1.639-3.708l1.33.886 1.854-1.855a.25.25 0 01.289-.047l1.888.974V8.5a.5.5 0 01-.5.5H5a.5.5 0 01-.5-.5V8s1.54-1.274 1.639-1.208zM6.25 6a.75.75 0 100-1.5.75.75 0 000 1.5z" /> - ); + ) } export function FileEarmarkLock2Icon(props: React.SVGProps) { @@ -126,7 +126,7 @@ export function FileEarmarkLock2Icon(props: React.SVGProps) { - ); + ) } export function FileEarmarkZipIcon(props: React.SVGProps) { @@ -146,7 +146,7 @@ export function FileEarmarkZipIcon(props: React.SVGProps) { /> - ); + ) } export function FileEarmarkCodeIcon(props: React.SVGProps) { @@ -165,7 +165,7 @@ export function FileEarmarkCodeIcon(props: React.SVGProps) { d="M8.646 6.646a.5.5 0 01.708 0l2 2a.5.5 0 010 .708l-2 2a.5.5 0 01-.708-.708L10.293 9 8.646 7.354a.5.5 0 010-.708zm-1.292 0a.5.5 0 00-.708 0l-2 2a.5.5 0 000 .708l2 2a.5.5 0 00.708-.708L5.707 9l1.647-1.646a.5.5 0 000-.708z" /> - ); + ) } export function FileEarmarkPDFIcon(props: React.SVGProps) { @@ -184,7 +184,7 @@ export function FileEarmarkPDFIcon(props: React.SVGProps) { d="M7 5a.5.5 0 01.5.5v.634l.549-.317a.5.5 0 11.5.866L8 7l.549.317a.5.5 0 11-.5.866L7.5 7.866V8.5a.5.5 0 01-1 0v-.634l-.549.317a.5.5 0 11-.5-.866L6 7l-.549-.317a.5.5 0 01.5-.866l.549.317V5.5A.5.5 0 017 5zm-2 5.5a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5zm0 2a.5.5 0 01.5-.5h5a.5.5 0 010 1h-5a.5.5 0 01-.5-.5z" /> - ); + ) } export function FileEarmarkBinaryIcon(props: React.SVGProps) { @@ -199,7 +199,7 @@ export function FileEarmarkBinaryIcon(props: React.SVGProps) { - ); + ) } //--------------------------------------------------------------------\\ @@ -224,5 +224,5 @@ export function FolderIcon(props: React.SVGProps) { d="M13.81 4H2.19a1 1 0 00-.996 1.09l.637 7a1 1 0 00.995.91h10.348a1 1 0 00.995-.91l.637-7A1 1 0 0013.81 4zM2.19 3A2 2 0 00.198 5.181l.637 7A2 2 0 002.826 14h10.348a2 2 0 001.991-1.819l.637-7A2 2 0 0013.81 3H2.19z" /> - ); + ) } diff --git a/src/background/api/api.ts b/src/background/api/api.ts index 7ad4f269..104ec55b 100644 --- a/src/background/api/api.ts +++ b/src/background/api/api.ts @@ -1,38 +1,38 @@ -import Axios from "axios"; -import { constants } from "../constants"; +import Axios from "axios" +import { constants } from "../constants" -export const hostname: string = constants.url.API_URL; +export const hostname: string = constants.url.API_URL -export const userPath: string = "/v1/users"; +export const userPath: string = "/v1/users" -export const filesystemPath: string = "/v1/filesystem/"; +export const filesystemPath: string = "/v1/filesystem/" enum DataIntegrity { STABLE = "bg-success", POSSIBLE_RISK = "bg-warning", - UNSTABLE = "bg-danger" + UNSTABLE = "bg-danger", } interface SystemHealthData { - uptimeInSeconds: number; - userCount: number; - dataIntegrity: string; - deployment: string; - usedStorageInBytes: number; - version: string; + uptimeInSeconds: number + userCount: number + dataIntegrity: string + deployment: string + usedStorageInBytes: number + version: string } function callBackendHealth(): Promise { return new Promise((resolve, reject) => { Axios.get(`${hostname}/health`) .then((data) => { - resolve(data.data); + resolve(data.data) }) .catch((error) => { - reject(error); - }); - }); + reject(error) + }) + }) } -export { callBackendHealth, DataIntegrity }; -export type { SystemHealthData }; +export { callBackendHealth, DataIntegrity } +export type { SystemHealthData } diff --git a/src/background/api/auth.ts b/src/background/api/auth.ts index c57887ed..47fc7fa2 100644 --- a/src/background/api/auth.ts +++ b/src/background/api/auth.ts @@ -1,131 +1,131 @@ -import Axios, { AxiosResponse } from "axios"; +import Axios, { AxiosResponse } from "axios" -import { hostname, userPath } from "./api"; +import { hostname, userPath } from "./api" -import { UserState } from "../redux/actions/userTypes"; -import store from "../redux/store"; +import { UserState } from "../redux/actions/userTypes" +import store from "../redux/store" import { addAccessToken, addRefreshToken, checkedCookies, - removeTokens -} from "../redux/actions/tokens"; -import { AccessToken, CookieStatus } from "../redux/actions/tokenTypes"; -import { deleteCookie, getCookie, setCookie } from "../methods/cookies"; -import { updateUser } from "../redux/actions/user"; -import { hashPassword } from "../methods/passwords"; + removeTokens, +} from "../redux/actions/tokens" +import { AccessToken, CookieStatus } from "../redux/actions/tokenTypes" +import { deleteCookie, getCookie, setCookie } from "../methods/cookies" +import { updateUser } from "../redux/actions/user" +import { hashPassword } from "../methods/passwords" // reference: https://daveceddia.com/access-redux-store-outside-react/ -const cookieName: string = "refreshToken"; +const cookieName: string = "refreshToken" export interface BackendLoginData { - tokenValue: string; - user: UserState; + tokenValue: string + user: UserState } export interface BackendAuthData { - tokenValue: string; - userId: number; - validUntil: number; + tokenValue: string + userId: number + validUntil: number } export const checkForCookie = () => { - let refreshTokenCookieValue = getCookie(cookieName); + let refreshTokenCookieValue = getCookie(cookieName) if (!refreshTokenCookieValue) { - return store.dispatch(checkedCookies(CookieStatus.FINISHED)); + return store.dispatch(checkedCookies(CookieStatus.FINISHED)) } - store.dispatch(addRefreshToken(refreshTokenCookieValue)); - store.dispatch(checkedCookies(CookieStatus.LOADING)); - getAccessTokenWithRefreshToken(); -}; + store.dispatch(addRefreshToken(refreshTokenCookieValue)) + store.dispatch(checkedCookies(CookieStatus.LOADING)) + getAccessTokenWithRefreshToken() +} export const loginWithUsernameAndPassword = async ( userName: string, password: string, stayLoggedIn: boolean ): Promise => { - console.log("[Auth] loginWithUsernameAndPassword", userName); - let hashed = await hashPassword(password); + console.log("[Auth] loginWithUsernameAndPassword", userName) + let hashed = await hashPassword(password) return new Promise((resolve, reject) => { let config = { headers: { - Authorization: `Basic ${btoa(userName + ":" + hashed)}` - } - }; + Authorization: `Basic ${btoa(userName + ":" + hashed)}`, + }, + } return Axios.get( hostname + userPath + "/login", config ) .then((data: AxiosResponse) => { - console.log(data.data); - store.dispatch(addRefreshToken(data.data.tokenValue)); - store.dispatch(updateUser(data.data.user as UserState)); + console.log(data.data) + store.dispatch(addRefreshToken(data.data.tokenValue)) + store.dispatch(updateUser(data.data.user as UserState)) if (stayLoggedIn) { - setCookie(cookieName, data.data.tokenValue, 60); + setCookie(cookieName, data.data.tokenValue, 60) } - getAccessTokenWithRefreshToken(); + getAccessTokenWithRefreshToken() }) .catch((error) => { - reject(error); - }); - }); -}; + reject(error) + }) + }) +} export const getAccessTokenWithRefreshToken = () => { - console.log("getAccessTokenWithRefreshToken"); + console.log("getAccessTokenWithRefreshToken") - let refreshToken: string | null = store.getState().tokens.refreshToken; + let refreshToken: string | null = store.getState().tokens.refreshToken let config = { headers: { - Authorization: `Bearer ${refreshToken}` - } - }; + Authorization: `Bearer ${refreshToken}`, + }, + } Axios.get(hostname + userPath + "/auth", config) .then((data: AxiosResponse) => { - store.dispatch(checkedCookies(CookieStatus.FINISHED)); - setAuthHeaderToAxios(data.data.tokenValue); + store.dispatch(checkedCookies(CookieStatus.FINISHED)) + setAuthHeaderToAxios(data.data.tokenValue) store.dispatch( addAccessToken({ token: data.data.tokenValue, - timestamp: data.data.validUntil + timestamp: data.data.validUntil, } as AccessToken) - ); + ) if (!store.getState().user.username) { - getOwnUserData(data.data.userId); + getOwnUserData(data.data.userId) } }) .catch((error) => { - store.dispatch(removeTokens()); - store.dispatch(checkedCookies(CookieStatus.FINISHED)); + store.dispatch(removeTokens()) + store.dispatch(checkedCookies(CookieStatus.FINISHED)) - console.log(error); + console.log(error) //you probably want to notify the user, maybe with a toast or similar - }); -}; + }) +} const getOwnUserData = (userId: number) => { Axios.get(`${hostname}${userPath}/${userId}/info`) .then((response: AxiosResponse) => { - store.dispatch(updateUser(response.data)); + store.dispatch(updateUser(response.data)) }) .catch((error) => { - console.log(error); - }); -}; + console.log(error) + }) +} export const logout = () => { - store.dispatch(removeTokens()); - deleteCookie(cookieName); -}; + store.dispatch(removeTokens()) + deleteCookie(cookieName) +} function setAuthHeaderToAxios(accessToken: string) { - Axios.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`; + Axios.defaults.headers.common["Authorization"] = `Bearer ${accessToken}` } diff --git a/src/background/api/filesystem.ts b/src/background/api/filesystem.ts index e2491ab3..0a3be370 100644 --- a/src/background/api/filesystem.ts +++ b/src/background/api/filesystem.ts @@ -1,45 +1,45 @@ -import { FsEntity } from "./filesystemTypes"; -import { filesystemPath, hostname } from "./api"; -import Axios, { AxiosError, AxiosResponse } from "axios"; -import { constants } from "../constants"; +import { FsEntity } from "./filesystemTypes" +import { filesystemPath, hostname } from "./api" +import Axios, { AxiosError, AxiosResponse } from "axios" +import { constants } from "../constants" -import store from "../redux/store"; +import store from "../redux/store" import { ApiAction, ApiActionStatus, - ApiActionType -} from "../redux/actions/apiActionsTypes"; + ApiActionType, +} from "../redux/actions/apiActionsTypes" import { addApiAction, changeStatus, - nextFsEntity -} from "../redux/actions/apiActions"; + nextFsEntity, +} from "../redux/actions/apiActions" import { addToContents, removeFromContents, - removeFromSelected -} from "../redux/actions/filesystem"; + removeFromSelected, +} from "../redux/actions/filesystem" import { EditableFileWithPreflightInfo, - PreflightEntity -} from "../../components/pages/filesytem/upload/preflightTypes"; -import { isFsEntityInFolder } from "../methods/filesystem"; + PreflightEntity, +} from "../../components/pages/filesytem/upload/preflightTypes" +import { isFsEntityInFolder } from "../methods/filesystem" -const fhHostname = constants.url.FH_URL; +const fhHostname = constants.url.FH_URL export const getFolderContents = (path: string) => { - console.log("[Get folder content", path); + console.log("[Get folder content", path) return new Promise>((resolve, reject) => { let config = { headers: { - "X-FF-PATH": path - } - }; + "X-FF-PATH": path, + }, + } Axios.get(hostname + filesystemPath + "contents", config) .then((response: AxiosResponse) => resolve(response)) - .catch((error) => reject(error)); - }); -}; + .catch((error) => reject(error)) + }) +} export const uploadPreflight = ( files: File[] | EditableFileWithPreflightInfo[], @@ -52,19 +52,19 @@ export const uploadPreflight = ( path: f.newPath ?? f.path, // @ts-ignore mimeType: f.type, - size: f.size - })); + size: f.size, + })) return new Promise((resolve, reject) => { Axios.post( hostname + filesystemPath + parentFolderID + "/upload/preflight", postData ) .then((response: AxiosResponse) => { - resolve(response.data); + resolve(response.data) }) - .catch((error: Error) => reject(error)); - }); -}; + .catch((error: Error) => reject(error)) + }) +} export const uploadFiles = ( files: File[] | EditableFileWithPreflightInfo[], @@ -74,11 +74,11 @@ export const uploadFiles = ( "[API filesystem] uploading files to folderID", parentFolderID, files - ); + ) const apiCall = (file: File | EditableFileWithPreflightInfo) => { return new Promise((resolve, reject) => { - let formData = new FormData(); - formData.append("file", file); + let formData = new FormData() + formData.append("file", file) Axios.post<[FsEntity]>( fhHostname + "/upload/" + parentFolderID, formData, @@ -89,31 +89,31 @@ export const uploadFiles = ( "X-FF-NAME": file.newName ?? file.name, // @ts-ignore "X-FF-PATH": file.newPath ?? file.path, - "X-FF-SIZE": file.size + "X-FF-SIZE": file.size, }, onUploadProgress(progress) { - console.log("upload progress:", progress); - } + console.log("upload progress:", progress) + }, } ) .then((response: AxiosResponse<[FsEntity]>) => { - const currentPath = store.getState().filesystem.currentPath; + const currentPath = store.getState().filesystem.currentPath const fsEntityToShow = response.data.find( (fsEntity: FsEntity) => isFsEntityInFolder(fsEntity, currentPath) - ); + ) if (fsEntityToShow) { - store.dispatch(addToContents(fsEntityToShow)); + store.dispatch(addToContents(fsEntityToShow)) } - resolve(response); + resolve(response) }) - .catch((error) => reject(error)); - }); - }; - handleMultipleApiActions(files, apiCall, ApiActionType.UPLOAD); -}; + .catch((error) => reject(error)) + }) + } + handleMultipleApiActions(files, apiCall, ApiActionType.UPLOAD) +} export const deleteFsEntities = (files: FsEntity[]) => { const apiCall = (fsEntity: FsEntity) => { @@ -123,22 +123,22 @@ export const deleteFsEntities = (files: FsEntity[]) => { ) .then((response: AxiosResponse) => { response.data.forEach((e) => { - store.dispatch(removeFromContents(e)); - store.dispatch(removeFromSelected(e)); - }); - resolve(response); + store.dispatch(removeFromContents(e)) + store.dispatch(removeFromSelected(e)) + }) + resolve(response) }) - .catch((error) => reject(error)); - }); - }; - handleMultipleApiActions(files, apiCall, ApiActionType.DELETE); -}; + .catch((error) => reject(error)) + }) + } + handleMultipleApiActions(files, apiCall, ApiActionType.DELETE) +} export const createNewFolder = ( folderName: string, parentFolderID: string ): Promise> => { - const body = { name: folderName }; + const body = { name: folderName } return new Promise((resolve, reject) => { Axios.post( @@ -146,21 +146,21 @@ export const createNewFolder = ( body ) .then((response: AxiosResponse) => resolve(response)) - .catch((error: AxiosError) => reject(error)); - }); -}; + .catch((error: AxiosError) => reject(error)) + }) +} export const searchFsEntities = ( searchString: string ): Promise> => { - const config = { params: { name: searchString } }; + const config = { params: { name: searchString } } return new Promise((resolve, reject) => { Axios.get(hostname + filesystemPath + "search", config) .then((response: AxiosResponse) => resolve(response)) - .catch((error: AxiosError) => reject(error)); - }); -}; + .catch((error: AxiosError) => reject(error)) + }) +} function handleMultipleApiActions( items: Type[], @@ -168,9 +168,9 @@ function handleMultipleApiActions( type: ApiActionType, apiAction?: ApiAction ) { - let currentIndex; + let currentIndex if (!apiAction) { - currentIndex = 0; + currentIndex = 0 apiAction = { key: Date.now() + type, timestamp: Date.now(), @@ -178,45 +178,43 @@ function handleMultipleApiActions( status: ApiActionStatus.ONGOING, progress: currentIndex, totalAmount: items.length, - currentFsEntity: items[0] - }; - store.dispatch(addApiAction(apiAction)); + currentFsEntity: items[0], + } + store.dispatch(addApiAction(apiAction)) } else { // get the info from the store apiAction = store .getState() - .apiActions.actions.find( - (a: ApiAction) => a.key === apiAction?.key - ); + .apiActions.actions.find((a: ApiAction) => a.key === apiAction?.key) if ( !apiAction || apiAction.status === ApiActionStatus.ABORTED || apiAction.status === ApiActionStatus.ERROR ) { - return; + return } - currentIndex = apiAction.progress + 1; + currentIndex = apiAction.progress + 1 console.log( "current amout " + currentIndex + " total: " + apiAction.totalAmount - ); + ) if (currentIndex === apiAction.totalAmount) { store.dispatch( changeStatus({ key: apiAction.key, - status: ApiActionStatus.FINISHED + status: ApiActionStatus.FINISHED, }) - ); - return; + ) + return } else { - console.log("dispatch nextFsEntity"); + console.log("dispatch nextFsEntity") store.dispatch( nextFsEntity({ key: apiAction.key, - currentFsEntity: items[currentIndex] + currentFsEntity: items[currentIndex], }) - ); + ) } } @@ -224,17 +222,17 @@ function handleMultipleApiActions( .then((response) => { console.log( "[API filesystem] handleMultipleApiActions next iteration" - ); - handleMultipleApiActions(items, action, type, apiAction); + ) + handleMultipleApiActions(items, action, type, apiAction) }) .catch((error) => { - console.log("errorr", error); + console.log("errorr", error) store.dispatch( changeStatus({ key: apiAction?.key ?? "ts sucks", status: ApiActionStatus.ERROR, - error: error.response?.data.message + error: error.response?.data.message, }) - ); - }); + ) + }) } diff --git a/src/background/api/filesystemTypes.ts b/src/background/api/filesystemTypes.ts index e6fed5dc..1025ac04 100644 --- a/src/background/api/filesystemTypes.ts +++ b/src/background/api/filesystemTypes.ts @@ -1,31 +1,31 @@ export interface UsersSet { - groups: string[]; - id: number; - username: string; + groups: string[] + id: number + username: string } export interface PermissionSet { - editableForGroups: string[]; - editableForUsers: UsersSet[]; - visibleForGroups: string[]; - visibleForUsers: UsersSet[]; + editableForGroups: string[] + editableForUsers: UsersSet[] + visibleForGroups: string[] + visibleForUsers: UsersSet[] } export interface User { - userId: number; - username: string; - groups: string[]; + userId: number + username: string + groups: string[] } export interface FsEntity { - owner: User; - lastUpdatedBy: User; - fileSystemId: number; - lastUpdated: number; - name: string; - path: string; - shared: boolean; - size: number; - type: string; - mimeType: string; + owner: User + lastUpdatedBy: User + fileSystemId: number + lastUpdated: number + name: string + path: string + shared: boolean + size: number + type: string + mimeType: string } diff --git a/src/background/api/registration.ts b/src/background/api/registration.ts index 765a48c2..05ea2865 100644 --- a/src/background/api/registration.ts +++ b/src/background/api/registration.ts @@ -1,11 +1,11 @@ -import Axios, { AxiosError, AxiosResponse } from "axios"; -import { hostname, userPath } from "./api"; -import { hashPassword } from "../methods/passwords"; +import Axios, { AxiosError, AxiosResponse } from "axios" +import { hostname, userPath } from "./api" +import { hashPassword } from "../methods/passwords" export interface IRegisterServerResponse { - httpStatus: number; - httpMessage: string; - outputMessage?: string; + httpStatus: number + httpMessage: string + outputMessage?: string } export const registerNewUser = async ( @@ -14,39 +14,39 @@ export const registerNewUser = async ( passwordConfirmation: string ): Promise => { if (password !== passwordConfirmation) { - throw new Error("Password did not match passwordConfirmation"); + throw new Error("Password did not match passwordConfirmation") } - let hashedPassword = await hashPassword(password); + let hashedPassword = await hashPassword(password) return new Promise((resolve, reject) => { const newUser = { username: username, password: hashedPassword, - confirmationPassword: hashedPassword - }; + confirmationPassword: hashedPassword, + } return Axios.post(hostname + userPath + "/register", newUser) .then((data: AxiosResponse) => { - console.log(data); + console.log(data) const response: IRegisterServerResponse = { httpStatus: data.status, - httpMessage: data.statusText - }; + httpMessage: data.statusText, + } if (data.status === 201) { - response.outputMessage = "User was successfully created."; + response.outputMessage = "User was successfully created." } - resolve(response); + resolve(response) }) .catch((error: AxiosError) => { - console.log(error.response); + console.log(error.response) const response: IRegisterServerResponse = { httpStatus: error.response?.status ?? 500, httpMessage: error.response?.statusText ?? "Internal Server Error", outputMessage: - error.response?.data.message ?? "Internal Server Error" - }; - reject(response); - }); - }); -}; + error.response?.data.message ?? "Internal Server Error", + } + reject(response) + }) + }) +} diff --git a/src/background/api/userInformation.ts b/src/background/api/userInformation.ts index 696e52c3..7bdf9520 100644 --- a/src/background/api/userInformation.ts +++ b/src/background/api/userInformation.ts @@ -1,35 +1,35 @@ -import Axios, { AxiosResponse } from "axios"; +import Axios, { AxiosResponse } from "axios" -import { hostname, userPath } from "./api"; +import { hostname, userPath } from "./api" -import store from "../redux/store"; -import { updateUser } from "../redux/actions/user"; -import { UserState } from "../redux/actions/userTypes"; +import store from "../redux/store" +import { updateUser } from "../redux/actions/user" +import { UserState } from "../redux/actions/userTypes" export interface UserInformation { - userId: number | null; - username?: string | null; - groups?: string[] | null; - password?: string; - confirmationPassword?: string; + userId: number | null + username?: string | null + groups?: string[] | null + password?: string + confirmationPassword?: string } export const changeUserInformation = ( userWithNewInformation: UserInformation ): Promise => { - console.log("[API] userinformation: User given to update user api:"); - console.log(userWithNewInformation); + console.log("[API] userinformation: User given to update user api:") + console.log(userWithNewInformation) return new Promise((resolve, reject) => { return Axios.put( `${hostname}${userPath}/${userWithNewInformation.userId}/edit`, userWithNewInformation ) .then((response: AxiosResponse) => { - store.dispatch(updateUser(JSON.parse(response.config.data))); - resolve(response.data); + store.dispatch(updateUser(JSON.parse(response.config.data))) + resolve(response.data) }) .catch((error) => { - reject(error.response?.data?.message); - }); - }); -}; + reject(error.response?.data?.message) + }) + }) +} diff --git a/src/background/constants.ts b/src/background/constants.ts index 7349747d..bdace2a4 100644 --- a/src/background/constants.ts +++ b/src/background/constants.ts @@ -1,13 +1,13 @@ interface constantsdef { - url: { API_URL: string; FH_URL: string }; + url: { API_URL: string; FH_URL: string } } const prod: constantsdef = { url: { API_URL: window.location.origin + "/api", - FH_URL: window.location.origin + "/data" - } -}; + FH_URL: window.location.origin + "/data", + }, +} const dev: constantsdef = { url: { @@ -16,11 +16,11 @@ const dev: constantsdef = { //API_URL: "http://localhost/api", //FH_URL: "http://localhost:5000/data" //FH_URL: "http://localhost/data" - FH_URL: "https://demo.filefighter.de/data" - } -}; -export const constants = process.env.NODE_ENV === "development" ? dev : prod; + FH_URL: "https://demo.filefighter.de/data", + }, +} +export const constants = process.env.NODE_ENV === "development" ? dev : prod -export const MIN_PASSWORD_LENGTH = 8; -export const MAX_PASSWORD_LENGTH = 20; -export const DEFAULT_ALERT_DURATION = 3500; +export const MIN_PASSWORD_LENGTH = 8 +export const MAX_PASSWORD_LENGTH = 20 +export const DEFAULT_ALERT_DURATION = 3500 diff --git a/src/background/methods/checkInput.ts b/src/background/methods/checkInput.ts index 8bb38c7c..24a778a0 100644 --- a/src/background/methods/checkInput.ts +++ b/src/background/methods/checkInput.ts @@ -1,7 +1,7 @@ export function notMinStrLength(text: string, minAnz: number): boolean { - return text.length < minAnz; + return text.length < minAnz } export function biggerMaxStrLength(text: string, maxAnz: number): boolean { - return text.length > maxAnz; + return text.length > maxAnz } diff --git a/src/background/methods/cookies.ts b/src/background/methods/cookies.ts index 05365803..f9b2bca1 100644 --- a/src/background/methods/cookies.ts +++ b/src/background/methods/cookies.ts @@ -1,27 +1,27 @@ export function getCookie(cname: string) { - let name = cname + "="; - let decodedCookie = decodeURIComponent(document.cookie); - let ca = decodedCookie.split(";"); + let name = cname + "=" + let decodedCookie = decodeURIComponent(document.cookie) + let ca = decodedCookie.split(";") for (let i = 0; i < ca.length; i++) { - let c = ca[i]; + let c = ca[i] while (c.charAt(0) === " ") { - c = c.substring(1); + c = c.substring(1) } if (c.indexOf(name) === 0) { - return c.substring(name.length, c.length); + return c.substring(name.length, c.length) } } - return ""; + return "" } export function setCookie(cname: string, cvalue: string, exdays: number) { - let d = new Date(); - d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); - let expires = "expires=" + d.toUTCString(); - document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; + let d = new Date() + d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000) + let expires = "expires=" + d.toUTCString() + document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/" } export function deleteCookie(cname: string) { document.cookie = - cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; + cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;" } diff --git a/src/background/methods/dataTypes/arrays.ts b/src/background/methods/dataTypes/arrays.ts index 981ed031..a5544d06 100644 --- a/src/background/methods/dataTypes/arrays.ts +++ b/src/background/methods/dataTypes/arrays.ts @@ -2,14 +2,14 @@ export function divideArrayByCondition( input: T[], condition: (a: T) => boolean ) { - let output: T[][] = [[], []]; + let output: T[][] = [[], []] input.forEach((el: T) => { if (!condition(el)) { - return output[1].push(el); + return output[1].push(el) } - output[0].push(el); - }); + output[0].push(el) + }) - return output; + return output } diff --git a/src/background/methods/dataTypes/bytes.ts b/src/background/methods/dataTypes/bytes.ts index 749528eb..2eb1a385 100644 --- a/src/background/methods/dataTypes/bytes.ts +++ b/src/background/methods/dataTypes/bytes.ts @@ -1,8 +1,8 @@ export function formatBytes(bytes: number, decimals: number = 2): string { - if (bytes === 0) return "0 Bytes"; + if (bytes === 0) return "0 Bytes" - const k: number = 1024; - const dm: number = decimals < 0 ? 0 : decimals; + const k: number = 1024 + const dm: number = decimals < 0 ? 0 : decimals const sizes: string[] = [ "Bytes", "KB", @@ -12,10 +12,10 @@ export function formatBytes(bytes: number, decimals: number = 2): string { "PB", "EB", "ZB", - "YB" - ]; + "YB", + ] - const i: number = Math.floor(Math.log(bytes) / Math.log(k)); + const i: number = Math.floor(Math.log(bytes) / Math.log(k)) - return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i]; + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i] } diff --git a/src/background/methods/dataTypes/objects/ObjectKeysTS.ts b/src/background/methods/dataTypes/objects/ObjectKeysTS.ts index 5eaa386c..bc169437 100644 --- a/src/background/methods/dataTypes/objects/ObjectKeysTS.ts +++ b/src/background/methods/dataTypes/objects/ObjectKeysTS.ts @@ -5,5 +5,5 @@ // in TS 3.0+, putting just "string" raises an error // https://dev.to/kingdaro/indexing-objects-in-typescript-1cgi export function hasKey(obj: O, key: keyof any): key is keyof O { - return key in obj; + return key in obj } diff --git a/src/background/methods/dataTypes/objects/objectEquals.ts b/src/background/methods/dataTypes/objects/objectEquals.ts index 5f0c8826..41fe2d13 100644 --- a/src/background/methods/dataTypes/objects/objectEquals.ts +++ b/src/background/methods/dataTypes/objects/objectEquals.ts @@ -1,18 +1,18 @@ function objectEquals(object1: object | any, object2: object | any): boolean { - let areEqual = true; + let areEqual = true //keylength if (Object.keys(object1).length === Object.keys(object2).length) - return false; + return false //compare keys Object.keys(object1).forEach((key) => { if (object1[key] !== object2[key]) { - areEqual = false; + areEqual = false } - }); + }) - return areEqual; + return areEqual } -export default objectEquals; +export default objectEquals diff --git a/src/background/methods/dataTypes/strings.ts b/src/background/methods/dataTypes/strings.ts index d5a48c67..3bfc5099 100644 --- a/src/background/methods/dataTypes/strings.ts +++ b/src/background/methods/dataTypes/strings.ts @@ -1,6 +1,6 @@ export function reverseString(string: string): string { - if (string === "") return ""; - else return reverseString(string.substr(1)) + string.charAt(0); + if (string === "") return "" + else return reverseString(string.substr(1)) + string.charAt(0) } export function stringReplaceSubstringOneTimeFromBeginningAndEnd( @@ -8,24 +8,24 @@ export function stringReplaceSubstringOneTimeFromBeginningAndEnd( substring: string, replaceWith: string ): string { - string = string.replace(substring, replaceWith); - string = reverseString(string); - string = string.replace(substring, replaceWith); - string = reverseString(string); - return string; + string = string.replace(substring, replaceWith) + string = reverseString(string) + string = string.replace(substring, replaceWith) + string = reverseString(string) + return string } export function deleteSpaces(string: string): string { - return string.replace(/\s/, ""); + return string.replace(/\s/, "") } export function trimString(string: string, maxLength: number): string { - return string.length > maxLength ? string.substr(0, maxLength - 1) : string; + return string.length > maxLength ? string.substr(0, maxLength - 1) : string } export function trimStringWithDotsAtEnd( string: string, maxLength: number ): string { - return trimString(string, maxLength) + "…"; + return trimString(string, maxLength) + "…" } diff --git a/src/background/methods/dataTypes/time.ts b/src/background/methods/dataTypes/time.ts index 7f41e862..9a743508 100644 --- a/src/background/methods/dataTypes/time.ts +++ b/src/background/methods/dataTypes/time.ts @@ -1,24 +1,24 @@ function getTimeStamp(): number { - return Math.round(new Date().getTime() / 1000); + return Math.round(new Date().getTime() / 1000) } function getTimeStampFromDate(date: Date): number { - return Math.round(new Date(date).getTime() / 1000); + return Math.round(new Date(date).getTime() / 1000) } function getRelativeTime(ts: number): string { - const diff = Number(new Date()) - ts * 1000; - const minute = 60 * 1000; - const hour = minute * 60; + const diff = Number(new Date()) - ts * 1000 + const minute = 60 * 1000 + const hour = minute * 60 /* const day = hour * 24; const month = day * 30; const year = day * 365;*/ switch (true) { case diff < minute: - return "just now"; + return "just now" case diff < hour: - const minutes = Math.round(diff / minute); - return `${minutes} minute${minutes > 1 ? "s" : ""} ago`; + const minutes = Math.round(diff / minute) + return `${minutes} minute${minutes > 1 ? "s" : ""} ago` /* case diff < day: const hours = Math.round(diff / hour); return `${hours} hour${hours > 1 ? "s" : ""} ago`; @@ -32,41 +32,41 @@ function getRelativeTime(ts: number): string { const years = Math.round(diff / year); return `${years} year${years > 1 ? "s" : ""} ago`;*/ default: - return ""; + return "" } } function getDateAsStringFromTimestamp(ts: number): string { - const relativeTime = getRelativeTime(ts); + const relativeTime = getRelativeTime(ts) if (relativeTime) { - return relativeTime; + return relativeTime } - let dateFromTs = new Date(ts * 1000); - let year = dateFromTs.getFullYear(); - let month = dateFromTs.getMonth() + 1; - let date = dateFromTs.getDate(); - return date + "." + month + "." + year; + let dateFromTs = new Date(ts * 1000) + let year = dateFromTs.getFullYear() + let month = dateFromTs.getMonth() + 1 + let date = dateFromTs.getDate() + return date + "." + month + "." + year } // 1 day 20 hours 29 minutes, 10 seconds function getDurationAsString(duration: number): string { // props to https://stackoverflow.com/questions/36098913/convert-seconds-to-days-hours-minutes-and-seconds - let d = Math.floor(duration / (3600 * 24)); - let h = Math.floor((duration % (3600 * 24)) / 3600); - let m = Math.floor((duration % 3600) / 60); - let s = Math.floor(duration % 60); + let d = Math.floor(duration / (3600 * 24)) + let h = Math.floor((duration % (3600 * 24)) / 3600) + let m = Math.floor((duration % 3600) / 60) + let s = Math.floor(duration % 60) - let dDisplay = d > 0 ? d + (d === 1 ? " day, " : " days, ") : ""; - let hDisplay = h > 0 ? h + (h === 1 ? " hour, " : " hours, ") : ""; - let mDisplay = m > 0 ? m + (m === 1 ? " minute, " : " minutes, ") : ""; - let sDisplay = s > 0 ? s + (s === 1 ? " second" : " seconds") : ""; - return dDisplay + hDisplay + mDisplay + sDisplay; + let dDisplay = d > 0 ? d + (d === 1 ? " day, " : " days, ") : "" + let hDisplay = h > 0 ? h + (h === 1 ? " hour, " : " hours, ") : "" + let mDisplay = m > 0 ? m + (m === 1 ? " minute, " : " minutes, ") : "" + let sDisplay = s > 0 ? s + (s === 1 ? " second" : " seconds") : "" + return dDisplay + hDisplay + mDisplay + sDisplay } export { getTimeStamp, getDateAsStringFromTimestamp, getTimeStampFromDate, - getDurationAsString -}; + getDurationAsString, +} diff --git a/src/background/methods/filesystem.ts b/src/background/methods/filesystem.ts index 1d64d805..94caf5b9 100644 --- a/src/background/methods/filesystem.ts +++ b/src/background/methods/filesystem.ts @@ -1,43 +1,39 @@ -import { FsEntity } from "../api/filesystemTypes"; -import { reverseString } from "./dataTypes/strings"; +import { FsEntity } from "../api/filesystemTypes" +import { reverseString } from "./dataTypes/strings" export const getPathWithoutName = ( pathWithName: string, name: string ): string => { - return pathWithName.substr(0, pathWithName.lastIndexOf(name.toLowerCase())); -}; + return pathWithName.substr(0, pathWithName.lastIndexOf(name.toLowerCase())) +} export const removeTrailingBackslash = (path: string): string => { if (path.lastIndexOf("/") + 1 === path.length) { - return path.substr(0, path.length - 1); + return path.substr(0, path.length - 1) } - return path; -}; + return path +} export const removeLeadingBackslash = (path: string): string => { if (path.indexOf("/") === 0) { - return path.substr(1, path.length); + return path.substr(1, path.length) } - return path; -}; + return path +} export const isFsEntityInFolder = (fsEntity: FsEntity, path: string) => { - let fsEntityPath = getPathWithoutName(fsEntity.path, fsEntity.name); - fsEntityPath = removeTrailingBackslash(fsEntityPath); + let fsEntityPath = getPathWithoutName(fsEntity.path, fsEntity.name) + fsEntityPath = removeTrailingBackslash(fsEntityPath) - return fsEntityPath === path.toLocaleLowerCase(); -}; + return fsEntityPath === path.toLocaleLowerCase() +} export const getFileExtension = (fileName: string): string => { - let positionOfPoint = reverseString(fileName).indexOf("."); - return reverseString(reverseString(fileName).substr(0, positionOfPoint)); -}; + let positionOfPoint = reverseString(fileName).indexOf(".") + return reverseString(reverseString(fileName).substr(0, positionOfPoint)) +} export const isFileNameValid = (name: string) => { - return !( - !name || - name.includes("/") || - name.match('[~#@*+:!?&%<>|"^\\\\]') - ); -}; + return !(!name || name.includes("/") || name.match('[~#@*+:!?&%<>|"^\\\\]')) +} diff --git a/src/background/methods/grammar/germanGrammar.ts b/src/background/methods/grammar/germanGrammar.ts index 96910929..c3f70b1c 100644 --- a/src/background/methods/grammar/germanGrammar.ts +++ b/src/background/methods/grammar/germanGrammar.ts @@ -1,14 +1,14 @@ function genitiveOfWord(name: string): string { // checks if "s" can be used for name's plural or if an apostrophe has to be used - let lastLetter = name[name.length - 1]; - let lastTwoLetters = name.substr(name.length - 2, 2).toLowerCase(); + let lastLetter = name[name.length - 1] + let lastTwoLetters = name.substr(name.length - 2, 2).toLowerCase() return lastLetter === "s" || lastLetter === "ß" || lastLetter === "z" || lastLetter === "x" || lastTwoLetters === "ce" ? name + "'" - : name + "s"; + : name + "s" } -export { genitiveOfWord }; +export { genitiveOfWord } diff --git a/src/background/methods/passwords.ts b/src/background/methods/passwords.ts index d9f9b599..40111f2e 100644 --- a/src/background/methods/passwords.ts +++ b/src/background/methods/passwords.ts @@ -1,21 +1,21 @@ //see: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest -import sha256 from "./sha256"; +import sha256 from "./sha256" -const salt = "FileFighterWithSomeSalt"; +const salt = "FileFighterWithSomeSalt" async function hashPassword(password: string) { if (!crypto.subtle) { - return sha256(password + salt)?.toUpperCase(); + return sha256(password + salt)?.toUpperCase() } - const msgUint8 = new TextEncoder().encode(password + salt); // encode as (utf-8) Uint8Array - const hashBuffer = await crypto.subtle.digest("SHA-256", msgUint8); // hash the message - const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array + const msgUint8 = new TextEncoder().encode(password + salt) // encode as (utf-8) Uint8Array + const hashBuffer = await crypto.subtle.digest("SHA-256", msgUint8) // hash the message + const hashArray = Array.from(new Uint8Array(hashBuffer)) // convert buffer to byte array const hashHex = hashArray .map((b) => b.toString(16).padStart(2, "0")) - .join(""); // convert bytes to hex string - return hashHex.toUpperCase(); + .join("") // convert bytes to hex string + return hashHex.toUpperCase() } -export { hashPassword }; +export { hashPassword } diff --git a/src/background/methods/redirect.ts b/src/background/methods/redirect.ts index b67eca15..b13afdc9 100644 --- a/src/background/methods/redirect.ts +++ b/src/background/methods/redirect.ts @@ -4,21 +4,21 @@ const scrollToElement = ( event?: { preventDefault: () => void } ): void => { //Replaces anchor for React - console.log("Scrolled to " + id); - event?.preventDefault(); + console.log("Scrolled to " + id) + event?.preventDefault() if (id) { - const element = document.getElementById(id); - element?.scrollIntoView(); + const element = document.getElementById(id) + element?.scrollIntoView() } -}; +} const redirect = ( history: { push: (path: string) => void }, path: string, event?: { preventDefault: () => void } ): void => { - console.log("Redirected to " + path); - event?.preventDefault(); - if (path !== window.location.pathname) history.push(path); -}; + console.log("Redirected to " + path) + event?.preventDefault() + if (path !== window.location.pathname) history.push(path) +} -export { redirect, scrollToElement }; +export { redirect, scrollToElement } diff --git a/src/background/methods/sha256.js b/src/background/methods/sha256.js index d60d84c4..e400e4c9 100644 --- a/src/background/methods/sha256.js +++ b/src/background/methods/sha256.js @@ -2,64 +2,64 @@ export default function sha256(ascii) { function rightRotate(value, amount) { - return (value >>> amount) | (value << (32 - amount)); + return (value >>> amount) | (value << (32 - amount)) } - const mathPow = Math.pow; - let maxWord = mathPow(2, 32); - let lengthProperty = "length"; - let i, j; // Used as a counter across the whole file - let result = ""; + const mathPow = Math.pow + let maxWord = mathPow(2, 32) + let lengthProperty = "length" + let i, j // Used as a counter across the whole file + let result = "" - let words = []; - let asciiBitLength = ascii[lengthProperty] * 8; + let words = [] + let asciiBitLength = ascii[lengthProperty] * 8 //* caching results is optional - remove/add slash from front of this line to toggle // Initial hash value: first 32 bits of the fractional parts of the square roots of the first 8 primes // (we actually calculate the first 64, but extra values are just ignored) - let hash = (sha256.h = sha256.h || []); + let hash = (sha256.h = sha256.h || []) // Round constants: first 32 bits of the fractional parts of the cube roots of the first 64 primes - let k = (sha256.k = sha256.k || []); - let primeCounter = k[lengthProperty]; + let k = (sha256.k = sha256.k || []) + let primeCounter = k[lengthProperty] - let isComposite = {}; + let isComposite = {} for (let candidate = 2; primeCounter < 64; candidate++) { if (!isComposite[candidate]) { for (i = 0; i < 313; i += candidate) { - isComposite[i] = candidate; + isComposite[i] = candidate } - hash[primeCounter] = (mathPow(candidate, 0.5) * maxWord) | 0; - k[primeCounter++] = (mathPow(candidate, 1 / 3) * maxWord) | 0; + hash[primeCounter] = (mathPow(candidate, 0.5) * maxWord) | 0 + k[primeCounter++] = (mathPow(candidate, 1 / 3) * maxWord) | 0 } } - ascii += "\x80"; // Append Ƈ' bit (plus zero padding) - while ((ascii[lengthProperty] % 64) - 56) ascii += "\x00"; // More zero padding + ascii += "\x80" // Append Ƈ' bit (plus zero padding) + while ((ascii[lengthProperty] % 64) - 56) ascii += "\x00" // More zero padding for (i = 0; i < ascii[lengthProperty]; i++) { - j = ascii.charCodeAt(i); - if (j >> 8) return; // ASCII check: only accept characters in range 0-255 - words[i >> 2] |= j << (((3 - i) % 4) * 8); + j = ascii.charCodeAt(i) + if (j >> 8) return // ASCII check: only accept characters in range 0-255 + words[i >> 2] |= j << (((3 - i) % 4) * 8) } - words[words[lengthProperty]] = (asciiBitLength / maxWord) | 0; - words[words[lengthProperty]] = asciiBitLength; + words[words[lengthProperty]] = (asciiBitLength / maxWord) | 0 + words[words[lengthProperty]] = asciiBitLength // process each chunk for (j = 0; j < words[lengthProperty]; ) { - let w = words.slice(j, (j += 16)); // The message is expanded into 64 words as part of the iteration - let oldHash = hash; + let w = words.slice(j, (j += 16)) // The message is expanded into 64 words as part of the iteration + let oldHash = hash // This is now the undefinedworking hash", often labelled as variables a...g // (we have to truncate as well, otherwise extra entries at the end accumulate - hash = hash.slice(0, 8); + hash = hash.slice(0, 8) for (i = 0; i < 64; i++) { // Expand the message into 64 words // Used below if let w15 = w[i - 15], - w2 = w[i - 2]; + w2 = w[i - 2] // Iterate let a = hash[0], - e = hash[4]; + e = hash[4] let temp1 = hash[7] + (rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25)) + // S1 @@ -77,26 +77,26 @@ export default function sha256(ascii) { (rightRotate(w2, 17) ^ rightRotate(w2, 19) ^ (w2 >>> 10))) | // s1 - 0); + 0) // This is only used once, so *could* be moved below, but it only saves 4 bytes and makes things unreadble let temp2 = (rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22)) + // S0 - ((a & hash[1]) ^ (a & hash[2]) ^ (hash[1] & hash[2])); // maj + ((a & hash[1]) ^ (a & hash[2]) ^ (hash[1] & hash[2])) // maj - hash = [(temp1 + temp2) | 0].concat(hash); // We don't bother trimming off the extra ones, they're harmless as long as we're truncating when we do the slice() - hash[4] = (hash[4] + temp1) | 0; + hash = [(temp1 + temp2) | 0].concat(hash) // We don't bother trimming off the extra ones, they're harmless as long as we're truncating when we do the slice() + hash[4] = (hash[4] + temp1) | 0 } for (i = 0; i < 8; i++) { - hash[i] = (hash[i] + oldHash[i]) | 0; + hash[i] = (hash[i] + oldHash[i]) | 0 } } for (i = 0; i < 8; i++) { for (j = 3; j + 1; j--) { - let b = (hash[i] >> (j * 8)) & 255; - result += (b < 16 ? 0 : "") + b.toString(16); + let b = (hash[i] >> (j * 8)) & 255 + result += (b < 16 ? 0 : "") + b.toString(16) } } - return result; + return result } diff --git a/src/background/methods/sound.js b/src/background/methods/sound.js index 6fd67cfb..51e00bbf 100644 --- a/src/background/methods/sound.js +++ b/src/background/methods/sound.js @@ -1,22 +1,22 @@ function playAudioByID(audioID) { - document.getElementById(audioID).play(); + document.getElementById(audioID).play() } function pauseAudioByID(audioID) { - document.getElementById(audioID).pause(); + document.getElementById(audioID).pause() } function setAudioVolumeByID(audioID, volume) { //0.0 - 1.0 - document.getElementById(audioID).volume = volume; + document.getElementById(audioID).volume = volume } function audioOnOff(audioID) { if (document.getElementById(audioID).paused) { - playAudioByID(audioID); + playAudioByID(audioID) } else { - pauseAudioByID(audioID); + pauseAudioByID(audioID) } } -export { pauseAudioByID, playAudioByID, setAudioVolumeByID, audioOnOff }; +export { pauseAudioByID, playAudioByID, setAudioVolumeByID, audioOnOff } diff --git a/src/background/methods/style.js b/src/background/methods/style.js index 2b6f3c08..c430a0ec 100644 --- a/src/background/methods/style.js +++ b/src/background/methods/style.js @@ -1,15 +1,15 @@ export function getStyleValue(element, strCssRule) { //https://stackoverflow.com/questions/5227909/how-to-get-an-elements-padding-value-using-javascript - let strValue = ""; + let strValue = "" if (document.defaultView && document.defaultView.getComputedStyle) { strValue = document.defaultView .getComputedStyle(element, "") - .getPropertyValue(strCssRule); + .getPropertyValue(strCssRule) } else if (element.currentStyle) { strCssRule = strCssRule.replace(/(\w)/g, function (strMatch, p1) { - return p1.toUpperCase(); - }); - strValue = element.currentStyle[strCssRule]; + return p1.toUpperCase() + }) + strValue = element.currentStyle[strCssRule] } - return strValue; + return strValue } diff --git a/src/background/methods/windowSize.ts b/src/background/methods/windowSize.ts index 4b8c508c..d60afdc1 100644 --- a/src/background/methods/windowSize.ts +++ b/src/background/methods/windowSize.ts @@ -1,16 +1,16 @@ export interface getWindowSize_Interface { - viewportWidth: number; - viewportHeight: number; + viewportWidth: number + viewportHeight: number } export function getWindowSize(): getWindowSize_Interface { - let viewportwidth: number; - let viewportheight: number; + let viewportwidth: number + let viewportheight: number // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight if (typeof window.innerWidth != "undefined") { - viewportwidth = window.innerWidth; - viewportheight = window.innerHeight; + viewportwidth = window.innerWidth + viewportheight = window.innerHeight } // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) @@ -18,17 +18,17 @@ export function getWindowSize(): getWindowSize_Interface { typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != ("undefined" || 0) ) { - viewportwidth = document.documentElement.clientWidth; - viewportheight = document.documentElement.clientHeight; + viewportwidth = document.documentElement.clientWidth + viewportheight = document.documentElement.clientHeight } // older versions of IE else { - viewportwidth = document.getElementsByTagName("body")[0].clientWidth; - viewportheight = document.getElementsByTagName("body")[0].clientHeight; + viewportwidth = document.getElementsByTagName("body")[0].clientWidth + viewportheight = document.getElementsByTagName("body")[0].clientHeight } return { viewportHeight: viewportheight, - viewportWidth: viewportwidth - }; + viewportWidth: viewportwidth, + } } diff --git a/src/background/redux/actions/apiActions.ts b/src/background/redux/actions/apiActions.ts index aa4e211d..9e81b9cf 100644 --- a/src/background/redux/actions/apiActions.ts +++ b/src/background/redux/actions/apiActions.ts @@ -9,25 +9,25 @@ import { NextFsEntity, NextFsEntityPayload, REPLACE_API_ACTION, - ReplaceApiAction -} from "./apiActionsTypes"; + ReplaceApiAction, +} from "./apiActionsTypes" export const addApiAction = (content: ApiAction): AddApiAction => ({ type: ADD_API_ACTION, - payload: content -}); + payload: content, +}) export const replaceApiAction = (content: ApiAction): ReplaceApiAction => ({ type: REPLACE_API_ACTION, - payload: content -}); + payload: content, +}) export const changeStatus = (content: ChangeStatusPayload): ChangeStatus => ({ type: CHANGE_STATUS, - payload: content -}); + payload: content, +}) export const nextFsEntity = (content: NextFsEntityPayload): NextFsEntity => ({ type: NEXT_FS_ENTITY, - payload: content -}); + payload: content, +}) diff --git a/src/background/redux/actions/apiActionsTypes.ts b/src/background/redux/actions/apiActionsTypes.ts index fedfecb6..c3aa5535 100644 --- a/src/background/redux/actions/apiActionsTypes.ts +++ b/src/background/redux/actions/apiActionsTypes.ts @@ -1,69 +1,69 @@ -import { FsEntity } from "../../api/filesystemTypes"; +import { FsEntity } from "../../api/filesystemTypes" -export const ADD_API_ACTION = "ADD_API_ACTION"; -export const REPLACE_API_ACTION = "REPLACE_API_ACTION"; -export const CHANGE_STATUS = "CHANGE_STATUS"; -export const NEXT_FS_ENTITY = "NEXT_FS_ENTITY"; +export const ADD_API_ACTION = "ADD_API_ACTION" +export const REPLACE_API_ACTION = "REPLACE_API_ACTION" +export const CHANGE_STATUS = "CHANGE_STATUS" +export const NEXT_FS_ENTITY = "NEXT_FS_ENTITY" export interface ApiActionsState { - actions: ApiAction[]; + actions: ApiAction[] } export interface ApiAction { - key: string; - timestamp: number; - type: ApiActionType; - status: ApiActionStatus; - progress: number; - totalAmount: number; - currentFsEntity: FsEntity | File; - error?: string; + key: string + timestamp: number + type: ApiActionType + status: ApiActionStatus + progress: number + totalAmount: number + currentFsEntity: FsEntity | File + error?: string } export enum ApiActionType { UPLOAD = "Uploading", - DELETE = "Deleting" + DELETE = "Deleting", } export enum ApiActionStatus { ONGOING = "Ongoing", ABORTED = "Aborted", ERROR = "Error", - FINISHED = "Finished" + FINISHED = "Finished", } export interface AddApiAction { - type: typeof ADD_API_ACTION; - payload: ApiAction; + type: typeof ADD_API_ACTION + payload: ApiAction } export interface ReplaceApiAction { - type: typeof REPLACE_API_ACTION; - payload: ApiAction; + type: typeof REPLACE_API_ACTION + payload: ApiAction } export interface ChangeStatusPayload { - key: string; - status: ApiActionStatus; - error?: string; + key: string + status: ApiActionStatus + error?: string } export interface ChangeStatus { - type: typeof CHANGE_STATUS; - payload: ChangeStatusPayload; + type: typeof CHANGE_STATUS + payload: ChangeStatusPayload } export interface NextFsEntityPayload { - key: string; - currentFsEntity: FsEntity | File; + key: string + currentFsEntity: FsEntity | File } export interface NextFsEntity { - type: typeof NEXT_FS_ENTITY; - payload: NextFsEntityPayload; + type: typeof NEXT_FS_ENTITY + payload: NextFsEntityPayload } export type ApiActionsTypes = | ChangeStatus | ReplaceApiAction | AddApiAction - | NextFsEntity; + | NextFsEntity diff --git a/src/background/redux/actions/filesystem.ts b/src/background/redux/actions/filesystem.ts index f75f59f4..e067b0b2 100644 --- a/src/background/redux/actions/filesystem.ts +++ b/src/background/redux/actions/filesystem.ts @@ -1,4 +1,4 @@ -import { FsEntity } from "../../api/filesystemTypes"; +import { FsEntity } from "../../api/filesystemTypes" import { ADD_TO_CONTENTS, ADD_TO_SELECTED, @@ -17,49 +17,49 @@ import { SET_CURRENT_PATH, SetContents, SetCurrentFsItemId, - SetCurrentPath -} from "./filesystemTypes"; + SetCurrentPath, +} from "./filesystemTypes" export const addToSelected = (content: FsEntity): AddToSelected => ({ type: ADD_TO_SELECTED, - payload: content -}); + payload: content, +}) export const removeFromSelected = (content: FsEntity): RemoveFromSelected => ({ type: REMOVE_FROM_SELECTED, - payload: content -}); + payload: content, +}) export const clearSelected = (): ClearSelected => ({ - type: CLEAR_SELECTED -}); + type: CLEAR_SELECTED, +}) export const replaceSelected = (content: FsEntity[]): ReplaceSelected => ({ type: REPLACE_SELECTED, - payload: content -}); + payload: content, +}) export const setContents = (content: FsEntity[]): SetContents => ({ type: SET_CONTENTS, - payload: content -}); + payload: content, +}) export const addToContents = (content: FsEntity): AddToContents => ({ type: ADD_TO_CONTENTS, - payload: content -}); + payload: content, +}) export const removeFromContents = (content: FsEntity): RemoveFromContents => ({ type: REMOVE_FROM_CONTENTS, - payload: content -}); + payload: content, +}) export const setCurrentFsItemId = (content: string): SetCurrentFsItemId => ({ type: SET_CURRENT_FSITEMID, - payload: content -}); + payload: content, +}) export const setCurrentPath = (content: string): SetCurrentPath => ({ type: SET_CURRENT_PATH, - payload: content -}); + payload: content, +}) diff --git a/src/background/redux/actions/filesystemTypes.ts b/src/background/redux/actions/filesystemTypes.ts index 762b40c0..a1a3e624 100644 --- a/src/background/redux/actions/filesystemTypes.ts +++ b/src/background/redux/actions/filesystemTypes.ts @@ -1,61 +1,61 @@ -import { FsEntity } from "../../api/filesystemTypes"; +import { FsEntity } from "../../api/filesystemTypes" -export const ADD_TO_SELECTED = "ADD_TO_SELECTED"; -export const CLEAR_SELECTED = "CLEAR_SELECTED"; -export const REMOVE_FROM_SELECTED = "REMOVE_FROM_SELECTED"; -export const REPLACE_SELECTED = "REPLACE_SELECTED"; -export const SET_CURRENT_FSITEMID = "SET_CURRENT_FSITEMID"; -export const SET_CURRENT_PATH = "SET_CURRENT_PATH"; -export const SET_CONTENTS = "SET_CONTENTS"; -export const ADD_TO_CONTENTS = "ADD_TO_CONTENTS"; -export const REMOVE_FROM_CONTENTS = "REMOVE_FROM_CONTENTS"; +export const ADD_TO_SELECTED = "ADD_TO_SELECTED" +export const CLEAR_SELECTED = "CLEAR_SELECTED" +export const REMOVE_FROM_SELECTED = "REMOVE_FROM_SELECTED" +export const REPLACE_SELECTED = "REPLACE_SELECTED" +export const SET_CURRENT_FSITEMID = "SET_CURRENT_FSITEMID" +export const SET_CURRENT_PATH = "SET_CURRENT_PATH" +export const SET_CONTENTS = "SET_CONTENTS" +export const ADD_TO_CONTENTS = "ADD_TO_CONTENTS" +export const REMOVE_FROM_CONTENTS = "REMOVE_FROM_CONTENTS" export interface FilesystemState { - selectedFsEntities: FsEntity[]; - folderContents: FsEntity[]; - currentFsItemId: string; - currentPath: string; + selectedFsEntities: FsEntity[] + folderContents: FsEntity[] + currentFsItemId: string + currentPath: string } export interface AddToSelected { - type: typeof ADD_TO_SELECTED; - payload: FsEntity; + type: typeof ADD_TO_SELECTED + payload: FsEntity } export interface RemoveFromSelected { - type: typeof REMOVE_FROM_SELECTED; - payload: FsEntity; + type: typeof REMOVE_FROM_SELECTED + payload: FsEntity } export interface ClearSelected { - type: typeof CLEAR_SELECTED; + type: typeof CLEAR_SELECTED } export interface ReplaceSelected { - type: typeof REPLACE_SELECTED; - payload: FsEntity[]; + type: typeof REPLACE_SELECTED + payload: FsEntity[] } export interface SetCurrentFsItemId { - type: typeof SET_CURRENT_FSITEMID; - payload: string; + type: typeof SET_CURRENT_FSITEMID + payload: string } export interface SetCurrentPath { - type: typeof SET_CURRENT_PATH; - payload: string; + type: typeof SET_CURRENT_PATH + payload: string } export interface SetContents { - type: typeof SET_CONTENTS; - payload: FsEntity[]; + type: typeof SET_CONTENTS + payload: FsEntity[] } export interface AddToContents { - type: typeof ADD_TO_CONTENTS; - payload: FsEntity; + type: typeof ADD_TO_CONTENTS + payload: FsEntity } export interface RemoveFromContents { - type: typeof REMOVE_FROM_CONTENTS; - payload: FsEntity; + type: typeof REMOVE_FROM_CONTENTS + payload: FsEntity } export type FilesystemActionTypes = @@ -67,4 +67,4 @@ export type FilesystemActionTypes = | AddToContents | RemoveFromContents | SetCurrentFsItemId - | SetCurrentPath; + | SetCurrentPath diff --git a/src/background/redux/actions/sytemState.tsx b/src/background/redux/actions/sytemState.tsx index 3f52644b..cd4ca018 100644 --- a/src/background/redux/actions/sytemState.tsx +++ b/src/background/redux/actions/sytemState.tsx @@ -1,9 +1,9 @@ -import { TokensState } from "./tokenTypes"; -import { UserState } from "./userTypes"; -import { FilesystemState } from "./filesystemTypes"; +import { TokensState } from "./tokenTypes" +import { UserState } from "./userTypes" +import { FilesystemState } from "./filesystemTypes" export interface SystemState { - tokens: TokensState; - user: UserState; - filesystem: FilesystemState; + tokens: TokensState + user: UserState + filesystem: FilesystemState } diff --git a/src/background/redux/actions/tokenTypes.tsx b/src/background/redux/actions/tokenTypes.tsx index 8f384dfc..b4930842 100644 --- a/src/background/redux/actions/tokenTypes.tsx +++ b/src/background/redux/actions/tokenTypes.tsx @@ -1,46 +1,46 @@ -export const ADD_REFRESH_TOKEN = "ADD_REFRESH_TOKEN"; -export const ADD_ACCESS_TOKEN = "ADD_ACCESS_TOKEN"; -export const CHECKED_COOKIES = "CHECKED_COOKIES"; -export const REMOVE_TOKENS = "REMOVE_TOKENS"; +export const ADD_REFRESH_TOKEN = "ADD_REFRESH_TOKEN" +export const ADD_ACCESS_TOKEN = "ADD_ACCESS_TOKEN" +export const CHECKED_COOKIES = "CHECKED_COOKIES" +export const REMOVE_TOKENS = "REMOVE_TOKENS" export interface AccessToken { - token: string | null; - timestamp: number | null; + token: string | null + timestamp: number | null } export enum CookieStatus { NOT_STARTED, LOADING, - FINISHED + FINISHED, } export interface TokensState { - refreshToken: string | null; - accessToken: AccessToken | null; - checkedCookies: number; + refreshToken: string | null + accessToken: AccessToken | null + checkedCookies: number } export interface AddRefreshToken { - type: typeof ADD_REFRESH_TOKEN; - payload: string; + type: typeof ADD_REFRESH_TOKEN + payload: string } export interface AddAccessToken { - type: typeof ADD_ACCESS_TOKEN; - payload: AccessToken; + type: typeof ADD_ACCESS_TOKEN + payload: AccessToken } export interface RemoveTokens { - type: typeof REMOVE_TOKENS; + type: typeof REMOVE_TOKENS } export interface CheckedCookies { - type: typeof CHECKED_COOKIES; - payload: CookieStatus; + type: typeof CHECKED_COOKIES + payload: CookieStatus } export type TokenActionsTypes = | AddRefreshToken | AddAccessToken | RemoveTokens - | CheckedCookies; + | CheckedCookies diff --git a/src/background/redux/actions/tokens.tsx b/src/background/redux/actions/tokens.tsx index 6947797a..270573df 100644 --- a/src/background/redux/actions/tokens.tsx +++ b/src/background/redux/actions/tokens.tsx @@ -8,24 +8,24 @@ import { CheckedCookies, CookieStatus, REMOVE_TOKENS, - RemoveTokens -} from "./tokenTypes"; + RemoveTokens, +} from "./tokenTypes" export const addRefreshToken = (content: string): AddRefreshToken => ({ type: ADD_REFRESH_TOKEN, - payload: content -}); + payload: content, +}) export const addAccessToken = (content: AccessToken): AddAccessToken => ({ type: ADD_ACCESS_TOKEN, - payload: content -}); + payload: content, +}) export const removeTokens = (): RemoveTokens => ({ - type: REMOVE_TOKENS -}); + type: REMOVE_TOKENS, +}) export const checkedCookies = (content: CookieStatus): CheckedCookies => ({ type: CHECKED_COOKIES, - payload: content -}); + payload: content, +}) diff --git a/src/background/redux/actions/user.tsx b/src/background/redux/actions/user.tsx index e2e72002..0ad8217f 100644 --- a/src/background/redux/actions/user.tsx +++ b/src/background/redux/actions/user.tsx @@ -1,6 +1,6 @@ -import { UPDATE_USER, UpdateUser, UserState } from "./userTypes"; +import { UPDATE_USER, UpdateUser, UserState } from "./userTypes" export const updateUser = (content: UserState): UpdateUser => ({ type: UPDATE_USER, - payload: content -}); + payload: content, +}) diff --git a/src/background/redux/actions/userTypes.tsx b/src/background/redux/actions/userTypes.tsx index fecbb3dc..8537bd81 100644 --- a/src/background/redux/actions/userTypes.tsx +++ b/src/background/redux/actions/userTypes.tsx @@ -1,14 +1,14 @@ -export const UPDATE_USER = "UPDATE_USER"; +export const UPDATE_USER = "UPDATE_USER" export interface UserState { - userId: number | null; - username: string | null; - groups: string[]; + userId: number | null + username: string | null + groups: string[] } export interface UpdateUser { - type: typeof UPDATE_USER; - payload: UserState; + type: typeof UPDATE_USER + payload: UserState } -export type UserActionTypes = UpdateUser; +export type UserActionTypes = UpdateUser diff --git a/src/background/redux/reducers/apiActions.ts b/src/background/redux/reducers/apiActions.ts index 680f4376..9b37c9aa 100644 --- a/src/background/redux/reducers/apiActions.ts +++ b/src/background/redux/reducers/apiActions.ts @@ -5,12 +5,12 @@ import { ApiActionsTypes, CHANGE_STATUS, NEXT_FS_ENTITY, - REPLACE_API_ACTION -} from "../actions/apiActionsTypes"; + REPLACE_API_ACTION, +} from "../actions/apiActionsTypes" const initialState: ApiActionsState = { - actions: [] -}; + actions: [], +} export default function apiActions( state = initialState, @@ -19,8 +19,8 @@ export default function apiActions( switch (action.type) { case ADD_API_ACTION: { return { - actions: [...state.actions, action.payload] - }; + actions: [...state.actions, action.payload], + } } case REPLACE_API_ACTION: { return { @@ -28,49 +28,49 @@ export default function apiActions( ...state.actions.filter( (a: ApiAction) => a.key !== action.payload.key ), - action.payload - ] - }; + action.payload, + ], + } } case CHANGE_STATUS: { let actionToChange = state.actions.find( (a: ApiAction) => a.key === action.payload.key - ); - console.log(actionToChange); - console.log(action.payload); + ) + console.log(actionToChange) + console.log(action.payload) if (actionToChange) { - actionToChange.status = action.payload.status; - actionToChange.error = action.payload.error; + actionToChange.status = action.payload.status + actionToChange.error = action.payload.error return { actions: [ ...state.actions.filter( (a: ApiAction) => a.key !== action.payload.key ), - actionToChange - ] - }; - } else return state; + actionToChange, + ], + } + } else return state } case NEXT_FS_ENTITY: { let actionToChange = state.actions.find( (a: ApiAction) => a.key === action.payload.key - ); - console.log("[Reducer ApiAction] new progress", actionToChange); + ) + console.log("[Reducer ApiAction] new progress", actionToChange) if (actionToChange) { - actionToChange.currentFsEntity = action.payload.currentFsEntity; - actionToChange.progress = actionToChange.progress + 1; + actionToChange.currentFsEntity = action.payload.currentFsEntity + actionToChange.progress = actionToChange.progress + 1 return { actions: [ ...state.actions.filter( (a: ApiAction) => a.key !== action.payload.key ), - actionToChange - ] - }; - } else return state; + actionToChange, + ], + } + } else return state } default: - return state; + return state } } diff --git a/src/background/redux/reducers/filesystem.ts b/src/background/redux/reducers/filesystem.ts index 1a6d3d6b..eb63858d 100644 --- a/src/background/redux/reducers/filesystem.ts +++ b/src/background/redux/reducers/filesystem.ts @@ -9,16 +9,16 @@ import { REPLACE_SELECTED, SET_CONTENTS, SET_CURRENT_FSITEMID, - SET_CURRENT_PATH -} from "../actions/filesystemTypes"; -import { FsEntity } from "../../api/filesystemTypes"; + SET_CURRENT_PATH, +} from "../actions/filesystemTypes" +import { FsEntity } from "../../api/filesystemTypes" const initialState: FilesystemState = { selectedFsEntities: [], folderContents: [], currentFsItemId: "-1", - currentPath: "" -}; + currentPath: "", +} export default function filesystem( state = initialState, @@ -26,16 +26,16 @@ export default function filesystem( ): FilesystemState { switch (action.type) { case ADD_TO_SELECTED: { - console.log("[REDUX] ADD_TO_SELECTED", action.payload); + console.log("[REDUX] ADD_TO_SELECTED", action.payload) return { selectedFsEntities: [ ...state.selectedFsEntities, - action.payload + action.payload, ], //concat because it does not modify the original array folderContents: state.folderContents, currentFsItemId: state.currentFsItemId, - currentPath: state.currentPath - }; + currentPath: state.currentPath, + } } case REMOVE_FROM_SELECTED: { return { @@ -45,34 +45,34 @@ export default function filesystem( ), //filter return a new array folderContents: state.folderContents, currentFsItemId: state.currentFsItemId, - currentPath: state.currentPath - }; + currentPath: state.currentPath, + } } case CLEAR_SELECTED: { - console.log("Clear Selected"); + console.log("Clear Selected") return { selectedFsEntities: [], folderContents: state.folderContents, currentFsItemId: state.currentFsItemId, - currentPath: state.currentPath - }; + currentPath: state.currentPath, + } } case REPLACE_SELECTED: { - console.log("Replace Selected"); + console.log("Replace Selected") return { selectedFsEntities: action.payload, folderContents: state.folderContents, currentFsItemId: state.currentFsItemId, - currentPath: state.currentPath - }; + currentPath: state.currentPath, + } } case SET_CONTENTS: { return { selectedFsEntities: state.selectedFsEntities, folderContents: action.payload, currentFsItemId: state.currentFsItemId, - currentPath: state.currentPath - }; + currentPath: state.currentPath, + } } case ADD_TO_CONTENTS: { return { @@ -81,11 +81,11 @@ export default function filesystem( ...state.folderContents.filter((fsEntity: FsEntity) => dontReplaceFsEntity(fsEntity, action.payload) ), - action.payload + action.payload, ], currentFsItemId: state.currentFsItemId, - currentPath: state.currentPath - }; + currentPath: state.currentPath, + } } case REMOVE_FROM_CONTENTS: { return { @@ -95,27 +95,27 @@ export default function filesystem( fse.fileSystemId !== action.payload.fileSystemId ), currentFsItemId: state.currentFsItemId, - currentPath: state.currentPath - }; + currentPath: state.currentPath, + } } case SET_CURRENT_FSITEMID: { return { selectedFsEntities: state.selectedFsEntities, folderContents: state.folderContents, currentFsItemId: action.payload, - currentPath: state.currentPath - }; + currentPath: state.currentPath, + } } case SET_CURRENT_PATH: { return { selectedFsEntities: state.selectedFsEntities, folderContents: state.folderContents, currentFsItemId: state.currentFsItemId, - currentPath: action.payload - }; + currentPath: action.payload, + } } default: - return state; + return state } } const dontReplaceFsEntity = ( @@ -125,5 +125,5 @@ const dontReplaceFsEntity = ( return ( existingFsEntity.fileSystemId !== newFsEntity.fileSystemId && existingFsEntity.path !== newFsEntity.path - ); -}; + ) +} diff --git a/src/background/redux/reducers/index.tsx b/src/background/redux/reducers/index.tsx index 32328ab4..907527c1 100644 --- a/src/background/redux/reducers/index.tsx +++ b/src/background/redux/reducers/index.tsx @@ -1,9 +1,9 @@ -import { combineReducers } from "redux"; -import tokens from "./tokens"; -import user from "./user"; -import filesystem from "./filesystem"; -import apiActions from "./apiActions"; +import { combineReducers } from "redux" +import tokens from "./tokens" +import user from "./user" +import filesystem from "./filesystem" +import apiActions from "./apiActions" // this combines all the stores from the reducers -export default combineReducers({ tokens, user, filesystem, apiActions }); +export default combineReducers({ tokens, user, filesystem, apiActions }) diff --git a/src/background/redux/reducers/tokens.tsx b/src/background/redux/reducers/tokens.tsx index 15d835b1..beda45f5 100644 --- a/src/background/redux/reducers/tokens.tsx +++ b/src/background/redux/reducers/tokens.tsx @@ -6,14 +6,14 @@ import { CookieStatus, REMOVE_TOKENS, TokenActionsTypes, - TokensState -} from "../actions/tokenTypes"; + TokensState, +} from "../actions/tokenTypes" const initialState: TokensState = { refreshToken: null, accessToken: null, - checkedCookies: CookieStatus.NOT_STARTED -}; + checkedCookies: CookieStatus.NOT_STARTED, +} export default function tokens( state = initialState, @@ -21,38 +21,38 @@ export default function tokens( ) { switch (action.type) { case ADD_REFRESH_TOKEN: { - console.log("[Redux] adding refreshToken"); - const refreshToken: string = action.payload; + console.log("[Redux] adding refreshToken") + const refreshToken: string = action.payload return { refreshToken: refreshToken, accessToken: state.accessToken, - checkedCookies: state.checkedCookies - }; + checkedCookies: state.checkedCookies, + } } case ADD_ACCESS_TOKEN: { - console.log("[Redux] adding accessToken"); - const accessToken: AccessToken = action.payload; + console.log("[Redux] adding accessToken") + const accessToken: AccessToken = action.payload return { refreshToken: state.refreshToken, accessToken: accessToken, - checkedCookies: state.checkedCookies - }; + checkedCookies: state.checkedCookies, + } } case REMOVE_TOKENS: { return { refreshToken: null, accessToken: null, - checkedCookies: state.checkedCookies - }; + checkedCookies: state.checkedCookies, + } } case CHECKED_COOKIES: { return { refreshToken: state.refreshToken, accessToken: state.accessToken, - checkedCookies: action.payload - }; + checkedCookies: action.payload, + } } default: - return state; + return state } } diff --git a/src/background/redux/reducers/user.tsx b/src/background/redux/reducers/user.tsx index 24bea8b6..afca9e4b 100644 --- a/src/background/redux/reducers/user.tsx +++ b/src/background/redux/reducers/user.tsx @@ -1,19 +1,19 @@ -import { UPDATE_USER, UserActionTypes, UserState } from "../actions/userTypes"; +import { UPDATE_USER, UserActionTypes, UserState } from "../actions/userTypes" const initialState: UserState = { groups: [], userId: null, - username: null -}; + username: null, +} export default function users(state = initialState, action: UserActionTypes) { switch (action.type) { case UPDATE_USER: { - console.log("[Redux] updating user"); - return action.payload; + console.log("[Redux] updating user") + return action.payload } default: - return state; + return state } } diff --git a/src/background/redux/store.tsx b/src/background/redux/store.tsx index 20701ae9..bab10a8a 100644 --- a/src/background/redux/store.tsx +++ b/src/background/redux/store.tsx @@ -1,6 +1,6 @@ -import { createStore } from "redux"; -import rootReducer from "./reducers"; +import { createStore } from "redux" +import rootReducer from "./reducers" -export default createStore(rootReducer); +export default createStore(rootReducer) -export type RootState = ReturnType; +export type RootState = ReturnType diff --git a/src/components/App.tsx b/src/components/App.tsx index 9619a42d..2fe0b92e 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1,49 +1,49 @@ -import React, { ReactElement } from "react"; -import "./App.css"; -import { BrowserRouter, Route,Routes } from "react-router-dom"; -import Router from "./Router/Router"; -import PermanentAssets from "./basicElements/PermanentAssets"; +import React, { ReactElement } from "react" +import "./App.css" +import { BrowserRouter, Route, Routes } from "react-router-dom" +import Router from "./Router/Router" +import PermanentAssets from "./basicElements/PermanentAssets" -import Login, { LoginHeader } from "./basicElements/login/Login"; -import HeadArea from "./basicElements/topArea/TopArea"; -import BottomArea from "./basicElements/bottomArea/BottomArea"; +import Login, { LoginHeader } from "./basicElements/login/Login" +import HeadArea from "./basicElements/topArea/TopArea" +import BottomArea from "./basicElements/bottomArea/BottomArea" -import { connect, ConnectedProps } from "react-redux"; +import { connect, ConnectedProps } from "react-redux" import { addAccessToken, addRefreshToken, - checkedCookies -} from "../background/redux/actions/tokens"; -import { SystemState } from "../background/redux/actions/sytemState"; -import { checkForCookie } from "../background/api/auth"; -import { FFLoading } from "./basicElements/Loading"; -import { CookieStatus } from "../background/redux/actions/tokenTypes"; -import Error400 from "./pages/errors/Error400"; -import { Container } from "react-bootstrap"; + checkedCookies, +} from "../background/redux/actions/tokens" +import { SystemState } from "../background/redux/actions/sytemState" +import { checkForCookie } from "../background/api/auth" +import { FFLoading } from "./basicElements/Loading" +import { CookieStatus } from "../background/redux/actions/tokenTypes" +import Error400 from "./pages/errors/Error400" +import { Container } from "react-bootstrap" // this takes the redux store and maps everything that is needed to the function props const mapState = (state: SystemState) => ({ tokens: { refreshToken: state.tokens.refreshToken, accessToken: state.tokens.accessToken, - checkedCookies: state.tokens.checkedCookies + checkedCookies: state.tokens.checkedCookies, }, - user: state.user -}); + user: state.user, +}) // this takes the redux actions and maps them to the props const mapDispatch = { addRefreshToken, addAccessToken, - checkedCookies -}; + checkedCookies, +} -const connector = connect(mapState, mapDispatch); +const connector = connect(mapState, mapDispatch) -type PropsFromRedux = ConnectedProps; +type PropsFromRedux = ConnectedProps // this defines the component props and also adds the redux imported props -type Props = PropsFromRedux; +type Props = PropsFromRedux function App(props: Props): ReactElement { console.log( @@ -51,7 +51,7 @@ function App(props: Props): ReactElement { props.tokens.refreshToken, props.tokens, props.user - ); + ) if (props.tokens.checkedCookies === CookieStatus.FINISHED) { if (props.tokens.refreshToken && props.tokens.accessToken?.token) { @@ -66,9 +66,9 @@ function App(props: Props): ReactElement { - ); + ) } else { - console.log("[APP] showing login"); + console.log("[APP] showing login") return (
@@ -79,20 +79,20 @@ function App(props: Props): ReactElement { path={"/error"} element={} /> - } /> + } />
- ); + ) } } else { if (props.tokens.checkedCookies === CookieStatus.NOT_STARTED) { - checkForCookie(); + checkForCookie() } - return ; + return } } -export default connector(App); +export default connector(App) diff --git a/src/components/Constants.tsx b/src/components/Constants.tsx index 935a4549..10e2aed0 100644 --- a/src/components/Constants.tsx +++ b/src/components/Constants.tsx @@ -1,8 +1,8 @@ -import React, { ReactElement } from "react"; -import App from "./App"; +import React, { ReactElement } from "react" +import App from "./App" -import { Provider } from "react-redux"; -import store from "../background/redux/store"; +import { Provider } from "react-redux" +import store from "../background/redux/store" function Constants(): ReactElement { // userinfos @@ -12,7 +12,7 @@ function Constants(): ReactElement { - ); + ) } -export default Constants; +export default Constants diff --git a/src/components/Router/BackendRedirect.tsx b/src/components/Router/BackendRedirect.tsx index 2d579e7c..ad615079 100644 --- a/src/components/Router/BackendRedirect.tsx +++ b/src/components/Router/BackendRedirect.tsx @@ -1,18 +1,18 @@ -import {useLocation, useNavigate} from "react-router-dom"; +import { useLocation, useNavigate } from "react-router-dom" export default function BackendRedirect() { - const location = useLocation(); - const navigate = useNavigate(); - const urlSearchParams = new URLSearchParams(location.search); - const redirected = urlSearchParams.get("redirected"); + const location = useLocation() + const navigate = useNavigate() + const urlSearchParams = new URLSearchParams(location.search) + const redirected = urlSearchParams.get("redirected") // this param will be visible for the user, even though it is only needed if the fe is not accessed via nginx, but it prevents endless loops if (redirected === "") { - navigate("/error404"); - return null; + navigate("/error404") + return null } - urlSearchParams.set("redirected", ""); - navigate(location.pathname + "?" + urlSearchParams.toString()); - window.location.reload(); // leave the spa, to access the apis. - return null; + urlSearchParams.set("redirected", "") + navigate(location.pathname + "?" + urlSearchParams.toString()) + window.location.reload() // leave the spa, to access the apis. + return null } diff --git a/src/components/Router/Router.tsx b/src/components/Router/Router.tsx index 14b185a0..ec956373 100644 --- a/src/components/Router/Router.tsx +++ b/src/components/Router/Router.tsx @@ -1,30 +1,31 @@ -import React, {ReactElement} from "react"; -import {Navigate, Route, Routes} from "react-router-dom"; -import Health from "../pages/health/Health"; -import Error404 from "../pages/errors/Error404"; -import Login from "../basicElements/login/Login"; -import Registration from "../pages/User/Registration"; -import FileSystem, {filesBaseUrl} from "../pages/filesytem/Filesystem"; -import Profile from "../pages/User/Profile"; -import Error400 from "../pages/errors/Error400"; -import BackendRedirect from "./BackendRedirect"; - +import React, { ReactElement } from "react" +import { Navigate, Route, Routes } from "react-router-dom" +import Health from "../pages/health/Health" +import Error404 from "../pages/errors/Error404" +import Login from "../basicElements/login/Login" +import Registration from "../pages/User/Registration" +import FileSystem, { filesBaseUrl } from "../pages/filesytem/Filesystem" +import Profile from "../pages/User/Profile" +import Error400 from "../pages/errors/Error400" +import BackendRedirect from "./BackendRedirect" export default function Router(): ReactElement { - return ( - }/> - }/> - }/> - }/> - }/> - }/> - }/> - }/> - }/> - }/> - }/> + } /> + } + /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> - ); + ) } diff --git a/src/components/basicElements/Loading.tsx b/src/components/basicElements/Loading.tsx index 5a07e885..2baf5a6c 100644 --- a/src/components/basicElements/Loading.tsx +++ b/src/components/basicElements/Loading.tsx @@ -1,6 +1,6 @@ -import React from "react"; -import Spinner from "react-bootstrap/Spinner"; -import { Container } from "react-bootstrap"; +import React from "react" +import Spinner from "react-bootstrap/Spinner" +import { Container } from "react-bootstrap" export function FFLoading(): JSX.Element { return ( @@ -11,5 +11,5 @@ export function FFLoading(): JSX.Element { Loading... - ); + ) } diff --git a/src/components/basicElements/PermanentAssets.tsx b/src/components/basicElements/PermanentAssets.tsx index 5787ca45..25c23b88 100644 --- a/src/components/basicElements/PermanentAssets.tsx +++ b/src/components/basicElements/PermanentAssets.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement } from "react"; +import React, { ReactElement } from "react" export default function PermanentAssets(): ReactElement { return ( @@ -7,5 +7,5 @@ export default function PermanentAssets(): ReactElement { - ); + ) } diff --git a/src/components/basicElements/__snapshots__/Banner.stories.tsx b/src/components/basicElements/__snapshots__/Banner.stories.tsx index e9a789d6..5a25901d 100644 --- a/src/components/basicElements/__snapshots__/Banner.stories.tsx +++ b/src/components/basicElements/__snapshots__/Banner.stories.tsx @@ -1,8 +1,8 @@ -import { storiesOf } from "@storybook/react"; -import { BottomBanner } from "../bottomArea/BottomBanner"; -import { TopBanner } from "../topArea/TopBanner"; +import { storiesOf } from "@storybook/react" +import { BottomBanner } from "../bottomArea/BottomBanner" +import { TopBanner } from "../topArea/TopBanner" storiesOf("Banner", module) .add("BottomBanner", () => ) - .add("TopBanner", () => ); + .add("TopBanner", () => ) diff --git a/src/components/basicElements/bottomArea/BottomArea.tsx b/src/components/basicElements/bottomArea/BottomArea.tsx index da0c99ef..70225127 100644 --- a/src/components/basicElements/bottomArea/BottomArea.tsx +++ b/src/components/basicElements/bottomArea/BottomArea.tsx @@ -1,6 +1,6 @@ -import Footer from "./Footer"; -import { BottomBanner } from "./BottomBanner"; -import React from "react"; +import Footer from "./Footer" +import { BottomBanner } from "./BottomBanner" +import React from "react" export default function BottomArea() { return ( @@ -8,5 +8,5 @@ export default function BottomArea() {