2
0
mirror of https://github.com/thumbsup/thumbsup synced 2024-11-03 15:40:14 +00:00

Fix #33: new --cleanup option to remove unused generated thumbnails/media

This commit is contained in:
Romain 2017-03-09 17:28:02 +11:00
parent 9dcebe6280
commit fb77791c80
5 changed files with 39 additions and 0 deletions

View File

@ -64,6 +64,7 @@ Output options:
--large-size Pixel height of the fullscreen photos [number] [default: 1000]
--original-photos Copy and allow download of full-size photos [boolean] [default: false]
--original-videos Copy and allow download of full-size videos [boolean] [default: false]
--cleanup Remove any output file that's no longer needed [boolean] [default: false]
Album options:
--albums-from How to group media into albums [choices: "folders", "date"] [default: "folders"]

View File

@ -58,6 +58,12 @@ var opts = yargs
type: 'boolean',
'default': false
},
'cleanup': {
group: 'Output options:',
description: 'Remove any output file that\'s no longer needed',
type: 'boolean',
'default': false
},
// ------------------------------------
// Album options
@ -159,6 +165,7 @@ var opts = yargs
index.build({
input: path.resolve(opts['input']),
output: path.resolve(opts['output']),
cleanup: opts['cleanup'],
title: opts['title'],
thumbSize: opts['thumb-size'],
largeSize: opts['large-size'],

View File

@ -30,6 +30,7 @@
"debug": "^2.6.1",
"exiftool-json-db": "~1.0.0",
"fs-extra": "^2.0.0",
"fs-readdir-recursive": "^1.0.0",
"gm": "^1.23.0",
"handlebars": "~4.0.5",
"less": "^2.7.1",

View File

@ -2,6 +2,7 @@ const async = require('async')
const fs = require('fs-extra')
const path = require('path')
const os = require('os')
const cleanup = require('./output-media/cleanup')
const database = require('./input/database')
const progress = require('./utils/progress')
const File = require('./input/file')
@ -43,6 +44,11 @@ exports.build = function (opts) {
parallel(videos, bar, callback)
},
function removeOldOutput (callback) {
if (!opts.cleanup) return callback()
cleanup.run(fileCollection, opts.output, callback)
},
function createAlbums (callback) {
const bar = progress.create('Creating albums')
const albumMapper = mapper.create(opts)

View File

@ -0,0 +1,24 @@
const _ = require('lodash')
const fs = require('fs')
const path = require('path')
const readdir = require('fs-readdir-recursive')
const progress = require('../utils/progress')
exports.run = function (fileCollection, outputRoot, callback) {
const mediaRoot = path.join(outputRoot, 'media')
const diskFiles = readdir(mediaRoot).map(f => path.join(mediaRoot, f))
const requiredFiles = []
fileCollection.forEach(f => {
Object.keys(f.output).forEach(out => {
var dest = path.join(outputRoot, f.output[out].path)
requiredFiles.push(dest)
})
})
const useless = _.difference(diskFiles, requiredFiles)
if (useless.length) {
const bar = progress.create('Cleaning up', useless.length)
useless.forEach(f => fs.unlinkSync(f))
bar.tick(useless.length)
}
callback()
}