mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 19:34:34 +00:00
fix: refactor sas/js session controller classes to inherit from base session controller class
This commit is contained in:
@@ -17,12 +17,14 @@ import {
|
|||||||
|
|
||||||
const execFilePromise = promisify(execFile)
|
const execFilePromise = promisify(execFile)
|
||||||
|
|
||||||
export class SASSessionController {
|
abstract class SessionController {
|
||||||
private sessions: Session[] = []
|
protected sessions: Session[] = []
|
||||||
|
|
||||||
private getReadySessions = (): Session[] =>
|
protected getReadySessions = (): Session[] =>
|
||||||
this.sessions.filter((sess: Session) => sess.ready && !sess.consumed)
|
this.sessions.filter((sess: Session) => sess.ready && !sess.consumed)
|
||||||
|
|
||||||
|
protected abstract createSession(): Promise<Session>
|
||||||
|
|
||||||
public async getSession() {
|
public async getSession() {
|
||||||
const readySessions = this.getReadySessions()
|
const readySessions = this.getReadySessions()
|
||||||
|
|
||||||
@@ -34,8 +36,10 @@ export class SASSessionController {
|
|||||||
|
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async createSession(): Promise<Session> {
|
export class SASSessionController extends SessionController {
|
||||||
|
protected async createSession(): Promise<Session> {
|
||||||
const sessionId = generateUniqueFileName(generateTimestamp())
|
const sessionId = generateUniqueFileName(generateTimestamp())
|
||||||
const sessionFolder = path.join(getSessionsFolder(), sessionId)
|
const sessionFolder = path.join(getSessionsFolder(), sessionId)
|
||||||
|
|
||||||
@@ -152,8 +156,8 @@ ${autoExecContent}`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class JSSessionController {
|
export class JSSessionController extends SessionController {
|
||||||
public async getSession() {
|
protected async createSession(): Promise<Session> {
|
||||||
const sessionId = generateUniqueFileName(generateTimestamp())
|
const sessionId = generateUniqueFileName(generateTimestamp())
|
||||||
const sessionFolder = path.join(getSessionsFolder(), sessionId)
|
const sessionFolder = path.join(getSessionsFolder(), sessionId)
|
||||||
|
|
||||||
@@ -179,6 +183,7 @@ export class JSSessionController {
|
|||||||
const headersPath = path.join(session.path, 'stpsrv_header.txt')
|
const headersPath = path.join(session.path, 'stpsrv_header.txt')
|
||||||
await createFile(headersPath, 'Content-type: application/json')
|
await createFile(headersPath, 'Content-type: application/json')
|
||||||
|
|
||||||
|
this.sessions.push(session)
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user