Skip to content

Commit

Permalink
Merge pull request #9 from filecoin-project/fix/application-types
Browse files Browse the repository at this point in the history
Fix application types
  • Loading branch information
clriesco committed Nov 24, 2023
2 parents 076c457 + da97c94 commit 243dee5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/services/backendService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export const getApplication = async (
method: "GET",
url: `${config.backendApi}/application/${appId}`,
});
const application = response.data as Application | null;

return {
application:
response.data.length > 0 ? (response.data[0] as Application) : null,
application,
error: "",
success: true,
};
Expand Down
44 changes: 44 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,57 @@ const byteConverter = new ByteConverter();
* @returns number
*/
export function anyToBytes(inputDatacap: string): number {
const allowedExtensions = [
"b",
"B",
"kb",
"kB",
"Kib",
"KiB",
"Mb",
"MB",
"Mib",
"MiB",
"Gb",
"GB",
"Gib",
"GiB",
"Tb",
"TB",
"Tib",
"TiB",
"Pb",
"PB",
"Pib",
"PiB",
"Eb",
"EB",
"Eib",
"EiB",
"Zb",
"ZB",
"Zib",
"ZiB",
"Yb",
"YB",
"Yib",
"YiB",
];
const formatDc = inputDatacap
.replace(/[t]/g, "T")
.replace(/[b]/g, "B")
.replace(/[p]/g, "P")
.replace(/[I]/g, "i")
.replace(/\s*/g, "");
const ext = formatDc.replace(/[0-9.]/g, "");

if (!allowedExtensions.includes(ext)) {
throw new Error(
`Invalid datacap format. Allowed extensions are: ${allowedExtensions.join(
", ",
)}`,
);
}
const datacap = formatDc.replace(/[^0-9.]/g, "");
const bytes = byteConverter.convert(parseFloat(datacap), ext, "B");
return bytes;
Expand Down

0 comments on commit 243dee5

Please sign in to comment.