@@ -20,11 +20,11 @@ export interface EditorSessionEntry {
20
20
}
21
21
22
22
interface DeleteSessionRequest {
23
- socketPath : string
23
+ socketPath ? : string
24
24
}
25
25
26
26
interface AddSessionRequest {
27
- entry : EditorSessionEntry
27
+ entry ? : EditorSessionEntry
28
28
}
29
29
30
30
interface GetSessionResponse {
@@ -40,37 +40,42 @@ export async function makeEditorSessionManagerServer(
40
40
// eslint-disable-next-line import/no-named-as-default-member
41
41
router . use ( express . json ( ) )
42
42
43
- router . get ( "/session" , async ( req , res ) => {
44
- const filePath = req . query . filePath as string
45
- if ( ! filePath ) {
46
- res . status ( HttpCode . BadRequest ) . send ( "filePath is required" )
47
- return
48
- }
49
- try {
50
- const socketPath = await editorSessionManager . getConnectedSocketPath ( filePath )
51
- const response : GetSessionResponse = { socketPath }
52
- res . json ( response )
53
- } catch ( error : unknown ) {
54
- res . status ( HttpCode . ServerError ) . send ( error )
55
- }
56
- } )
43
+ router . get < { } , GetSessionResponse | string | unknown , undefined , { filePath ?: string } > (
44
+ "/session" ,
45
+ async ( req , res ) => {
46
+ const filePath = req . query . filePath
47
+ if ( ! filePath ) {
48
+ res . status ( HttpCode . BadRequest ) . send ( "filePath is required" )
49
+ return
50
+ }
51
+ try {
52
+ const socketPath = await editorSessionManager . getConnectedSocketPath ( filePath )
53
+ const response : GetSessionResponse = { socketPath }
54
+ res . json ( response )
55
+ } catch ( error : unknown ) {
56
+ res . status ( HttpCode . ServerError ) . send ( error )
57
+ }
58
+ } ,
59
+ )
57
60
58
- router . post ( "/add-session" , async ( req , res ) => {
59
- const request = req . body as AddSessionRequest
60
- if ( ! request . entry ) {
61
+ router . post < { } , string , AddSessionRequest | undefined > ( "/add-session" , async ( req , res ) => {
62
+ const entry = req . body ?. entry
63
+ if ( ! entry ) {
61
64
res . status ( 400 ) . send ( "entry is required" )
65
+ return
62
66
}
63
- editorSessionManager . addSession ( request . entry )
64
- res . status ( 200 ) . send ( )
67
+ editorSessionManager . addSession ( entry )
68
+ res . status ( 200 ) . send ( "session added" )
65
69
} )
66
70
67
- router . post ( "/delete-session" , async ( req , res ) => {
68
- const request = req . body as DeleteSessionRequest
69
- if ( ! request . socketPath ) {
71
+ router . post < { } , string , DeleteSessionRequest | undefined > ( "/delete-session" , async ( req , res ) => {
72
+ const socketPath = req . body ?. socketPath
73
+ if ( ! socketPath ) {
70
74
res . status ( 400 ) . send ( "socketPath is required" )
75
+ return
71
76
}
72
- editorSessionManager . deleteSession ( request . socketPath )
73
- res . status ( 200 ) . send ( )
77
+ editorSessionManager . deleteSession ( socketPath )
78
+ res . status ( 200 ) . send ( "session deleted" )
74
79
} )
75
80
76
81
const server = http . createServer ( router )
0 commit comments