From 9f850fc5119a0548cae752f6280b5d8784291062 Mon Sep 17 00:00:00 2001 From: Vincent Rubinetti Date: Fri, 7 Jun 2024 11:14:36 -0400 Subject: [PATCH] fix --- .github/check.js | 38 +++++++++++++++++------------------- .github/clean.js | 23 ++++++++++++++++------ .github/util.js | 7 ------- .github/workflows/check.yaml | 12 +++++++++++- .github/workflows/clean.yaml | 12 +++++++++++- README.md | 3 +-- 6 files changed, 58 insertions(+), 37 deletions(-) delete mode 100644 .github/util.js diff --git a/.github/check.js b/.github/check.js index d7620ab..e8471d6 100644 --- a/.github/check.js +++ b/.github/check.js @@ -1,15 +1,16 @@ -const { readdirSync, readFileSync, existsSync } = require("fs"); -const { exec } = require("./util"); +import { readdirSync, readFileSync, existsSync } from "fs"; +import { ExifTool } from "exiftool-vendored"; -// install exiftool -exec("sudo apt install exiftool"); +const exiftool = new ExifTool({ taskTimeoutMillis: 5000 }); -checkDimensions("./images", 600, 600); -checkDimensions("./print", 1200, 1200); +await checkDimensions("./images", 600, 600); +await checkDimensions("./print", 1200, 1200); checkList("software.json"); checkList("groups.json"); +exiftool.end(); + // check list of entries in json file function checkList(filename) { console.info(`Checking list "${filename}"`); @@ -40,29 +41,27 @@ function checkList(filename) { } } -// check dimensions of images in directory -function checkDimensions( - directory, +// check dimensions of images in folder +async function checkDimensions( + folder, expectedWidth, expectedHeight, extension = "png" ) { - // get all images matching extension in directory - const paths = readdirSync(directory) + // get all images matching extension in folder + const paths = readdirSync(folder) .filter((filename) => filename.endsWith(`.${extension}`)) - .map((filename) => `${directory}/${filename}`); + .map((filename) => `${folder}/${filename}`); for (const [index, path] of Object.entries(paths)) { console.info(`Checking "${path}" (${+index + 1} of ${paths.length})`); // extract dimensions - const [width, height] = exec( - `exiftool -s3 -ImageWidth -ImageHeight ${path}`, - false - ) - .split(/\s/) - .filter(Boolean) - .map(Number); + const { + ImageWidth: width, + ImageHeight: height, + ColorType: colorspace, + } = await exiftool.read(path); // check dimensions if (width !== expectedWidth || height !== expectedHeight) @@ -71,7 +70,6 @@ function checkDimensions( ); // check color space - const colorspace = exec(`exiftool -s3 -ColorType ${path}`, false); if (!colorspace.toLowerCase().includes("rgb")) throw Error(`Colorspace "${colorspace}", expected RGB`); } diff --git a/.github/clean.js b/.github/clean.js index 7bf7b93..80c4b4f 100644 --- a/.github/clean.js +++ b/.github/clean.js @@ -1,8 +1,19 @@ -const { exec } = require("./util"); +import { readdirSync, unlinkSync } from "fs"; +import { ExifTool } from "exiftool-vendored"; -// install exiftool -exec("sudo apt install exiftool"); +const exiftool = new ExifTool({ taskTimeoutMillis: 5000 }); -// strip all metadata to ensure consistency -exec("exiftool -All= -r -overwrite_original ./images"); -exec("exiftool -All= -r -overwrite_original ./print"); +await stripMeta("./images"); +await stripMeta("./print"); + +exiftool.end(); + +// strip all metadata from all images in folder to ensure consistency +async function stripMeta(folder) { + await exiftool.deleteAllTags(folder, ["-recurse", "-overwrite_original"]); + // delete originals + readdirSync(folder) + .filter((filename) => filename.endsWith("_original")) + .map((filename) => `${folder}/${filename}`) + .forEach(unlinkSync); +} diff --git a/.github/util.js b/.github/util.js deleted file mode 100644 index e6a3674..0000000 --- a/.github/util.js +++ /dev/null @@ -1,7 +0,0 @@ -const { execSync } = require("child_process"); - -export function exec(command, print = true) { - const result = execSync(command).toString().trim(); - if (print) console.log(result); - return result; -} diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 0b3b877..84c264a 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -14,5 +14,15 @@ jobs: with: ref: ${{ github.head_ref }} + - name: Set up Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Install packages + run: | + bun add exiftool-vendored@26 + bun install + - name: Run script - run: node ./.github/check.js + run: bun ./.github/check.js diff --git a/.github/workflows/clean.yaml b/.github/workflows/clean.yaml index 9b24eea..db93d18 100644 --- a/.github/workflows/clean.yaml +++ b/.github/workflows/clean.yaml @@ -12,8 +12,18 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Set up Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Install packages + run: | + bun add exiftool-vendored@26 + bun install + - name: Run script - run: node ./.github/clean.js + run: bun ./.github/clean.js - name: Commit changed files uses: stefanzweifel/git-auto-commit-action@v5 diff --git a/README.md b/README.md index 6fcb760..cf73071 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ The order of entries on the website is shuffled randomly on each page visit to n 1. [Fork this repo](https://github.dev/CU-DBMI/wall-of-software) and make one or more changes. 1. Open a pull request (PR). - Check "Allow edits by maintainers". Name the PR the canonical name(s) of the software/group(s) you're changing, using commas for multiple, e.g. "Word Lapse, Preprint Similarity Search". 1. Shortly after opening the PR, a link will appear that shows a preview of the website with your changes (if any). Add `?print` at the end of the url to view the print versions of images instead. @@ -59,7 +58,7 @@ To remove/change entries, edit the above files as needed. ## Images -Images should meet the following standards: +Images must meet the following standards: - Unique, visually appealing logo or other graphical representation of your software/group. - Not up-scaled, stretched, or otherwise blurry/noisy/distorted/etc.