diff options
| -rw-r--r-- | assets/src/entries/request.ts | 4 | ||||
| -rw-r--r-- | assets/src/entries/share.ts | 4 | ||||
| -rw-r--r-- | assets/src/models/rook_type.ts | 4 | ||||
| -rw-r--r-- | assets/src/stores/constant_state.ts | 33 | ||||
| -rw-r--r-- | assets/src/utils/getShareToken.ts | 12 |
5 files changed, 55 insertions, 2 deletions
diff --git a/assets/src/entries/request.ts b/assets/src/entries/request.ts index 6b8a79f..fcdda2f 100644 --- a/assets/src/entries/request.ts +++ b/assets/src/entries/request.ts @@ -1,4 +1,8 @@ import RequestPage from "../components/RequestPage.svelte"; +import { RookType } from "../models/rook_type"; +import { setClientType } from "../stores/constant_state"; + +setClientType(RookType.REQUEST); const app = new RequestPage({ target: document.getElementById("app"), diff --git a/assets/src/entries/share.ts b/assets/src/entries/share.ts index 2704a62..cc2ab9c 100644 --- a/assets/src/entries/share.ts +++ b/assets/src/entries/share.ts @@ -1,4 +1,8 @@ import SharePage from "../components/SharePage.svelte"; +import { RookType } from "../models/rook_type"; +import { setClientType } from "../stores/constant_state"; + +setClientType(RookType.SHARE); const app = new SharePage({ target: document.getElementById("app"), diff --git a/assets/src/models/rook_type.ts b/assets/src/models/rook_type.ts new file mode 100644 index 0000000..083b446 --- /dev/null +++ b/assets/src/models/rook_type.ts @@ -0,0 +1,4 @@ +export enum RookType { + SHARE, + REQUEST, +} diff --git a/assets/src/stores/constant_state.ts b/assets/src/stores/constant_state.ts new file mode 100644 index 0000000..aeda86e --- /dev/null +++ b/assets/src/stores/constant_state.ts @@ -0,0 +1,33 @@ +// Cannot be changed after being set. + +import { RookType } from "../models/rook_type"; + +let clientType: RookType = null; + +export function setClientType(type: RookType) { + if (clientType !== null) { + clientType = type; + } else { + throw new Error("Tried changing client type after initialization."); + } +} + +export function isClientShare() { + if (clientType === null) { + throw new Error( + "Tried accessing client type before initialization was completed." + ); + } + + return clientType === RookType.SHARE; +} + +export function isClientRequest() { + if (clientType === null) { + throw new Error( + "Tried accessing client type before initialization was completed." + ); + } + + return clientType === RookType.REQUEST; +} diff --git a/assets/src/utils/getShareToken.ts b/assets/src/utils/getShareToken.ts index bfe6f58..b470695 100644 --- a/assets/src/utils/getShareToken.ts +++ b/assets/src/utils/getShareToken.ts @@ -1,4 +1,12 @@ -export default (): string => { +import { isClientRequest } from "../stores/constant_state"; + +export default function (): string { + if (!isClientRequest()) { + throw new Error( + "Client is not requesting so it does not have a share token." + ); + } + const splitPath = window.location.pathname.split("/"); return splitPath[splitPath.length - 1]; -}; +} |
