add cli commands
parent
fb684ee324
commit
82e3f1bf59
|
@ -11,9 +11,7 @@
|
|||
"start_dev": "cross-env NODE_ENV=development node dist/server/index.js",
|
||||
"import_without_check": "cross-env NODE_ENV=development node dist/server/bulk_import_images/bulk_import_images_without_check.js",
|
||||
"import_tags": "cross-env NODE_ENV=development node dist/server/bulk_import_images/bulk_import_tags.js",
|
||||
"import_captions": "cross-env NODE_ENV=development node dist/server/bulk_import_images/bulk_import_captions.js",
|
||||
"pm2_start_ms": "pm2 start ./ambience/microservices.config.js",
|
||||
"pm2_start": "pm2 start ./ambience/microservices.config.js && pm2 start"
|
||||
"import_captions": "cross-env NODE_ENV=development node dist/server/bulk_import_images/bulk_import_captions.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emotion/cache": "^11.10.1",
|
||||
|
|
|
@ -1,23 +1,34 @@
|
|||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import image_ops from "../helpers/image_ops"
|
||||
import sharp from "sharp"
|
||||
import config from "../../config/config"
|
||||
import db_ops from "../helpers/db_ops"
|
||||
const myArgs:any = {}
|
||||
for (const arg of process.argv.slice(2)){
|
||||
if(arg === "--use_filename_id"){
|
||||
myArgs["use_filename_id"]=true
|
||||
}
|
||||
}
|
||||
const fsPromises = fs.promises;
|
||||
const PATH_TO_IMAGE_IMPORT = path.join(config.root_path, 'import', 'images')
|
||||
const IMAGES = fs.readdirSync(PATH_TO_IMAGE_IMPORT)
|
||||
|
||||
async function import_images() {
|
||||
|
||||
for (const image_file_name of IMAGES) {
|
||||
const img_buffer= await fsPromises.readFile(`${PATH_TO_IMAGE_IMPORT}/${image_file_name}`)
|
||||
const metadata = await sharp(img_buffer).metadata()
|
||||
const height = metadata.height || 10
|
||||
const width = metadata.width || 10
|
||||
if(height*width<921600){
|
||||
console.log(`${image_file_name} is low_res. Skipping.`)
|
||||
}
|
||||
await image_ops.import_image(img_buffer)
|
||||
const img_path = `${PATH_TO_IMAGE_IMPORT}/${image_file_name}`
|
||||
const img_buffer = await fsPromises.readFile(img_path)
|
||||
const img_id = myArgs["use_filename_id"]? parseInt(path.parse(img_path).name) : -1
|
||||
if (isNaN(img_id)) {
|
||||
console.log(`${path.parse(img_path).name} is not a number`)
|
||||
break
|
||||
}
|
||||
const img_exists = await db_ops.image_ops.check_if_image_exists_by_id(img_id)
|
||||
if (img_exists){
|
||||
console.log(`id: ${img_id} is already in db`)
|
||||
break
|
||||
}
|
||||
const img_data = await image_ops.import_image(img_buffer, [], "", false, img_id)
|
||||
console.log(img_data)
|
||||
// fsPromises.unlink(img_path)
|
||||
}
|
||||
process.exit()
|
||||
}
|
||||
|
|
|
@ -3,6 +3,12 @@ import path from 'path'
|
|||
import image_ops from "../helpers/image_ops"
|
||||
import config from "../../config/config"
|
||||
import db_ops from "../helpers/db_ops"
|
||||
const myArgs:any = {}
|
||||
for (const arg of process.argv.slice(2)){
|
||||
if(arg === "--use_filename_id"){
|
||||
myArgs["use_filename_id"]=true
|
||||
}
|
||||
}
|
||||
|
||||
const fsPromises = fs.promises;
|
||||
const PATH_TO_IMAGE_IMPORT = path.join(config.root_path, 'import', 'images')
|
||||
|
@ -11,7 +17,7 @@ async function import_images() {
|
|||
for (const image_file_name of IMAGES) {
|
||||
const img_path = `${PATH_TO_IMAGE_IMPORT}/${image_file_name}`
|
||||
const img_buffer = await fsPromises.readFile(img_path)
|
||||
const img_id = parseInt(path.parse(img_path).name)
|
||||
const img_id = myArgs["use_filename_id"] ? parseInt(path.parse(img_path).name) : -1
|
||||
if (isNaN(img_id)) {
|
||||
console.log(`${path.parse(img_path).name} is not a number`)
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue