first commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
FROM node:slim
|
||||
|
||||
# We don't need the standalone Chromium
|
||||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
|
||||
|
||||
# Install Google Chrome Stable and fonts
|
||||
# Note: this installs the necessary libs to make the browser work with Puppeteer.
|
||||
RUN apt-get update && apt-get install gnupg wget -y && \
|
||||
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
|
||||
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
|
||||
apt-get update && \
|
||||
apt-get install google-chrome-stable -y --no-install-recommends && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Setting up the work directory
|
||||
WORKDIR /agent
|
||||
|
||||
#Copying all the files in our project
|
||||
COPY . .
|
||||
|
||||
# Installing dependencies
|
||||
RUN npm install
|
||||
|
||||
# Add user so we don't need --no-sandbox.
|
||||
# same layer as npm install to keep re-chowned files from using up several hundred MBs more space
|
||||
# RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
|
||||
# && mkdir -p /home/pptruser/Downloads \
|
||||
# && chown -R pptruser:pptruser /home/pptruser \
|
||||
# && chown -R pptruser:pptruser ./node_modules \
|
||||
# && chown -R pptruser:pptruser ./package.json \
|
||||
# && chown -R pptruser:pptruser ./package-lock.json
|
||||
|
||||
# # Run everything after as non-privileged user.
|
||||
# USER pptruser
|
||||
|
||||
# Starting our application
|
||||
#CMD [ "npm", "run", "debug-cluster" ]
|
||||
CMD [ "npm", "run", "start" ]
|
||||
|
||||
# Exposing server port
|
||||
EXPOSE 3020
|
||||
@@ -0,0 +1,65 @@
|
||||
const asyncHandler = require("express-async-handler");
|
||||
const {ScraperTools} = require('../AuctionServices/Scraper/Scraper.js')
|
||||
const Drouot = require('../AuctionServices/Scraper/Drouot/Drouot.js')
|
||||
const Interencheres = require('../AuctionServices/Scraper/Interencheres/Interencheres.js')
|
||||
|
||||
let CleanUrl = function(url){
|
||||
|
||||
if(String(url).split("http").length > 1){
|
||||
url = 'http'+String(url).split("http")[1]
|
||||
}else{
|
||||
url = ""
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
let getAuctionPlatform = function(Url){
|
||||
|
||||
let AuctionPlatform
|
||||
let STools = new ScraperTools();
|
||||
|
||||
switch (STools.detectPlatform(Url)) {
|
||||
|
||||
case STools._CONST_INTERENCHERES:
|
||||
AuctionPlatform = new Interencheres(Url);
|
||||
break;
|
||||
|
||||
case STools._CONST_DROUOT:
|
||||
AuctionPlatform = new Drouot(Url);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return AuctionPlatform
|
||||
}
|
||||
|
||||
// get Sale info
|
||||
exports.sale = asyncHandler(async (req, res, next) => {
|
||||
|
||||
let url = req.params.url
|
||||
url = decodeURIComponent(url);
|
||||
|
||||
url = CleanUrl(url)
|
||||
if(url == ""){
|
||||
res.status(400).send("URL not supported")
|
||||
}
|
||||
|
||||
try{
|
||||
let AuctionPlatform = getAuctionPlatform(url);
|
||||
if(AuctionPlatform){
|
||||
|
||||
console.log("Agent Follow Sale: ", url)
|
||||
|
||||
AuctionPlatform.Live(req.browser)
|
||||
|
||||
res.status(200).send({"Following URL": url})
|
||||
}else{
|
||||
res.status(400).send("URL not supported")
|
||||
}
|
||||
}catch(e){
|
||||
res.status(500).send("Error: "+e)
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
const asyncHandler = require("express-async-handler");
|
||||
|
||||
// get Sale info
|
||||
exports.health = asyncHandler(async (req, res, next) => {
|
||||
|
||||
try{
|
||||
res.status(200).send("Health OK")
|
||||
}catch(e){
|
||||
res.status(500).send("Error: "+e)
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
|
||||
var bodyParser = require('body-parser');
|
||||
app.use(bodyParser.json())
|
||||
|
||||
//const puppeteer = require('puppeteer');
|
||||
const puppeteer = require('puppeteer-extra');
|
||||
const pluginStealth = require('puppeteer-extra-plugin-stealth');
|
||||
puppeteer.use(pluginStealth())
|
||||
|
||||
const puppeteerMiddleware = require('./middleware/puppeteer');
|
||||
|
||||
(async () => {
|
||||
|
||||
app.use(puppeteerMiddleware(puppeteer));
|
||||
|
||||
// main routes
|
||||
app.use('/internApi/follow', require('./routes/follow'));
|
||||
app.use('/health', require('./routes/health'));
|
||||
|
||||
})();
|
||||
|
||||
|
||||
module.exports = app
|
||||
@@ -0,0 +1,14 @@
|
||||
module.exports = (puppeteer) => {
|
||||
return async (req, res, next) => {
|
||||
|
||||
const browser = await puppeteer.launch({
|
||||
executablePath: '/usr/bin/google-chrome',
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu'],
|
||||
ignoreDefaultArgs: ['--disable-extensions'],
|
||||
headless: 'new'
|
||||
});
|
||||
|
||||
req.browser = browser;
|
||||
next();
|
||||
}
|
||||
}
|
||||
Generated
+2901
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "agent",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon server.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.20.2",
|
||||
"express": "^4.19.2",
|
||||
"express-async-handler": "^1.2.0",
|
||||
"moment-timezone": "^0.5.45",
|
||||
"node-fetch": "^2.6.1",
|
||||
"puppeteer": "^22.6.4",
|
||||
"puppeteer-extra": "^3.3.6",
|
||||
"puppeteer-extra-plugin-stealth": "^2.11.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.0.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const controllers = require('../controllers/follow')
|
||||
const router = require('express').Router()
|
||||
|
||||
router.get('/sale/:url', controllers.sale)
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,6 @@
|
||||
const controllers = require('../controllers/health')
|
||||
const router = require('express').Router()
|
||||
|
||||
router.get('/check', controllers.health)
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,16 @@
|
||||
const app = require('./index.js')
|
||||
|
||||
const port = process.env.PORT || '80'
|
||||
app.listen(port, () => {
|
||||
console.log('Server listening on port '+port);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||
// Application specific logging, throwing an error, or other logic here
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (err, origin) => {
|
||||
console.log('Caught exception: ', err, 'Exception origin: ', origin);
|
||||
// Application specific logging, throwing an error, or other logic here
|
||||
});
|
||||
Reference in New Issue
Block a user