Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gcp-hackathon-snap-n-shop-apis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gaurav Jain
gcp-hackathon-snap-n-shop-apis
Commits
7b22ce98
Commit
7b22ce98
authored
Oct 20, 2022
by
Gaurav Jain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
64527ba9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
0 deletions
+77
-0
server.js
server.js
+77
-0
No files found.
server.js
0 → 100644
View file @
7b22ce98
const
http
=
require
(
'http'
);
const
express
=
require
(
'express'
);
var
cors
=
require
(
'cors'
);
var
app
=
express
();
const
vision
=
require
(
'@google-cloud/vision'
);
const
open
=
require
(
'open'
);
let
formidable
=
require
(
'formidable'
);
let
fs
=
require
(
'fs'
);
app
.
use
(
express
.
json
());
app
.
use
(
cors
({
origin
:
'http://localhost:8080'
}));
app
.
listen
(
3000
,
()
=>
{
console
.
log
(
"Server running on port 3000"
);
});
const
CREDENTIALS
=
JSON
.
parse
(
JSON
.
stringify
({
"type"
:
"service_account"
,
"project_id"
:
"skilful-asset-365811"
,
"private_key_id"
:
"4374aaffcf81723277cc5aa47b0726d151dd63dc"
,
"private_key"
:
"-----BEGIN PRIVATE KEY-----
\n
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCf9JZ34BriCUCZ
\n
R/WvDFFa8rltl8KsunXcE8egNbLrf9XVI1Ud+Hcek2jjWiCTfllNcga8FRKXyB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ToBuX6S4f72vsIgKtsLC
\n
JmUU2uNjF2W+Zy861MbjDCvKXyEQxqVuu7wgvbsYQQdp+GG5Zi0rtMqHHRUe5/V0
\n
CMnflau0A0jCK00ev8+z6WvBdwEhxW0/Ua3mJ/c+NaZtwzovbiloyubpAoGAc0C9
\n
n/bkQrtL6LwGp/9grVaC/cKc8tMW5GISuyTIGViFIjNbnCho7i1CAPD5Ta92Y7um
\n
cQuc/zfsPYIWBnlcBJQeZwushmF1AatKO8xRVL4CeXFHzOi1JOaKFps1GLoPX27j
\n
hqBfe40lwdHdPFH6ABekDdcAuZH6YsldC4fGpkECgYBhEPIq/JjZlM1f8xC+0/25
\n
WrCdbrVC55+X+nlN4ky5UGoqW6SGAXvGn5pNI6UfKssTL1tpKxn+hGSPcfNkjZkv
\n
0uNVuyr57iOeOVCtqFhSOqEwYklV0j3PaaepIR27M/6JQmq5UD07dEEBaiiFEtZp
\n
H0QwCpE+z/0Ezo9EVd17vw==
\n
-----END PRIVATE KEY-----
\n
"
,
"client_email"
:
"gcp-18oct-test1@skilful-asset-365811.iam.gserviceaccount.com"
,
"client_id"
:
"116950260649845203323"
,
"auth_uri"
:
"https://accounts.google.com/o/oauth2/auth"
,
"token_uri"
:
"https://oauth2.googleapis.com/token"
,
"auth_provider_x509_cert_url"
:
"https://www.googleapis.com/oauth2/v1/certs"
,
"client_x509_cert_url"
:
"https://www.googleapis.com/robot/v1/metadata/x509/gcp-18oct-test1%40skilful-asset-365811.iam.gserviceaccount.com"
}
));
const
CONFIG
=
{
credentials
:
{
private_key
:
CREDENTIALS
.
private_key
,
client_email
:
CREDENTIALS
.
client_email
}
};
const
client
=
new
vision
.
ImageAnnotatorClient
(
CONFIG
);
const
imageRecognition
=
async
(
file_path
)
=>
{
console
.
log
({
file_path
});
console
.
log
(
"I can tell you what it is! Wait"
);
try
{
let
[
result
]
=
await
client
.
objectLocalization
(
file_path
);
let
names
=
result
.
localizedObjectAnnotations
.
map
(
localizedObject
=>
localizedObject
.
name
);
console
.
log
(
names
);
const
finalURL
=
`https://www.williams-sonoma.com/search/results.html?words=
${
names
.
join
(
","
)}
`
console
.
log
(
finalURL
);
open
(
finalURL
);
open
(
`https://www.amazon.com/s?k=
${
names
}
`
);
}
catch
(
error
)
{
console
.
error
(
error
);
}
};
app
.
post
(
"/image-recognition"
,
async
(
req
,
res
,
next
)
=>
{
console
.
log
(
"I can tell you what it is! Wait"
);
console
.
log
(
'Came here'
);
let
form
=
new
formidable
.
IncomingForm
();
form
.
parse
(
req
,
function
(
error
,
fields
,
file
)
{
console
.
log
({
file
});
let
filepath
=
file
.
imageName
.
filepath
;
let
newPath
=
`/Users/GJain3/Desktop/gcp-hackathon/`
;
newPath
+=
file
.
imageName
.
originalFilename
;
console
.
log
({
newPath
});
fs
.
rename
(
filepath
,
newPath
,
function
(){
imageRecognition
(
newPath
);
res
.
write
(
'Upload file successful'
);
res
.
end
();
});
})
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment