Skip to content

Commit b08e0a8

Browse files
Merge pull request #2 from Dynamsoft/release/v1.0.x/v1.0.2
feat: release v1.0.2
2 parents 24a0345 + b0d53a6 commit b08e0a8

21 files changed

+942
-249
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: CI
42

53
# Controls when the workflow will run
@@ -20,7 +18,6 @@ jobs:
2018

2119
# Steps represent a sequence of tasks that will be executed as part of the job
2220
steps:
23-
# Runs a set of commands using the runners shell
2421
- name: Get Source
2522
run: |
2623
cd /home/ubuntu
@@ -30,22 +27,21 @@ jobs:
3027
- name: Prepare Files
3128
run: |
3229
# Create a temporary directory for the files to be uploaded
33-
mkdir -p /home/ubuntu/document-scanner-javascript/demo
30+
mkdir -p /home/ubuntu/document-scanner-javascript/deploy
3431
3532
# Copy the dist folder
36-
cp -r /home/ubuntu/document-scanner-javascript/dist /home/ubuntu/document-scanner-javascript/demo
33+
cp -r /home/ubuntu/document-scanner-javascript/dist /home/ubuntu/document-scanner-javascript/deploy
3734
38-
# Copy the samples folder and rename demo.html to index.html
39-
cp -r /home/ubuntu/document-scanner-javascript/samples/* /home/ubuntu/document-scanner-javascript/demo
40-
mv /home/ubuntu/document-scanner-javascript/demo/demo.html /home/ubuntu/document-scanner-javascript/demo/index.html
35+
# Copy demo and hello world. On demo branch, be sure to update the pathing for the demo
36+
cp -r /home/ubuntu/document-scanner-javascript/samples/demo/* /home/ubuntu/document-scanner-javascript/deploy
37+
cp -r /home/ubuntu/document-scanner-javascript/samples/hello-world.html /home/ubuntu/document-scanner-javascript/deploy
4138
42-
4339
- name: Sync files
4440
uses: SamKirkland/[email protected]
4541
with:
4642
server: ${{ secrets.FTP_DEMO_SERVER }}
4743
username: ${{ secrets.FTP_DEMO_USERNAME }}
4844
password: ${{ secrets.FTP_DEMO_PASSWORD }}
4945
port: 21
50-
local-dir: /home/ubuntu/document-scanner-javascript/demo/
51-
server-dir: /Demo.dynamsoft.com/document-scanner/
46+
local-dir: /home/ubuntu/document-scanner-javascript/deploy/
47+
server-dir: /Demo.dynamsoft.com/document-scanner/

README.md

Lines changed: 554 additions & 77 deletions
Large diffs are not rendered by default.

dev-server/index.js

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import formidable from "formidable";
12
import express from "express";
23
import fs from "fs";
34
import http from "http";
@@ -32,23 +33,69 @@ app.use(
3233

3334
// Serve static files
3435
app.use("/dist", express.static(distPath));
35-
app.use("/assets", express.static(path.join(__dirname, "../samples/assets")));
36-
app.use("/css", express.static(path.join(__dirname, "../samples/css")));
37-
app.use("/font", express.static(path.join(__dirname, "../samples/font")));
36+
app.use("/assets", express.static(path.join(__dirname, "../samples/demo/assets")));
37+
app.use("/css", express.static(path.join(__dirname, "../samples/demo/css")));
38+
app.use("/font", express.static(path.join(__dirname, "../samples/demo/font")));
3839

3940
// Routes
4041
app.get("/", (req, res) => {
41-
res.sendFile(path.join(__dirname, "../samples/demo.html"));
42+
res.sendFile(path.join(__dirname, "../samples/hello-world.html"));
4243
});
4344

4445
app.get("/demo", (req, res) => {
45-
res.sendFile(path.join(__dirname, "../samples/demo.html"));
46+
res.sendFile(path.join(__dirname, "../samples/demo/index.html"));
4647
});
4748

4849
app.get("/hello-world", (req, res) => {
4950
res.sendFile(path.join(__dirname, "../samples/hello-world.html"));
5051
});
5152

53+
// Allow upload feature
54+
app.post("/upload", function (req, res) {
55+
try {
56+
// Create a new Formidable form
57+
const form = formidable({
58+
multiples: false,
59+
keepExtensions: true,
60+
});
61+
62+
form.parse(req, (err, fields, files) => {
63+
if (err) {
64+
console.error(err);
65+
return res.status(500).send("Error processing the file upload.");
66+
}
67+
68+
const uploadedFile = files.uploadFile[0]; // Ensure the file field name matches the form
69+
if (!uploadedFile) {
70+
return res.status(400).json({ success: false, message: "No file uploaded" });
71+
}
72+
73+
// Get current timestamp
74+
let dt = new Date();
75+
76+
const fileSavePath = path.join(__dirname, "\\");
77+
const newFileName = uploadedFile.originalFilename;
78+
const newFilePath = path.join(fileSavePath, newFileName);
79+
80+
// Move the uploaded file to the desired directory
81+
fs.rename(uploadedFile.filepath, newFilePath, (err) => {
82+
if (err) {
83+
console.error(err);
84+
return res.status(500).send("Error saving the file.");
85+
}
86+
console.log(`\x1b[33m ${newFileName} \x1b[0m uploaded successfully!`);
87+
});
88+
res.status(200).json({
89+
success: true,
90+
message: `${newFileName} uploaded successfully`,
91+
filename: newFileName,
92+
});
93+
});
94+
} catch (error) {
95+
res.status(500).send("An error occurred during file upload.");
96+
}
97+
});
98+
5299
let httpPort = 3000;
53100
let httpsPort = 3001;
54101

@@ -107,10 +154,11 @@ httpsServer.on("error", (error) => {
107154

108155
// Start the servers
109156
httpServer.listen(httpPort, () => {
110-
console.log("\n\x1b[1m Dynamsoft Document Scanner Sample\x1b[0m\n");
111-
console.log("\x1b[36m Access URLs:\x1b[0m");
157+
console.log("\n\x1b[1m Dynamsoft Document Scanner Samples\x1b[0m\n");
158+
console.log("\x1b[36m HTTP URLs:\x1b[0m");
112159
console.log("\x1b[90m-------------------\x1b[0m");
113-
console.log("\x1b[32m Local:\x1b[0m http://localhost:" + httpPort + "/");
160+
console.log("\x1b[33m Hello World:\x1b[0m http://localhost:" + httpPort + "/hello-world");
161+
console.log("\x1b[33m Demo:\x1b[0m http://localhost:" + httpPort + "/demo");
114162
});
115163

116164
httpsServer.listen(httpsPort, "0.0.0.0", () => {
@@ -124,13 +172,13 @@ httpsServer.listen(httpsPort, "0.0.0.0", () => {
124172
});
125173
});
126174

175+
console.log("\n");
176+
console.log("\x1b[36m HTTPS URLs:\x1b[0m");
177+
console.log("\x1b[90m-------------------\x1b[0m");
127178
ipv4Addresses.forEach((localIP) => {
128-
console.log("\x1b[32m Network:\x1b[0m https://" + localIP + ":" + httpsPort + "/");
179+
console.log("\x1b[32m Hello World:\x1b[0m https://" + localIP + ":" + httpsPort + "/hello-world");
180+
console.log("\x1b[32m Demo:\x1b[0m https://" + localIP + ":" + httpsPort + "/demo");
129181
});
130-
console.log("\x1b[36m Available Pages:\x1b[0m");
131-
console.log("\x1b[90m-------------------\x1b[0m");
132-
console.log("\x1b[33m Demo:\x1b[0m /demo");
133-
console.log("\x1b[33m Hello World:\x1b[0m /hello-world\n");
134-
182+
console.log("\n");
135183
console.log("\x1b[90mPress Ctrl+C to stop the server\x1b[0m\n");
136184
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dynamsoft-document-scanner",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Dynamsoft Document Scanner (DDS) is a ready-to-use SDK for capturing and enhancing document images with automatic border detection, correction, and customizable workflows.",
55
"files": [
66
"/dist",

0 commit comments

Comments
 (0)