@@ -20,11 +20,11 @@ export interface EditorSessionEntry {
2020}
2121
2222interface DeleteSessionRequest {
23- socketPath : string
23+ socketPath ? : string
2424}
2525
2626interface AddSessionRequest {
27- entry : EditorSessionEntry
27+ entry ? : EditorSessionEntry
2828}
2929
3030interface GetSessionResponse {
@@ -40,37 +40,42 @@ export async function makeEditorSessionManagerServer(
4040 // eslint-disable-next-line import/no-named-as-default-member
4141 router . use ( express . json ( ) )
4242
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+ )
5760
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 ) {
6164 res . status ( 400 ) . send ( "entry is required" )
65+ return
6266 }
63- editorSessionManager . addSession ( request . entry )
64- res . status ( 200 ) . send ( )
67+ editorSessionManager . addSession ( entry )
68+ res . status ( 200 ) . send ( "session added" )
6569 } )
6670
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 ) {
7074 res . status ( 400 ) . send ( "socketPath is required" )
75+ return
7176 }
72- editorSessionManager . deleteSession ( request . socketPath )
73- res . status ( 200 ) . send ( )
77+ editorSessionManager . deleteSession ( socketPath )
78+ res . status ( 200 ) . send ( "session deleted" )
7479 } )
7580
7681 const server = http . createServer ( router )
0 commit comments