Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/__tests__/__snapshots__/storybook.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ Array [
>
Show all (
3
)
)

</button>
</div>
</div>,
Expand All @@ -292,7 +293,8 @@ Array [
<div
className="w-100 text-warning row"
>
Some files or folders need to be renamed, because their name is invalid or you have not the permission to overwrite them
Some files or folders need to be renamed, because their name is invalid or you have not the permission to overwrite them

</div>
<div
className="w-100 justify-content-between row"
Expand Down Expand Up @@ -522,7 +524,8 @@ exports[`Storyshots Footer default 1`] = `
src="github.svg"
/>
</a>
is made with &lt;3 by

is made with &lt;3 by
</span>
<div
className="d-flex justify-content-around"
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/storybook.test.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import initStoryshots from '@storybook/addon-storyshots';
initStoryshots();
import initStoryshots from "@storybook/addon-storyshots";
initStoryshots();
9 changes: 5 additions & 4 deletions src/assets/images/icons/reactSvgIcons/SymbolFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export function FileEarmarkImageIcon(props: React.SVGProps<SVGSVGElement>) {
fillRule="evenodd"
d="M12 16a2 2 0 002-2V4.5L9.5 0H4a2 2 0 00-2 2v12a2 2 0 002 2h8zM3 2a1 1 0 011-1h5.5v2A1.5 1.5 0 0011 4.5h2V10l-2.083-2.083a.5.5 0 00-.76.063L8 11 5.835 9.7a.5.5 0 00-.611.076L3 12V2z"
/>
<path fillRule="evenodd" d="M6.502 7a1.5 1.5 0 100-3 1.5 1.5 0 000 3z" />
<path
fillRule="evenodd"
d="M6.502 7a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"
/>
</svg>
);
}
Expand Down Expand Up @@ -199,8 +202,6 @@ export function FileEarmarkBinaryIcon(props: React.SVGProps<SVGSVGElement>) {
);
}



//--------------------------------------------------------------------\\
//--------------------------------------------------------------------\\
//--------------------------------------------------------------------\\
Expand All @@ -224,4 +225,4 @@ export function FolderIcon(props: React.SVGProps<SVGSVGElement>) {
/>
</svg>
);
}
}
36 changes: 18 additions & 18 deletions src/background/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ export const userPath: string = "/v1/users";
export const filesystemPath: string = "/v1/filesystem/";

enum DataIntegrity {
STABLE = "bg-success",
POSSIBLE_RISK = "bg-warning",
UNSTABLE = "bg-danger"
STABLE = "bg-success",
POSSIBLE_RISK = "bg-warning",
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<SystemHealthData> {
return new Promise((resolve, reject) => {
Axios.get(`${hostname}/health`)
.then((data) => {
resolve(data.data);
})
.catch((error) => {
reject(error);
});
});
return new Promise((resolve, reject) => {
Axios.get(`${hostname}/health`)
.then((data) => {
resolve(data.data);
})
.catch((error) => {
reject(error);
});
});
}

export { callBackendHealth, DataIntegrity };
Expand Down
27 changes: 17 additions & 10 deletions src/background/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
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 { 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";
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";

// reference: https://daveceddia.com/access-redux-store-outside-react/

Expand All @@ -34,7 +39,6 @@ export const checkForCookie = () => {
store.dispatch(addRefreshToken(refreshTokenCookieValue));
store.dispatch(checkedCookies(CookieStatus.LOADING));
getAccessTokenWithRefreshToken();

};

export const loginWithUsernameAndPassword = async (
Expand All @@ -51,7 +55,10 @@ export const loginWithUsernameAndPassword = async (
}
};

return Axios.get<BackendLoginData>(hostname + userPath + "/login", config)
return Axios.get<BackendLoginData>(
hostname + userPath + "/login",
config
)
.then((data: AxiosResponse<BackendLoginData>) => {
console.log(data.data);
store.dispatch(addRefreshToken(data.data.tokenValue));
Expand Down
40 changes: 20 additions & 20 deletions src/background/api/filesystemTypes.ts
Original file line number Diff line number Diff line change
@@ -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;
}
42 changes: 22 additions & 20 deletions src/background/api/registration.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
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 (username: string, password: string, passwordConfirmation: string): Promise<IRegisterServerResponse> => {

if (password !== passwordConfirmation){
export const registerNewUser = async (
username: string,
password: string,
passwordConfirmation: string
): Promise<IRegisterServerResponse> => {
if (password !== passwordConfirmation) {
throw new Error("Password did not match passwordConfirmation");
}
let hashedPassword = await hashPassword(password);
Expand All @@ -20,29 +23,28 @@ export const registerNewUser = async (username: string, password: string, passwo
username: username,
password: hashedPassword,
confirmationPassword: hashedPassword
}

};

return Axios.post(hostname + userPath + '/register', newUser)
return Axios.post(hostname + userPath + "/register", newUser)
.then((data: AxiosResponse<object>) => {
console.log(data)
console.log(data);
const response: IRegisterServerResponse = {
httpStatus: data.status,
httpMessage: data.statusText
}
};
if (data.status === 201) {
response.outputMessage = "User was successfully created."
response.outputMessage = "User was successfully created.";
}
resolve(response);
})
.catch((error: AxiosError) => {
console.log(error.response)
console.log(error.response);
const response: IRegisterServerResponse = {
httpStatus: error.response!.status,
httpMessage: error.response!.statusText,
outputMessage: error.response!.data.message
}
};
reject(response);
})
})
}
});
});
};
4 changes: 2 additions & 2 deletions src/background/methods/checkInput.ts
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 10 additions & 11 deletions src/background/methods/cookies.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export function getCookie(cname:string) {
export function getCookie(cname: string) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let ca = decodedCookie.split(";");
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
while (c.charAt(0) === " ") {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
Expand All @@ -14,15 +14,14 @@ export function getCookie(cname:string) {
return "";
}


export function setCookie(cname:string, cvalue:string, exdays:number) {
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();
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=/;";
export function deleteCookie(cname: string) {
document.cookie =
cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}
26 changes: 18 additions & 8 deletions src/background/methods/dataTypes/bytes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
export function formatBytes(bytes:number, decimals:number = 2):string {
if (bytes === 0) return '0 Bytes';
export function formatBytes(bytes: number, decimals: number = 2): string {
if (bytes === 0) return "0 Bytes";

const k:number = 1024;
const dm:number = decimals < 0 ? 0 : decimals;
const sizes:string[] = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const k: number = 1024;
const dm: number = decimals < 0 ? 0 : decimals;
const sizes: string[] = [
"Bytes",
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"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];
}
2 changes: 1 addition & 1 deletion src/background/methods/dataTypes/objects/ObjectKeysTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<O>(obj: O, key: keyof any): key is keyof O {
return key in obj
return key in obj;
}
7 changes: 4 additions & 3 deletions src/background/methods/dataTypes/objects/objectEquals.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
function objectEquals(object1:object|any, object2:object|any):boolean {
function objectEquals(object1: object | any, object2: object | any): boolean {
let areEqual = true;

//keylength
if (Object.keys(object1).length === Object.keys(object2).length) return false;
if (Object.keys(object1).length === Object.keys(object2).length)
return false;

//compare keys
Object.keys(object1).forEach((key) => {
Expand All @@ -14,4 +15,4 @@ function objectEquals(object1:object|any, object2:object|any):boolean {
return areEqual;
}

export default objectEquals;
export default objectEquals;
Loading