Porównaj commity

...

4 Commity

Autor SHA1 Wiadomość Data
Manuel Kasper 1b2ac37d18 Change temporary paths 2022-08-02 17:01:09 +02:00
Manuel Kasper 40febaf6a1 Use environment vars for certain config vars 2022-08-02 16:53:14 +02:00
Manuel Kasper c23962bda2 Change bucket name/path 2022-08-02 14:15:22 +02:00
Manuel Kasper a05edc7b64 Store original photos in Backblaze (S3 compatible object storage) 2022-08-02 13:34:32 +02:00
4 zmienionych plików z 4735 dodań i 24 usunięć

Wyświetl plik

@ -7,8 +7,8 @@ config.http = {
};
config.mongodb = {
url: 'mongodb://sotlas:XXXXXXXX@localhost:27017/sotlas',
dbName: 'sotlas',
url: process.env.MONGODB_URL,
dbName: process.env.MONGODB_DBNAME,
batchSize: 1000
};
@ -45,7 +45,6 @@ config.sotatrailsUrl = 'https://sotatrails.ch/api.php';
config.photos = {
paths: {
original: '/data/images/photos/original',
thumb: '/data/images/photos/thumb',
large: '/data/images/photos/large'
},
@ -59,7 +58,12 @@ config.photos = {
height: 256
}
},
uploadPath: '/data/upload/photos'
uploadPath: '/tmp/upload/photos',
originalStorage: {
endPoint: 's3.eu-central-003.backblazeb2.com',
accessKey: process.env.B2_ACCESS_KEY,
secretKey: process.env.B2_SECRET_KEY
}
};
config.tracks = {
@ -68,7 +72,7 @@ config.tracks = {
simple: '/data/tracks/simple'
},
tolerance: 0.00001,
uploadPath: '/data/upload/tracks'
uploadPath: '/tmp/upload/tracks'
};
config.sso = {
@ -76,10 +80,10 @@ config.sso = {
};
config.mail = {
host: "neon1.net",
port: 587
host: process.env.MAIL_HOST,
port: process.env.MAIL_PORT
};
config.solardata = {
apiKey: 'xxxxxxxxxxxxxxxxx'
apiKey: process.env.SOLARDATA_API_KEY
};

4716
package-lock.json wygenerowano

Plik diff jest za duży Load Diff

Wyświetl plik

@ -26,6 +26,7 @@
"htmlparser2": "^3.10.1",
"jwks-rsa": "^1.6.0",
"maxmind": "^3.1.2",
"minio": "^7.0.29",
"moment": "^2.24.0",
"mongodb": "^3.6.1",
"multer": "^1.4.2",

Wyświetl plik

@ -5,6 +5,8 @@ const fsPromises = require('fs').promises
const exif = require('exif-reader')
const path = require('path')
const hasha = require('hasha')
const minio = require('minio')
const nodemailer = require('nodemailer')
const config = require('./config')
const db = require('./db')
@ -13,15 +15,27 @@ module.exports = {
// Hash input file to determine filename
let hash = await hasha.fromFile(filename, {algorithm: 'sha256'})
let hashFilename = hash.substr(0, 32) + '.jpg'
let originalPath = config.photos.paths.original + '/' + hashFilename.substr(0, 2) + '/' + hashFilename
await fsPromises.mkdir(path.dirname(originalPath), {recursive: true})
let metadata = await getMetadata(filename)
if (metadata.format !== 'jpeg' && metadata.format != 'png' && metadata.format != 'heif') {
throw new Error('Bad input format, must be JPEG, PNG or HEIF')
}
await fsPromises.copyFile(filename, originalPath)
// Upload original photo to Backblaze (don't wait for completion)
let minioClient = new minio.Client(config.photos.originalStorage)
minioClient.fPutObject('sotlas-photos', 'original/' + hashFilename, filename, {'Content-Type': 'image/jpeg'}, (err, etag) => {
if (err) {
console.error(err)
let transporter = nodemailer.createTransport(config.mail)
transporter.sendMail({
from: 'api@sotl.as',
to: 'mk@neon1.net',
subject: 'Backblaze upload failed',
text: `The file ${filename} could not be uploaded:\n${err}`
})
}
})
let photo = {
filename: hashFilename,
@ -84,7 +98,7 @@ module.exports = {
Object.keys(config.photos.sizes).forEach(sizeDescr => {
let outPath = config.photos.paths[sizeDescr] + '/' + hashFilename.substr(0, 2) + '/' + hashFilename
mkdirTasks.push(fsPromises.mkdir(path.dirname(outPath), {recursive: true}))
resizeTasks.push(makeResized(originalPath, outPath, config.photos.sizes[sizeDescr].width, config.photos.sizes[sizeDescr].height))
resizeTasks.push(makeResized(filename, outPath, config.photos.sizes[sizeDescr].width, config.photos.sizes[sizeDescr].height))
})
await Promise.all(mkdirTasks)