Skip to content

Commit

Permalink
fix: parse session age as seconds inside file store
Browse files Browse the repository at this point in the history
Closes: #86
  • Loading branch information
thetutlage committed Jun 5, 2024
1 parent edd54c5 commit 76818f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/stores/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ import type { FileStoreConfig, SessionData, SessionStoreContract } from '../type
/**
* File store writes the session data on the file system as. Each session
* id gets its own file.
*
*/
export class FileStore implements SessionStoreContract {
#config: FileStoreConfig
#age: string | number

/**
* @param {FileStoreConfig} config
* @param {string|number} The age must be in seconds or a time expression
*/
constructor(config: FileStoreConfig, age: string | number) {
this.#config = config
this.#age = age
Expand Down Expand Up @@ -95,7 +100,7 @@ export class FileStore implements SessionStoreContract {
/**
* Check if the file has been expired and return null (if expired)
*/
const sessionWillExpireAt = stats.mtimeMs + string.milliseconds.parse(this.#age)
const sessionWillExpireAt = stats.mtimeMs + (string.seconds.parse(this.#age) * 1000)

Check failure on line 103 in src/stores/file.ts

View workflow job for this annotation

GitHub Actions / test_windows (20.10.0)

Replace `(string.seconds.parse(this.#age)·*·1000)` with `string.seconds.parse(this.#age)·*·1000`

Check failure on line 103 in src/stores/file.ts

View workflow job for this annotation

GitHub Actions / test_linux (20.10.0)

Replace `(string.seconds.parse(this.#age)·*·1000)` with `string.seconds.parse(this.#age)·*·1000`

Check failure on line 103 in src/stores/file.ts

View workflow job for this annotation

GitHub Actions / test_linux (21.x)

Replace `(string.seconds.parse(this.#age)·*·1000)` with `string.seconds.parse(this.#age)·*·1000`

Check failure on line 103 in src/stores/file.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Replace `(string.seconds.parse(this.#age)·*·1000)` with `string.seconds.parse(this.#age)·*·1000`
if (Date.now() > sessionWillExpireAt) {
debug('file store: expired session data %s', sessionId)
return null
Expand Down
2 changes: 1 addition & 1 deletion tests/stores/file_store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test.group('File store', () => {

test('return null when session data is expired', async ({ assert, fs }) => {
const sessionId = '1234'
const session = new FileStore({ location: fs.basePath }, 1000)
const session = new FileStore({ location: fs.basePath }, 1)
await session.write(sessionId, { message: 'hello-world' })

await setTimeout(2000)
Expand Down

0 comments on commit 76818f9

Please sign in to comment.