diff --git a/.gitignore b/.gitignore index e3ed788..7e02ba2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules www *.DS_Store data +post.log diff --git a/dist/generate.js b/dist/generate.js index 51faeee..10d0b0f 100644 --- a/dist/generate.js +++ b/dist/generate.js @@ -64,7 +64,8 @@ class Generate { if (el.toLowerCase().indexOf('.jpg') !== -1 || el.toLowerCase().indexOf('.jpeg') !== -1 || el.toLowerCase().indexOf('.tif') !== -1 - || el.toLowerCase().indexOf('.tiff') !== -1) { + || el.toLowerCase().indexOf('.tiff') !== -1 + || el.toLowerCase().indexOf('.png') !== -1) { return true; } return false; diff --git a/dist/generate.js.map b/dist/generate.js.map index 6b23344..7c8c08e 100644 --- a/dist/generate.js.map +++ b/dist/generate.js.map @@ -1 +1 @@ -{"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";;;;;AAAA,yBAAuB;AACvB,+BAAkC;AAElC,0CAA6E;AAC7E,+BAAsC;AACtC,+BAAiC;AACjC,+BAAkC;AAClC,mCAAqC;AACrC,2BAA4B;AAC5B,oDAA4B;AAC5B,uCAA0C;AAC1C,mCAAgC;AAChC,iCAAgC;AAChC,qCAAiC;AACjC,+BAAkC;AAClC,6BAA0B;AAE1B,uCAAoC;AAEpC,MAAM,MAAM,GAAG,IAAA,gBAAS,EAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;AAahD,MAAM,QAAQ;IAYb;QATQ,UAAK,GAAY,IAAA,eAAS,EAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;QAC1D,WAAM,GAAY,IAAA,eAAS,EAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;QAC5D,WAAM,GAAY,IAAA,eAAS,EAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAIjD,QAAG,GAAY,IAAA,WAAM,GAAE,CAAC;QAI/B,IAAI,CAAC,GAAG,GAAG,IAAA,eAAS,EAAC,UAAU,CAAC,CAAC;QACjC,MA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AC;QAE7D,IAAI,CAAC;YACJ,MAAM,IAAA,oBAAS,EAAC,YAAY,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,OAAO,YAAY,CAAC;QACrB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACP,MAAM,GAAG,CAAC;YACX,CAAC;QACF,CAAC;IACF,CAAC;IAEO,aAAa,CAAC,GAAY;QACjC,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;CACD;AAED,IAAI,QAAQ,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/post.js b/dist/post.js index a7dfdf8..639ebc5 100644 --- a/dist/post.js +++ b/dist/post.js @@ -12,6 +12,9 @@ const argparse_1 = require("argparse"); const moment_1 = __importDefault(require("moment")); const db_1 = require("./db"); const env_1 = require("./env"); +const size_1 = require("./size"); +const tmp_1 = require("./tmp"); +const shell_1 = require("./shell"); class Post { constructor() { this.log = (0, log_1.createLog)('post'); @@ -44,12 +47,15 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; const photo = await this.db.getBsky(this.random); const identifier = (0, env_1.envString)('BSKY_USER', null); const password = (0, env_1.envString)('BSKY_PASSWORD', null); + const maxSize = 976560; let text; let post; let imagePath; let imageData; + let imageSize; let blobResponse; let postData; + let usedTmp = false; if (identifier === null || password === null) { this.log.error(`Cannot post without Bluesky username or password`); return; @@ -80,11 +86,39 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; */ this.log.info(text); imagePath = (0, path_1.join)((0, env_1.envString)('WWW', './www'), 'img', `${photo.id}_full.jpg`); + try { + imageSize = await (0, size_1.size)(imagePath); + } + catch (err) { + this.log.error(`Error getting image size`, err); + return; + } + //976.56KB limit + if (imageSize > maxSize) { + this.log.info(`Image size too large: ${imageSize} > ${maxSize}`); + try { + imagePath = await this.imgFix(imagePath); + } + catch (err) { + this.log.error(`Error resizing image with img_fix.sh`, err); + return; + } + usedTmp = true; + try { + imageSize = await (0, size_1.size)(imagePath); + } + catch (err) { + this.log.error(`Error getting resized image size`, err); + return; + } + this.log.info(`Image resized to: ${imageSize}`); + } try { imageData = await (0, promises_1.readFile)(imagePath); } catch (err) { this.log.error(`Error reading image data ${imagePath}`, err); + return; } try { blobResponse = await this.bskyAgent.uploadBlob(imageData, { contentType: 'image/jpeg' }); @@ -118,6 +152,22 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; this.log.error(`Could not confirm that photo ${photo.name} was posted`, err); return; } + if (usedTmp) { + try { + await (0, promises_1.unlink)(imagePath); + } + catch (err) { + this.log.error(`Error removing temp image file ${imagePath}`, err); + return; + } + } + } + async imgFix(imagePath) { + const dest = (0, tmp_1.tmp)('.jpg', 'bsky-upload-'); + const args = ['bash', 'scripts/img_fix.sh', imagePath, dest]; + const shell = new shell_1.Shell(args); + await shell.execute(); + return dest; } } new Post(); diff --git a/dist/post.js.map b/dist/post.js.map index 162b1bd..04d62ec 100644 --- a/dist/post.js.map +++ b/dist/post.js.map @@ -1 +1 @@ -{"version":3,"file":"post.js","sourceRoot":"","sources":["../src/post.ts"],"names":[],"mappings":";;;;;AAAA,yBAAuB;AAEvB,+BAAkC;AAElC,0CAAuC;AACvC,+BAA4B;AAC5B,sCAAyC;AAEzC,uCAA0C;AAC1C,oDAA4B;AAG5B,6BAA0B;AAE1B,+BAAkC;AAElC,MAAM,IAAI;IAMT;QALQ,QAAG,GAAY,IAAA,eAAS,EAAC,MAAM,CAAC,CAAC;QACjC,OAAE,GAAQ,IAAI,OAAE,EAAE,CAAC;QACnB,cAAS,GAAe,IAAI,eAAS,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAA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QACR,CAAC;QAED,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,gCAAgC,KAAK,CAAC,IAAI,aAAa,EAAE,GAAG,CAAC,CAAC;YAC7E,OAAO;QACR,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,CAAC;gBACJ,MAAM,IAAA,iBAAM,EAAC,SAAS,CAAC,CAAC;YACzB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,kCAAkC,SAAS,EAAE,EAAE,GAAG,CAAC,CAAC;gBACnE,OAAO;YACR,CAAC;QACF,CAAC;IAEF,CAAC;IAEO,KAAK,CAAC,MAAM,CAAE,SAAkB;QACvC,MAAM,IAAI,GAAY,IAAA,SAAG,EAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAClD,MAAM,IAAI,GAAc,CAAC,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QACxE,MAAM,KAAK,GAAW,IAAI,aAAK,CAAC,IAAI,CAAC,CAAC;QAEtC,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAEtB,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED,IAAI,IAAI,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/size/index.js b/dist/size/index.js new file mode 100644 index 0000000..50655d0 --- /dev/null +++ b/dist/size/index.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.size = size; +const promises_1 = require("fs/promises"); +async function size(filePath) { + const stats = await (0, promises_1.stat)(filePath); + return stats.size; +} +module.exports = { size }; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/size/index.js.map b/dist/size/index.js.map new file mode 100644 index 0000000..598ee1a --- /dev/null +++ b/dist/size/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/size/index.ts"],"names":[],"mappings":";;AAGA,oBAGC;AAND,0CAAmC;AAG5B,KAAK,UAAU,IAAI,CAAE,QAAiB;IAC5C,MAAM,KAAK,GAAW,MAAM,IAAA,eAAI,EAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,KAAK,CAAC,IAAI,CAAC;AACnB,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,IAAI,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/tmp/index.js b/dist/tmp/index.js new file mode 100644 index 0000000..24d1c01 --- /dev/null +++ b/dist/tmp/index.js @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.tmp = tmp; +const os_1 = require("os"); +const path_1 = require("path"); +const crypto_1 = require("crypto"); +const TMP = (0, os_1.tmpdir)(); +function tmp(ext = '', prefix = '3d-tmp-', fileName = null) { + let path = null; + if (fileName === null) { + fileName = prefix + (0, crypto_1.randomBytes)(32).toString('hex') + ext; + } + path = (0, path_1.join)(TMP, fileName); + return path; +} +module.exports = { tmp }; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/tmp/index.js.map b/dist/tmp/index.js.map new file mode 100644 index 0000000..bb9e3e6 --- /dev/null +++ b/dist/tmp/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tmp/index.ts"],"names":[],"mappings":";;AAMA,kBAOC;AAbD,2BAA4B;AAC5B,+BAA4B;AAC5B,mCAAqC;AAErC,MAAM,GAAG,GAAY,IAAA,WAAM,GAAE,CAAC;AAE9B,SAAgB,GAAG,CAAE,MAAe,EAAE,EAAE,SAAkB,SAAS,EAAE,WAAoB,IAAI;IAC5F,IAAI,IAAI,GAAY,IAAI,CAAC;IACzB,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACvB,QAAQ,GAAG,MAAM,GAAG,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;IAC3D,CAAC;IACD,IAAI,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,GAAG,EAAE,CAAC"} \ No newline at end of file diff --git a/scripts/img.sh b/scripts/img.sh index 2dba981..08121f0 100644 --- a/scripts/img.sh +++ b/scripts/img.sh @@ -28,7 +28,7 @@ for sizeRaw in ${SIZES[@]}; do name=${name%.*} output="${WWW}/img/${ID}_${sizeName}.jpg" img "${1}" "${output}" "${size}" - if [[ -f "${WWW}/img/${ID}_${sizeName}-1.jpg" ]]; then + if [[ -f "${WWW}/img/${ID}_${sizeName}-0.jpg" ]]; then mv "${WWW}/img/${ID}_${sizeName}-0.jpg" "${WWW}/img/${ID}_${sizeName}.jpg" rm "${WWW}/img/${ID}_${sizeName}-1.jpg" fi diff --git a/scripts/img_fix.sh b/scripts/img_fix.sh new file mode 100644 index 0000000..25fcfad --- /dev/null +++ b/scripts/img_fix.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +convert "${1}" -define jpeg:extent=975kb "${2}" \ No newline at end of file diff --git a/src/generate.ts b/src/generate.ts index e01eb18..a045f7b 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -84,7 +84,8 @@ class Generate { if (el.toLowerCase().indexOf('.jpg') !== -1 || el.toLowerCase().indexOf('.jpeg') !== -1 || el.toLowerCase().indexOf('.tif') !== -1 - || el.toLowerCase().indexOf('.tiff') !== -1) { + || el.toLowerCase().indexOf('.tiff') !== -1 + || el.toLowerCase().indexOf('.png') !== -1) { return true; } return false; diff --git a/src/post.ts b/src/post.ts index f1d9e6b..f2cbb4f 100644 --- a/src/post.ts +++ b/src/post.ts @@ -2,7 +2,7 @@ import 'dotenv/config'; import { createLog } from './log'; import type { Logger } from 'winston'; -import { readFile } from 'fs/promises'; +import { readFile, unlink } from 'fs/promises'; import { join } from 'path'; import { BskyAgent } from '@atproto/api'; import type CallOptions from '@atproto/api'; @@ -13,6 +13,9 @@ import type { Moment } from 'moment'; import { DB } from './db'; import type { Photo } from './db'; import { envString } from './env'; +import { size } from './size'; +import { tmp } from './tmp'; +import { Shell } from './shell'; class Post { private log : Logger = createLog('post'); @@ -50,12 +53,15 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; const photo : Photo = await this.db.getBsky(this.random); const identifier : string = envString('BSKY_USER', null); const password : string = envString('BSKY_PASSWORD', null); + const maxSize : number = 976560; let text : string; let post : any; let imagePath : string; let imageData : Buffer; + let imageSize : number; let blobResponse : any; let postData : any; + let usedTmp : boolean = false; if (identifier === null || password === null) { this.log.error(`Cannot post without Bluesky username or password`); @@ -91,10 +97,41 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; imagePath = join(envString('WWW', './www'), 'img', `${photo.id}_full.jpg`); + try { + imageSize = await size(imagePath); + } catch (err) { + this.log.error(`Error getting image size`, err); + return; + } + + //976.56KB limit + if (imageSize > maxSize) { + this.log.info(`Image size too large: ${imageSize} > ${maxSize}`); + + try { + imagePath = await this.imgFix(imagePath); + } catch (err) { + this.log.error(`Error resizing image with img_fix.sh`, err); + return; + } + + usedTmp = true; + + try { + imageSize = await size(imagePath); + } catch (err) { + this.log.error(`Error getting resized image size`, err); + return; + } + + this.log.info(`Image resized to: ${imageSize}`); + } + try { imageData = await readFile(imagePath); } catch (err) { this.log.error(`Error reading image data ${imagePath}`, err); + return; } try { @@ -130,6 +167,25 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; return; } + if (usedTmp) { + try { + await unlink(imagePath); + } catch (err) { + this.log.error(`Error removing temp image file ${imagePath}`, err); + return; + } + } + + } + + private async imgFix (imagePath : string) : Promise { + const dest : string = tmp('.jpg', 'bsky-upload-'); + const args : string[] = ['bash', 'scripts/img_fix.sh', imagePath, dest]; + const shell : Shell = new Shell(args); + + await shell.execute(); + + return dest; } } diff --git a/src/size/index.ts b/src/size/index.ts new file mode 100644 index 0000000..1222958 --- /dev/null +++ b/src/size/index.ts @@ -0,0 +1,9 @@ +import { stat } from 'fs/promises'; +import type { Stats } from 'fs'; + +export async function size (filePath : string) : Promise { + const stats : Stats = await stat(filePath); + return stats.size; +} + +module.exports = { size }; \ No newline at end of file diff --git a/src/tmp/index.ts b/src/tmp/index.ts new file mode 100644 index 0000000..0836514 --- /dev/null +++ b/src/tmp/index.ts @@ -0,0 +1,16 @@ +import { tmpdir } from 'os'; +import { join } from 'path'; +import { randomBytes } from 'crypto'; + +const TMP : string = tmpdir(); + +export function tmp (ext : string = '', prefix : string = '3d-tmp-', fileName : string = null) : string { + let path : string = null; + if (fileName === null) { + fileName = prefix + randomBytes(32).toString('hex') + ext; + } + path = join(TMP, fileName); + return path; +} + +module.exports = { tmp }; \ No newline at end of file