Skip to content

Commit 62f0f7a

Browse files
committed
them do an
1 parent 77cb2ff commit 62f0f7a

File tree

2,011 files changed

+829026
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,011 files changed

+829026
-0
lines changed

Diff for: sachcu.store/.vscode/settings.json

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

Diff for: sachcu.store/app.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var createError = require('http-errors');
2+
var fs=require("fs");
3+
var express = require('express');
4+
var path = require('path');
5+
var cookieParser = require('cookie-parser');
6+
var logger = require('morgan');
7+
8+
var indexRouter = require('./routes/index');
9+
var usersRouter = require('./routes/users');
10+
11+
var app = express();
12+
13+
// view engine setup
14+
app.set('views', path.join(__dirname, 'views'));
15+
app.set('view engine', 'ejs');
16+
17+
app.use(logger('dev'));
18+
app.use(express.json());
19+
app.use(express.urlencoded({ extended: false }));
20+
app.use(cookieParser());
21+
app.use(express.static(path.join(__dirname, 'public')));
22+
23+
app.use('/', indexRouter);
24+
app.use('/users', usersRouter);
25+
26+
// catch 404 and forward to error handler
27+
app.use(function(req, res, next) {
28+
next(createError(404));
29+
});
30+
31+
// error handler
32+
app.use(function(err, req, res, next) {
33+
// set locals, only providing error in development
34+
res.locals.message = err.message;
35+
res.locals.error = req.app.get('env') === 'development' ? err : {};
36+
37+
// render the error page
38+
res.status(err.status || 500);
39+
res.render('error');
40+
});
41+
42+
app.locals.ArrBook=require("./model/book.json");
43+
module.exports = app;

Diff for: sachcu.store/bin/www

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('bootstrap:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
84+
function onListening() {
85+
var addr = server.address();
86+
var bind = typeof addr === 'string'
87+
? 'pipe ' + addr
88+
: 'port ' + addr.port;
89+
debug('Listening on ' + bind);
90+
}

Diff for: sachcu.store/model/b.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
{
3+
"ID":"1",
4+
"NAME":"Danh sach book",
5+
"Book":"Hoà"
6+
},
7+
{
8+
"ID":"2",
9+
"NAME":"Danh sach user",
10+
"Users":"cuong"
11+
}
12+
}

Diff for: sachcu.store/model/book.json

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"ID":1,
3+
"NAME":"Danh sach book",
4+
"Book":[
5+
{
6+
"BookID":1,
7+
"BookName":"Quẳng Gánh Lo Đi Và Vui Sống",
8+
"BookAuthor":"Nguyễn Hiến Lê",
9+
"BookPrice":"20.000đ",
10+
"Status":"Sách đã qua sử dụng 3 tháng, bìa hơi bị nhăn, có môt số trang bị gấp mép",
11+
"MainPhoto":"https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book1.img1.jpg",
12+
"SubPhoto":["https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book1.img2.jpg","https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book1.img3.jpg"]
13+
},
14+
{
15+
"BookID":2,
16+
"BookName":"Khi Hơi Thở Hóa Thinh Không",
17+
"BookAuthor":"Paul Kalanithi",
18+
"BookPrice":"70.500₫",
19+
"Status":"Sách còn mới 95%, không bị rách, không dính mực hoặc tẩy xoá",
20+
"MainPhoto":"https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book2.img1.jpg",
21+
"SubPhoto":["https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book2.img2.jpg","https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book2.img3.jpg"]
22+
},
23+
{
24+
"BookID":3,
25+
"BookName":"Truyện Thúy Kiều (Tái Bản)",
26+
"BookAuthor":"Nguyễn Du",
27+
"BookPrice":"48.980₫",
28+
"Status":"Sách mới sử dụng 1 lần, không bị rách, mực in rõ không bị nhoè",
29+
"MainPhoto":"https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book3.img1.jpg",
30+
"SubPhoto":[]
31+
},
32+
{
33+
"BookID":4,
34+
"BookName":"Bội Tình - Thơ",
35+
"BookAuthor":"Vanness Uyên (Mỡ)",
36+
"BookPrice":"100.000₫",
37+
"Status":"Sách sử dụng được 1 năm, một số trang bị rách",
38+
"MainPhoto":"https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book4.img1.jpg",
39+
"SubPhoto":["https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book4.img2.jpg","https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book4.img3.jpg"]
40+
},
41+
{
42+
"BookID":5,
43+
"BookName":"Người Lớn Không Khóc (Tái Bản)",
44+
"BookAuthor":"Hamlet Trương",
45+
"BookPrice":"51.350₫",
46+
"Status":"Sách đã qua sử dụng một vài lần",
47+
"MainPhoto":"https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book5.img1.jpg",
48+
"SubPhoto":[]
49+
},
50+
{
51+
"BookID":6,
52+
"BookName":"Bí Mật Dinh Dưỡng Cho Sức Khỏe Toàn Diện",
53+
"BookAuthor":"Thomas M. Campbell II",
54+
"BookPrice":"190.000₫",
55+
"Status":"Sách đã qua sử dụng một vài lần, còn mới nguyên vẹn",
56+
"MainPhoto":"https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book6.img1.jpg",
57+
"SubPhoto":["https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book6.img2.jpg","https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book6.img3.jpg"]
58+
},
59+
{
60+
"BookID":4,
61+
"BookName":"Bội Tình - Thơ",
62+
"BookAuthor":"Vanness Uyên (Mỡ)",
63+
"BookPrice":"100.000₫",
64+
"Status":"Sách sử dụng được 1 năm, một số trang bị rách",
65+
"MainPhoto":"https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book4.img1.jpg",
66+
"SubPhoto":["https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book4.img2.jpg","https://s3-us-west-2.amazonaws.com/sachcu.store/sach/book4.img3.jpg"]
67+
}
68+
],
69+
"ID":2,
70+
"NAME":"Danh sach user",
71+
"Users":[
72+
{
73+
"UserID":1,
74+
"UserName":"vucuong1112",
75+
"UserPassword":"123456",
76+
"UserLocation":"12 Nguyễn Văn Bảo, P4, Gò Vấp, TP HCM",
77+
"UserPhoneNumber":"0966072266",
78+
"UserImg":"https://s3-us-west-2.amazonaws.com/sachcu.store/users/avt1.jpg",
79+
"BookSell":[1,6]
80+
},
81+
{
82+
"UserID":2,
83+
"UserName":"khoadang",
84+
"UserPassword":"123456",
85+
"UserLocation":"12 Nguyễn Văn Bảo, P4, Gò Vấp, TP HCM",
86+
"UserPhoneNumber":"0999657262",
87+
"UserImg":"https://s3-us-west-2.amazonaws.com/sachcu.store/users/avt2.jpg",
88+
"BookSell":[2,3]
89+
},
90+
{
91+
"UserID":3,
92+
"UserName":"tuanminh",
93+
"UserPassword":"123456",
94+
"UserLocation":"12 Nguyễn Văn Bảo, P4, Gò Vấp, TP HCM",
95+
"UserPhoneNumber":"09636372233",
96+
"UserImg":"https://s3-us-west-2.amazonaws.com/sachcu.store/users/avt3.jpg",
97+
"BookSell":[4,5]
98+
}
99+
]
100+
}

