Skip to content

Commit

Permalink
Merge pull request #38 from xoeye/chore/update-metadata-remover
Browse files Browse the repository at this point in the history
Chore/update metadata remover
  • Loading branch information
danielxoi authored Mar 12, 2024
2 parents 9f9dfe8 + ce2e939 commit 80bf6a8
Show file tree
Hide file tree
Showing 25 changed files with 1,375 additions and 4,559 deletions.
17 changes: 0 additions & 17 deletions .babelrc

This file was deleted.

11 changes: 0 additions & 11 deletions .flowconfig

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '14.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: Setup
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '14.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: Set release notes tag
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ lib/
__tests__/images/**/processed
yarn-error.log*
.idea/
dist/
build/
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v2.0.0
- Dependency Updates
- Removes jDataView dependency, DataView is stable now

- Switch to Typescript
- Switch to vite + vitest
- Use Logger instead of console.log

# v1.1.2
- Dependency Updates

Expand Down
110 changes: 0 additions & 110 deletions __tests__/metadata.test.js

This file was deleted.

106 changes: 106 additions & 0 deletions __tests__/metadata.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { removeLocationFromFile } from "./utils/nodeStripContent";
import fs from "fs";
import hasha from "hasha";
import isCorrupted from "is-corrupted-jpeg";
import ffprobe from "ffprobe";
import ffprobeStatic from "ffprobe-static";
import { beforeEach, it, describe, vi, expect } from "vitest";
import { Logger } from "../src/logger";

const MODE_JPG = 0;
const MODE_IMG_NON_JPG = 1;
const MODE_VIDEO = 2;

const baseTestImagePath = "./__tests__/images/";
const PREPROCESSED = "preprocessed/";
const PROCESSED = "processed/";
const PROCESSED_CLEAN = "processed-clean/";

const formatJpg = "jpg/";
const baseJpgPath = baseTestImagePath + formatJpg;
const jpgInFolder = baseJpgPath + PREPROCESSED;
const jpgOutFolder = baseJpgPath + PROCESSED;
const jpgCleanFolder = baseJpgPath + PROCESSED_CLEAN;

const formatPng = "png/";
const basePngPath = baseTestImagePath + formatPng;
const pngInFolder = basePngPath + PREPROCESSED;
const pngOutFolder = basePngPath + PROCESSED;
const pngCleanFolder = basePngPath + PROCESSED_CLEAN;

const formatTif = "tif/";
const baseTifPath = baseTestImagePath + formatTif;
const tifInFolder = baseTifPath + PREPROCESSED;
const tifOutFolder = baseTifPath + PROCESSED;
const tifCleanFolder = baseTifPath + PROCESSED_CLEAN;

const formatMp4 = "mp4/";
const baseMp4Path = baseTestImagePath + formatMp4;
const mp4InFolder = baseMp4Path + PREPROCESSED;
const mp4OutFolder = baseMp4Path + PROCESSED;
const mp4CleanFolder = baseMp4Path + PROCESSED_CLEAN;

const formatMov = "mov/";
const baseMovPath = baseTestImagePath + formatMov;
const movInFolder = baseMovPath + PREPROCESSED;
const movOutFolder = baseMovPath + PROCESSED;
const movCleanFolder = baseMovPath + PROCESSED_CLEAN;

beforeEach(() => {
vi.spyOn(console, "log").mockImplementation(() => {});
});

const itif = (condition: boolean) => (condition ? it : it.skip);

const testFiles = (files: readonly (any[] | [any])[]) =>
describe.each(files)(
"fileName %s",
(fileName, inFolder, outFolder, cleanFolder, mode) => {
const processedFile = outFolder + fileName;
const cleanFile = cleanFolder + fileName;
it("consistently builds", async () => {
await removeLocationFromFile(fileName, inFolder, outFolder);
const cleanFileHash = await hasha.fromFile(cleanFile, {
algorithm: "sha256",
});
const newFileHash = await hasha.fromFile(processedFile, {
algorithm: "sha256",
});
expect(cleanFileHash).toEqual(newFileHash);
});
itif(mode === MODE_JPG)("image is not corrupted - JPG", async () => {
await removeLocationFromFile(fileName, inFolder, outFolder);
const fileIsCorrupted = isCorrupted(processedFile);
expect(fileIsCorrupted).toEqual(false);
});
it("ffprobe corruption check", async (done) => {
await removeLocationFromFile(fileName, inFolder, outFolder);
ffprobe(processedFile, { path: ffprobeStatic.path }, function(
err: any,
info: any
) {
expect(err).to.be.null;
});
});
}
);

const testFormat = (
inFolder: string,
outFolder: string,
cleanFolder: string,
testJpg: number
) => {
const files = fs.readdirSync(inFolder);
const testObjects = files
.filter((file: string) => file !== ".DS_Store")
.map((file: any) => [file, inFolder, outFolder, cleanFolder, testJpg]);

testFiles(testObjects);
};

testFormat(jpgInFolder, jpgOutFolder, jpgCleanFolder, MODE_JPG);
testFormat(pngInFolder, pngOutFolder, pngCleanFolder, MODE_IMG_NON_JPG);
testFormat(tifInFolder, tifOutFolder, tifCleanFolder, MODE_IMG_NON_JPG);
testFormat(movInFolder, movOutFolder, movCleanFolder, MODE_VIDEO);
testFormat(mp4InFolder, mp4OutFolder, mp4CleanFolder, MODE_VIDEO);
43 changes: 0 additions & 43 deletions __tests__/utils/nodeStripContent.js

This file was deleted.

Loading

0 comments on commit 80bf6a8

Please sign in to comment.