-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: locally caching of booking sessions
Allows for the ability to resume a session without the need to BankID identification if not yet expired.
- Loading branch information
Showing
9 changed files
with
251 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ dist | |
build | ||
.*.log | ||
proxies.txt | ||
.config.local.json | ||
.config.local.json | ||
.session.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import fs from "fs"; | ||
|
||
import { logger } from "../logger"; | ||
import { getPath } from "../utils"; | ||
|
||
interface SessionData { | ||
cookie: string; | ||
hash: string; | ||
} | ||
|
||
export const saveSession = (hash: string, cookie: string) => { | ||
try { | ||
const configPath = getPath("./.session.json"); | ||
|
||
if (configPath) { | ||
fs.writeFileSync(configPath, JSON.stringify({ cookie, hash }), "utf-8"); | ||
} | ||
} catch (error) { | ||
logger.verbose(`Failed to save session: ${error}`); | ||
} | ||
}; | ||
|
||
export const getSession = (hash: string) => { | ||
try { | ||
const sessionPath = getPath("./.session.json"); | ||
const data: SessionData = JSON.parse( | ||
fs.readFileSync(sessionPath).toString() | ||
); | ||
|
||
if (data.hash !== hash) { | ||
logger.verbose( | ||
"Session hash mismatch, ignoring recovering from last session" | ||
); | ||
} | ||
|
||
return data.cookie; | ||
} catch (error) { | ||
// quiet, there might be no session... | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.