Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
buu-ci-cd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Melon User
buu-ci-cd
Compare revisions
f6f9a12ba76c69da014ef99766ca1b3c7ec0d115 to main
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
melonuser/buu-ci-cd
Select target project
No results found
main
Select Git revision
Branches
main
1 result
Swap
Target
65160386/buu-ci-cd
Select target project
melonuser/buu-ci-cd
65160382/buu-ci-cd
65160266/testnode
65160014/buu-ci-cd
65160386/buu-ci-cd
65160269/buu-ci-cd
65160117/buu-ci-cd-01
65160249/buu-ci-cd
65160128/buu-ci-cd
65160246/melon-cd-demo
65160116/buu-ci-cd
65160392/buu-ci-cd
12 results
f6f9a12ba76c69da014ef99766ca1b3c7ec0d115
Select Git revision
Branches
main
1 result
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source
1
init ci cd first
· f99268e4
Melon User
authored
5 months ago
f99268e4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
data/qr_1741789899794.png
+0
-0
0 additions, 0 deletions
data/qr_1741789899794.png
index.js
+149
-0
149 additions, 0 deletions
index.js
package-lock.json
+1162
-0
1162 additions, 0 deletions
package-lock.json
package.json
+16
-0
16 additions, 0 deletions
package.json
with
1327 additions
and
0 deletions
data/qr_1741789899794.png
0 → 100644
View file @
f99268e4
615 B
This diff is collapsed.
Click to expand it.
index.js
0 → 100644
View file @
f99268e4
require
(
'
dotenv
'
).
config
();
const
express
=
require
(
'
express
'
);
const
mysql
=
require
(
'
mysql2/promise
'
);
const
fs
=
require
(
'
fs
'
);
const
path
=
require
(
'
path
'
);
const
qr
=
require
(
'
qr-image
'
);
const
promptpay
=
require
(
'
promptpay-qr
'
);
const
app
=
express
();
app
.
use
(
express
.
json
());
app
.
use
(
express
.
urlencoded
({
extended
:
true
}));
// Database configuration
const
pool
=
mysql
.
createPool
({
host
:
process
.
env
.
DB_HOST
||
"
202.151.176.72
"
,
port
:
process
.
env
.
DB_PORT
||
"
3306
"
,
user
:
process
.
env
.
DB_USER
||
"
root
"
,
password
:
process
.
env
.
DB_PASSWORD
||
"
FTOedf36275
"
,
database
:
process
.
env
.
DB_NAME
||
"
qr_code
"
,
waitForConnections
:
true
,
connectionLimit
:
10
,
queueLimit
:
0
});
// Check database connection
async
function
testConnection
()
{
try
{
const
connection
=
await
pool
.
getConnection
();
await
connection
.
ping
();
console
.
log
(
'
Database connection succeeded.
'
);
connection
.
release
();
}
catch
(
err
)
{
console
.
error
(
'
Database connection failed:
'
,
err
);
process
.
exit
(
1
);
// Terminate the app if the database connection fails
}
}
testConnection
();
// Initialize database (create table if not exists)
async
function
initDB
()
{
const
createTableQuery
=
`
CREATE TABLE IF NOT EXISTS qr_code (
id INT AUTO_INCREMENT PRIMARY KEY,
promptpay_id VARCHAR(50) NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
image_path TEXT NOT NULL
)`
;
try
{
await
pool
.
query
(
createTableQuery
);
}
catch
(
err
)
{
console
.
error
(
'
Failed to create table:
'
,
err
);
}
}
initDB
().
catch
(
console
.
error
);
// Serve static QR images from ./data
const
imageDir
=
path
.
join
(
__dirname
,
'
data
'
);
if
(
!
fs
.
existsSync
(
imageDir
))
fs
.
mkdirSync
(
imageDir
);
app
.
use
(
'
/qr-images
'
,
express
.
static
(
imageDir
));
// Main page route (QR generation form)
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
res
.
send
(
`
<h1>Generate PromptPay QR Code</h1>
<form method="POST" action="/generate">
<label>PromptPay ID:</label><br/>
<input type="text" name="promptpayId" required /><br/><br/>
<label>Amount:</label><br/>
<input type="number" name="amount" step="0.01" required /><br/><br/>
<button type="submit">Generate QR</button>
</form>
<br/>
<a href="/list">View QR List</a>
`
);
});
// Route to generate QR code
app
.
post
(
'
/generate
'
,
async
(
req
,
res
)
=>
{
const
{
promptpayId
,
amount
}
=
req
.
body
;
if
(
!
promptpayId
||
!
amount
)
{
return
res
.
status
(
400
).
send
(
'
Missing promptpayId or amount
'
);
}
try
{
console
.
log
(
promptpay
);
const
qrData
=
promptpay
(
promptpayId
,
parseFloat
(
amount
));
const
qrPng
=
qr
.
imageSync
(
qrData
,
{
type
:
'
png
'
});
const
fileName
=
`qr_
${
Date
.
now
()}
.png`
;
const
savePath
=
path
.
join
(
imageDir
,
fileName
);
fs
.
writeFileSync
(
savePath
,
qrPng
);
const
insertQuery
=
`
INSERT INTO qr_code (promptpay_id, amount, image_path)
VALUES (?, ?, ?)`
;
const
[
result
]
=
await
pool
.
execute
(
insertQuery
,
[
promptpayId
,
amount
,
fileName
]);
res
.
send
(
`
<h2>QR Generated Successfully</h2>
<p>ID:
${
result
.
insertId
}
</p>
<p>PromptPay ID:
${
promptpayId
}
</p>
<p>Amount:
${
amount
}
</p>
<p>Image: <a href="/qr-images/
${
fileName
}
" target="_blank">View QR Code</a></p>
<br/>
<a href="/">Go Back</a> | <a href="/list">View All QR Codes</a>
`
);
}
catch
(
err
)
{
console
.
error
(
'
Error during QR generation:
'
,
err
);
res
.
status
(
500
).
send
(
'
Internal Server Error
'
);
}
});
// Route to list generated QR codes
app
.
get
(
'
/list
'
,
async
(
req
,
res
)
=>
{
try
{
const
[
rows
]
=
await
pool
.
query
(
'
SELECT * FROM qr_code ORDER BY id DESC
'
);
let
html
=
`<h1>List of Generated QR Codes</h1>`
;
html
+=
`<table border="1" cellpadding="5" cellspacing="0">
<tr>
<th>ID</th>
<th>PromptPay ID</th>
<th>Amount</th>
<th>QR Code Image</th>
</tr>`
;
rows
.
forEach
(
row
=>
{
html
+=
`<tr>
<td>
${
row
.
id
}
</td>
<td>
${
row
.
promptpay_id
}
</td>
<td>
${
row
.
amount
}
</td>
<td><a href="/qr-images/
${
row
.
image_path
}
" target="_blank">View Image</a></td>
</tr>`
;
});
html
+=
`</table><br/><a href="/">Go Back</a>`
;
res
.
send
(
html
);
}
catch
(
err
)
{
console
.
error
(
'
Error fetching QR list:
'
,
err
);
res
.
status
(
500
).
send
(
'
Internal Server Error
'
);
}
});
// Start the server
const
port
=
process
.
env
.
PORT
||
3000
;
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`Server started on port
${
port
}
`
);
});
This diff is collapsed.
Click to expand it.
package-lock.json
0 → 100644
View file @
f99268e4
This diff is collapsed.
Click to expand it.
package.json
0 → 100644
View file @
f99268e4
{
"name"
:
"my-qr-demo"
,
"version"
:
"1.0.0"
,
"main"
:
"index.js"
,
"scripts"
:
{
"start"
:
"node index.js"
},
"dependencies"
:
{
"
dotenv
"
:
"
^16.4.7
"
,
"
express
"
:
"
^4.18.2
"
,
"
fs-extra
"
:
"
^11.1.0
"
,
"
mysql2
"
:
"
^3.2.0
"
,
"
promptpay-qr
"
:
"
^0.5.0
"
,
"
qr-image
"
:
"
^3.2.0
"
}
}
This diff is collapsed.
Click to expand it.