mirror of
https://github.com/slynn1324/tinypin.git
synced 2026-01-23 02:25:08 +00:00
merge
This commit is contained in:
commit
3cee573bdb
5 changed files with 42 additions and 6 deletions
6
.dockerignore
Normal file
6
.dockerignore
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
*.db
|
||||
*.psd
|
||||
*.crx
|
||||
*.pem
|
||||
.gitignore
|
||||
.git
|
||||
11
Dockerfile
Normal file
11
Dockerfile
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
FROM node:alpine3.12
|
||||
|
||||
COPY . /tinypin
|
||||
|
||||
WORKDIR /tinypin
|
||||
|
||||
RUN apk add build-base python3 && npm install --verbose && apk del build-base python3
|
||||
|
||||
RUN npm install
|
||||
|
||||
ENTRYPOINT ["sh", "-c" , "node server.js -i /data/images -d /data/tinypin.db"]
|
||||
2
docker-build.sh
Executable file
2
docker-build.sh
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
docker build -t tinypin .
|
||||
4
docker-run.sh
Executable file
4
docker-run.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
#-e TINYPIN_SLOW=2000
|
||||
docker run -d --name tinypin -p 3001:3000 -v "$(pwd)/data:/data" --restart=unless-stopped tinypin
|
||||
25
server.js
25
server.js
|
|
@ -10,6 +10,17 @@ const fs = require('fs').promises;
|
|||
const path = require('path');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.info('ctrl+c detected, exiting tinypin');
|
||||
console.info('goodbye.');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
console.info('sigterm detected, exiting tinypin');
|
||||
console.info('goodbye.');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
const argv = yargs
|
||||
.option('slow', {
|
||||
|
|
@ -49,8 +60,10 @@ console.log('configuration:');
|
|||
console.log(` port: ${PORT}`);
|
||||
console.log(` database path: ${DB_PATH}`);
|
||||
console.log(` image path: ${IMAGE_PATH}`)
|
||||
if ( argv.slow ){
|
||||
console.log(` slow mode delay: ${argv.slow}`);
|
||||
|
||||
const SLOW = argv.slow || parseInt(process.env.TINYPIN_SLOW);
|
||||
if ( SLOW ){
|
||||
console.log(` slow mode delay: ${SLOW}`);
|
||||
}
|
||||
console.log('');
|
||||
|
||||
|
|
@ -59,18 +72,18 @@ const db = betterSqlite3(DB_PATH);
|
|||
// express config
|
||||
const app = express();
|
||||
app.use(express.static('static'));
|
||||
app.use(express.static('images'));
|
||||
app.use(express.static(IMAGE_PATH));
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
app.use(bodyParser.json());
|
||||
app.set('json spaces', 2);
|
||||
|
||||
//emulate slow down
|
||||
if ( argv.slow ){
|
||||
if ( SLOW ){
|
||||
app.use( (req,res,next) => {
|
||||
console.log("slow...");
|
||||
setTimeout(() => {
|
||||
next();
|
||||
}, 2000);
|
||||
}, SLOW);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -413,4 +426,4 @@ function getThumbnailImagePath(pinId){
|
|||
let dir = `${IMAGE_PATH}/thumbnails/${paddedId[11]}/${paddedId[10]}/${paddedId[9]}/${paddedId[8]}`;
|
||||
let file = `${dir}/${paddedId}.jpg`;
|
||||
return {dir: dir, file: file};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue