Skip to content

Commit

Permalink
frontend: port to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed Mar 24, 2022
1 parent 179611e commit b999087
Show file tree
Hide file tree
Showing 16 changed files with 419 additions and 133 deletions.
208 changes: 208 additions & 0 deletions frontend/package-lock.json

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

3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
"sass": "^1.49.9",
"sass-loader": "^12.6.0",
"style-loader": "^3.3.1",
"ts-loader": "^9.2.8",
"typescript": "^4.6.2",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4"
},
"dependencies": {
"@types/crypto-js": "^4.1.1",
"bootstrap": "^5.1.3",
"crypto-js": "^4.1.1",
"pretty-bytes": "^6.0.0",
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const apiBase = "/api/v1";

export async function apiRequest(req: string, body: object, method = "POST") {
let resp = await fetch(`${apiBase}/${req}`, {
method: method,
mode: "cors",
headers: {
"Content-Type": "application/json"
},
body: method === "POST" ? JSON.stringify(body) : undefined
});

if (resp.status !== 200) {
throw resp;
}

return resp.json();
}
18 changes: 9 additions & 9 deletions frontend/src/checksum.js → frontend/src/checksum.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import SHA256 from "crypto-js/sha256";
import MD5 from "crypto-js/md5";
import WordArray from "crypto-js/lib-typedarrays";
import * as SHA256 from "crypto-js/sha256";
import * as MD5 from "crypto-js/md5";
import * as WordArray from "crypto-js/lib-typedarrays";

function wordToUintArray(wordArray) {
function wordToUintArray(wordArray: WordArray) {
const l = wordArray.sigBytes;
const words = wordArray.words;
const result = new Uint8Array(l);
Expand Down Expand Up @@ -31,17 +31,17 @@ function wordToUintArray(wordArray) {
return result;
}

export async function sha256sum(blob) {
export async function sha256sum(buf: ArrayBuffer): Promise<Uint8Array> {
if (window.crypto.subtle !== undefined) {
return await crypto.subtle.digest("SHA-256", blob);
let ab = await crypto.subtle.digest("SHA-256", buf);
}

let wa = WordArray.create(blob);
let wa = WordArray.create(buf as unknown as number[]);
return wordToUintArray(SHA256(wa));
}

export async function md5sum(blob) {
const wa = WordArray.create(blob);
export async function md5sum(buf: ArrayBuffer): Promise<Uint8Array> {
const wa = WordArray.create(buf as unknown as number[]);
const hash = MD5(wa);
return wordToUintArray(hash);
}
9 changes: 9 additions & 0 deletions frontend/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ExpirationClass {
tag: string = "";
title: string = "";
days: number = 0;
};

export class Config {
expiration_classes: Array<ExpirationClass> = [];
}
3 changes: 3 additions & 0 deletions frontend/src/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class ChecksummedFile extends File {
checksum: Uint8Array
}
Loading

0 comments on commit b999087

Please sign in to comment.