Skip to content

Commit

Permalink
Merge branch '5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhas Vishwanath committed Sep 28, 2023
2 parents ce722a5 + 761e70e commit 58e4bfb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 101 deletions.
11 changes: 9 additions & 2 deletions client/components/ImageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,15 @@ export default function ImageList() {
{(selectAllInPage[currentPage] === ALL_SELECTED) && <>
<MUIButton variant="text" onClick={toggleSelectAllPages} style={{textTransform:"capitalize", fontSize:"1rem"}}>{selectAllPages ? "Clear selection" : "Select all media matching filter"}</MUIButton>
</>}


{
(selectAllPages || checkedImage.length > 0) && <Divider style={{paddingTop:"24px"}}/>
}
{
(!selectAllPages && checkedImage.length > 0) && <p style={{paddingTop:"24px", fontSize:"1rem"}}>Selected {checkedImage.length} media items</p>
}
{
selectAllPages && <p style={{paddingTop:"24px", fontSize:"1rem"}}>Selected all media items in all pages</p>
}
</div>
<Divider style={{paddingTop: "24px"}}/>
<div className="max-w-2xl mx-auto py-16 px-4 sm:py-24 sm:px-6 lg:max-w-7xl lg:px-8">
Expand Down
164 changes: 65 additions & 99 deletions server/src/utils/file-utility.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,69 @@
import { Injectable } from "@nestjs/common";
import { Injectable } from '@nestjs/common';
import * as fs from 'fs';
Injectable()
export class FileUtility{
getFileSizeText(fileSizeInBytes: number): string {
const BYTE_TO_KB = 1024;
const KB_TO_MB = 1024;
const MB_TO_GB = 1024;

if (!Number.isFinite(fileSizeInBytes) || fileSizeInBytes < 0) {
throw new Error('Invalid file size');
}

let size: string | number;
let unit: string;

if (fileSizeInBytes < BYTE_TO_KB) {
size = fileSizeInBytes;
unit = 'bytes';
} else if (fileSizeInBytes < BYTE_TO_KB * KB_TO_MB) {
size = (fileSizeInBytes / BYTE_TO_KB).toFixed(2);
unit = 'KB';
} else if (fileSizeInBytes < BYTE_TO_KB * KB_TO_MB * MB_TO_GB) {
size = (fileSizeInBytes / BYTE_TO_KB / KB_TO_MB).toFixed(2);
unit = 'MB';
} else {
size = (fileSizeInBytes / BYTE_TO_KB / KB_TO_MB / MB_TO_GB).toFixed(2);
unit = 'GB';
}

return `${size} ${unit}`;
}

Injectable();

async folderStructure(
metadata: any,
locationHierarchy: { name: any; }[]
): Promise<string> {
const address = metadata.address;
const conceptType = metadata.conceptName;
const subjectType = metadata.subjectTypeName;
const encounterType = metadata.encounterTypeName;
const keys = locationHierarchy.map((index: { name: any; }) => index.name);
const jsonadd = JSON.parse(address);
const addressArray = [];
let val =''
for (const key of keys) {
val= key.toString()
addressArray.push(jsonadd[val]);
}
let directoryPath = ''
await Promise.all(
addressArray.map(async (addressPart) => {
if (addressPart) {
if (directoryPath) {
directoryPath = `${directoryPath}/${addressPart}`;
} else {
directoryPath = `${addressPart}`;
}
if (!fs.existsSync(directoryPath)) {
fs.mkdirSync(directoryPath);
}
}
}),
);

if (subjectType) {
if (directoryPath) {
directoryPath = `${directoryPath}/${subjectType}`;
} else {
directoryPath = `${subjectType}`;
}
if (!fs.existsSync(directoryPath)) {
fs.mkdirSync(directoryPath);
}
}

if (encounterType) {
if (directoryPath) {
directoryPath = `${directoryPath}/${encounterType}`;
} else {
directoryPath = `${encounterType}`;
}
if (!fs.existsSync(directoryPath)) {
fs.mkdirSync(directoryPath);
}
}

if (conceptType) {
if (directoryPath) {
directoryPath = `${directoryPath}/${conceptType}`;
} else {
directoryPath = `${conceptType}`;
}
if (!fs.existsSync(directoryPath)) {
fs.mkdirSync(directoryPath);
}
}

return directoryPath;
}
export class FileUtility {
getFileSizeText(fileSizeInBytes: number): string {
const BYTE_TO_KB = 1024;
const KB_TO_MB = 1024;
const MB_TO_GB = 1024;

if (!Number.isFinite(fileSizeInBytes) || fileSizeInBytes < 0) {
throw new Error('Invalid file size');
}

let size: string | number;
let unit: string;

}
if (fileSizeInBytes < BYTE_TO_KB) {
size = fileSizeInBytes;
unit = 'bytes';
} else if (fileSizeInBytes < BYTE_TO_KB * KB_TO_MB) {
size = (fileSizeInBytes / BYTE_TO_KB).toFixed(2);
unit = 'KB';
} else if (fileSizeInBytes < BYTE_TO_KB * KB_TO_MB * MB_TO_GB) {
size = (fileSizeInBytes / BYTE_TO_KB / KB_TO_MB).toFixed(2);
unit = 'MB';
} else {
size = (fileSizeInBytes / BYTE_TO_KB / KB_TO_MB / MB_TO_GB).toFixed(2);
unit = 'GB';
}

return `${size} ${unit}`;
}

async folderStructure(
metadata: any,
locationHierarchy: { name: any }[],
): Promise<string> {
const address = metadata.address;
const conceptType = metadata.conceptName;
const subjectType = metadata.subjectTypeName;
const encounterType = metadata.encounterTypeName;
const keys = locationHierarchy.map((index: { name: any }) => index.name);
const jsonAddress = JSON.parse(address);
const pathPartsArray = [];
let val = '';
for (const key of keys) {
val = key.toString();
if (jsonAddress[val]) {
pathPartsArray.push(jsonAddress[val].replace('/', '-'));
}
}
if (subjectType) {
pathPartsArray.push(subjectType.replace('/', '-'));
}
if (encounterType) {
pathPartsArray.push(encounterType.replace('/', '-'));
}
if (conceptType) {
pathPartsArray.push(conceptType.replace('/', '-'));
}
const directoryPath = pathPartsArray.join('/');
if (!fs.existsSync(directoryPath)) {
fs.mkdirSync(directoryPath, { recursive: true });
}
return directoryPath;
}
}

0 comments on commit 58e4bfb

Please sign in to comment.