UNPKG

image-classifier-ts

Version:

Command line tool to auto-classify images, renaming them with appropriate labels. Uses Node and Google Vision API.

45 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileUtils = void 0; var fs = require("fs"); var path = require("path"); var ExifUtils_1 = require("./ExifUtils"); var SimpleDate_1 = require("./SimpleDate"); var FileUtils; (function (FileUtils) { function ensureDirExists(dirPath) { if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath); } } FileUtils.ensureDirExists = ensureDirExists; function ensureSubDirsExist(outDir, subDirPath) { var subDirs = subDirPath.split("/"); ensureDirExists(outDir); var dirPath = outDir; subDirs.forEach(function (s) { dirPath = path.join(dirPath, s); ensureDirExists(dirPath); }); } FileUtils.ensureSubDirsExist = ensureSubDirsExist; function getModificationDateOfFile(filepath, outputter) { // use date from exif if available (is less likely to change than the file stamp) var exifTags = ExifUtils_1.ExifUtils.readFile(filepath, outputter); if (exifTags) { var exifDate = exifTags.getDateStamp(); if (exifDate) { return exifDate; } } // fallback: var fileCreatedDate = fs.statSync(filepath).mtime; return SimpleDate_1.SimpleDate.fromDate(fileCreatedDate); } FileUtils.getModificationDateOfFile = getModificationDateOfFile; function getModificationYearOfFile(filePath, outputter) { return getModificationDateOfFile(filePath, outputter).year.toString(); } FileUtils.getModificationYearOfFile = getModificationYearOfFile; })(FileUtils = exports.FileUtils || (exports.FileUtils = {})); //# sourceMappingURL=FileUtils.js.map