@@ -36,6 +36,7 @@ app.use("/dist", express.static(distPath));
3636app . use ( "/assets" , express . static ( path . join ( __dirname , "../samples/demo/assets" ) ) ) ;
3737app . use ( "/css" , express . static ( path . join ( __dirname , "../samples/demo/css" ) ) ) ;
3838app . use ( "/font" , express . static ( path . join ( __dirname , "../samples/demo/font" ) ) ) ;
39+ app . use ( "/samples" , express . static ( path . join ( __dirname , "../samples" ) ) ) ;
3940
4041// Routes
4142app . get ( "/" , ( req , res ) => {
@@ -50,8 +51,16 @@ app.get("/hello-world", (req, res) => {
5051 res . sendFile ( path . join ( __dirname , "../samples/hello-world.html" ) ) ;
5152} ) ;
5253
53- app . get ( "/scenarios/use-file-input" , ( req , res ) => {
54- res . sendFile ( path . join ( __dirname , "../samples/scenarios/use-file-input.html" ) ) ;
54+ app . get ( "/multi-page-scanning" , ( req , res ) => {
55+ res . sendFile ( path . join ( __dirname , "../samples/scenarios/multi-page-scanning.html" ) ) ;
56+ } ) ;
57+
58+ app . get ( "/scanning-to-pdf" , ( req , res ) => {
59+ res . sendFile ( path . join ( __dirname , "../samples/scenarios/scanning-to-pdf.html" ) ) ;
60+ } ) ;
61+
62+ app . get ( "/image-file-scanning" , ( req , res ) => {
63+ res . sendFile ( path . join ( __dirname , "../samples/scenarios/image-file-scanning.html" ) ) ;
5564} ) ;
5665
5766// Allow upload feature
@@ -74,11 +83,9 @@ app.post("/upload", function (req, res) {
7483 return res . status ( 400 ) . json ( { success : false , message : "No file uploaded" } ) ;
7584 }
7685
77- // Get current timestamp
78- let dt = new Date ( ) ;
79-
80- const fileSavePath = path . join ( __dirname , "\\" ) ;
81- const newFileName = uploadedFile . originalFilename ;
86+ // Sanitize filename to prevent path traversal
87+ const newFileName = path . basename ( uploadedFile . originalFilename ) ;
88+ const fileSavePath = __dirname ;
8289 const newFilePath = path . join ( fileSavePath , newFileName ) ;
8390
8491 // Move the uploaded file to the desired directory
@@ -88,11 +95,11 @@ app.post("/upload", function (req, res) {
8895 return res . status ( 500 ) . send ( "Error saving the file." ) ;
8996 }
9097 console . log ( `\x1b[33m ${ newFileName } \x1b[0m uploaded successfully!` ) ;
91- } ) ;
92- res . status ( 200 ) . json ( {
93- success : true ,
94- message : ` ${ newFileName } uploaded successfully` ,
95- filename : newFileName ,
98+ res . status ( 200 ) . json ( {
99+ success : true ,
100+ message : ` ${ newFileName } uploaded successfully` ,
101+ filename : newFileName ,
102+ } ) ;
96103 } ) ;
97104 } ) ;
98105 } catch ( error ) {
@@ -151,7 +158,7 @@ httpsServer.on("error", (error) => {
151158 console . log ( `2. Close any other applications using port ${ httpsPort } ` ) ;
152159 console . log ( `3. Wait a few moments and try again - the port might be in a cleanup state\n` ) ;
153160 } else {
154- console . error ( "\x1b[31mHTTP Server error:\x1b[0m" , error ) ;
161+ console . error ( "\x1b[31mHTTPS Server error:\x1b[0m" , error ) ;
155162 }
156163 process . exit ( 1 ) ;
157164} ) ;
@@ -161,8 +168,12 @@ httpServer.listen(httpPort, () => {
161168 console . log ( "\n\x1b[1m Dynamsoft Document Scanner Samples\x1b[0m\n" ) ;
162169 console . log ( "\x1b[36m HTTP URLs:\x1b[0m" ) ;
163170 console . log ( "\x1b[90m-------------------\x1b[0m" ) ;
164- console . log ( "\x1b[33m Hello World:\x1b[0m http://localhost:" + httpPort + "/hello-world" ) ;
165- console . log ( "\x1b[33m Demo:\x1b[0m http://localhost:" + httpPort + "/demo" ) ;
171+ console . log ( "\x1b[1m\x1b[35m → Samples Index:\x1b[0m \x1b[1mhttp://localhost:" + httpPort + "/samples\x1b[0m" ) ;
172+ console . log ( "\x1b[33m Hello World:\x1b[0m http://localhost:" + httpPort + "/hello-world" ) ;
173+ console . log ( "\x1b[33m Scanning to PDF:\x1b[0m http://localhost:" + httpPort + "/scanning-to-pdf" ) ;
174+ console . log ( "\x1b[33m Demo:\x1b[0m http://localhost:" + httpPort + "/demo" ) ;
175+ console . log ( "\x1b[33m Multi-Page Scanning:\x1b[0m http://localhost:" + httpPort + "/multi-page-scanning" ) ;
176+ console . log ( "\x1b[33m Image File Scanning:\x1b[0m http://localhost:" + httpPort + "/image-file-scanning" ) ;
166177} ) ;
167178
168179httpsServer . listen ( httpsPort , "0.0.0.0" , ( ) => {
@@ -179,9 +190,15 @@ httpsServer.listen(httpsPort, "0.0.0.0", () => {
179190 console . log ( "\n" ) ;
180191 console . log ( "\x1b[36m HTTPS URLs:\x1b[0m" ) ;
181192 console . log ( "\x1b[90m-------------------\x1b[0m" ) ;
182- ipv4Addresses . forEach ( ( localIP ) => {
183- console . log ( "\x1b[32m Hello World:\x1b[0m https://" + localIP + ":" + httpsPort + "/hello-world" ) ;
184- console . log ( "\x1b[32m Demo:\x1b[0m https://" + localIP + ":" + httpsPort + "/demo" ) ;
193+ ipv4Addresses . forEach ( ( localIP , index ) => {
194+ if ( index > 0 ) console . log ( "" ) ; // Add spacing between different IPs
195+ console . log ( "\x1b[32m----IP[" + index + "]: " + localIP + "----\x1b" ) ;
196+ console . log ( "\x1b[1m\x1b[35m → Samples Index:\x1b[0m \x1b[1mhttps://" + localIP + ":" + httpsPort + "/samples\x1b[0m" ) ;
197+ console . log ( "\x1b[32m Hello World:\x1b[0m https://" + localIP + ":" + httpsPort + "/hello-world" ) ;
198+ console . log ( "\x1b[32m Scanning to PDF:\x1b[0m https://" + localIP + ":" + httpsPort + "/scanning-to-pdf" ) ;
199+ console . log ( "\x1b[32m Demo:\x1b[0m https://" + localIP + ":" + httpsPort + "/demo" ) ;
200+ console . log ( "\x1b[32m Multi-Page Scanning:\x1b[0m https://" + localIP + ":" + httpsPort + "/multi-page-scanning" ) ;
201+ console . log ( "\x1b[32m Image File Scanning:\x1b[0m https://" + localIP + ":" + httpsPort + "/image-file-scanning" ) ;
185202 } ) ;
186203 console . log ( "\n" ) ;
187204 console . log ( "\x1b[90mPress Ctrl+C to stop the server\x1b[0m\n" ) ;
0 commit comments