Diff for: sachcu.store/model/napdulieu.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var AWS = require("aws-sdk");
2+
var fs=require("fs");
3+
4+
AWS.config.update({
5+
region:"us-west-2",
6+
endpoint:"http://dynamodb.us-west-2.amazonaws.com",
7+
accessKeyId: "AKIAIMF4ROOBX63PWXSA",
8+
secretAccessKey: "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"
9+
});
10+
11+
var docClient=new AWS.DynamoDB.DocumentClient();
12+
console.log("Dang load du lieu... vui long doi trong giay lat");
13+
14+
var dsBook=JSON.parse(fs.readFileSync("b.json","utf8"));
15+
function a(dsBook){
16+
// console.log(book.BookName);
17+
// console.log(book.BookYear);
18+
// gan du lieu thogng
19+
var params={
20+
TableName:"SACHCU.STORE",
21+
Item:{
22+
"ID":dsBook.ID,
23+
"NAME":dsBook.NAME
24+
}
25+
26+
};
27+
// console.log(params.Item.BookName);
28+
// console.log(params.Item.BookYear);
29+
30+
// docClient.putItem(params,function(err,data){
31+
// if(err) console.log(err);
32+
// //else console.log(book.BookName);
33+
// });
34+
docClient.put(params, function(err, data) {
35+
if (err) {
36+
console.error("Unable to add book", dsBook.NAME, ". Error JSON:", JSON.stringify(err, null, 2));
37+
} else {
38+
console.log("PutItem succeeded:", dsBook.Book);
39+
}
40+
});
41+
};
42+
a(dsBook);

Diff for: sachcu.store/model/s3.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const AWS = require('aws-sdk');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
//configuring the AWS environment
6+
AWS.config.update({
7+
accessKeyId: "AKIAIMF4ROOBX63PWXSA",
8+
secretAccessKey: "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"
9+
});
10+
11+
var s3 = new AWS.S3();
12+
var filePath = "../public/images/hinh.jpg";
13+
14+
//configuring parameters
15+
var params = {
16+
Bucket: 'sachcu.store',
17+
Body : fs.createReadStream(filePath),
18+
Key : "sachcu/"+Date.now()+"_"+path.basename(filePath),
19+
ACL: 'public-read-write'
20+
};
21+
22+
// https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#CannedACL
23+
24+
s3.upload(params, function (err, data) {
25+
//handle error
26+
if (err) {
27+
console.log("Error", err);
28+
}
29+
30+
//success
31+
if (data) {
32+
console.log("Uploaded in:", data.Location);
33+
}
34+
});

Diff for: sachcu.store/model/taobang.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var AWS=require("aws-sdk");
2+
AWS.config.update({
3+
region:"us-west-2",
4+
endpoint:"http://dynamodb.us-west-2.amazonaws.com",
5+
accessKeyId: "AKIAIMF4ROOBX63PWXSA",
6+
secretAccessKey: "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"
7+
});
8+
9+
var dynamodb=new AWS.DynamoDB();
10+
var params = {
11+
TableName : "SACHCU.STORE",
12+
KeySchema: [
13+
// ?? bookyear--> range, booknamw-->hash??
14+
{ AttributeName: "ID", KeyType: "HASH"}
15+
],
16+
AttributeDefinitions: [
17+
{ AttributeName: "ID", AttributeType: "S" }
18+
],
19+
ProvisionedThroughput: {
20+
ReadCapacityUnits: 5,
21+
WriteCapacityUnits: 5
22+
}
23+
};
24+
25+
dynamodb.createTable(params,function(err,data){
26+
if(err)
27+
console.log(err);
28+
else{
29+
console.log("create success table Book");
30+
}
31+
});

Diff for: sachcu.store/node_modules/.bin/mime

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: sachcu.store/node_modules/.bin/mime.cmd

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)