initial commit

This commit is contained in:
Kegan Myers 2017-04-15 23:49:36 -05:00
commit f7540ddac8
4 changed files with 93 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
images
node_modules

49
move-media.js Normal file
View File

@ -0,0 +1,49 @@
const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs-extra');
const path = require('path');
const _ = require('lodash');
if (argv._.length !== 2) {
console.log('Please provide a source (mastodon base path) and a destiantion (to be uploaded with gsutil)');
process.exit(1);
}
const basePath = path.resolve(process.cwd(), argv._[0], 'public/system/media_attachments/files');
const targetPath = path.resolve(process.cwd(), argv._[1], 'images/media_attachments');
const targetSuffix = 'files';
const sizes = ['original', 'small'];
function handleDir(...prefix) {
const contents = fs.readdirSync(path.join(basePath, ...prefix));
if (contents.length === 2 && _.difference(contents, sizes).length === 0) {
return { prefix };
}
return _.flatten(contents.map((content) => handleDir(...prefix, content)));
}
const action = !argv['dry-run'] ? (sourceFile, targetDir, targetFile) => {
fs.mkdirpSync(targetDir);
fs.copySync(sourceFile, targetFile);
} : (sourceFile, targetDir, targetFile) => {
console.log(`mkdirp ${targetDir}`);
console.log(`cp ${sourceFile} -> ${targetFile}`);
}
const allFiles = handleDir().map((info) => (Object.assign(
{ number: parseInt(info.prefix.join(''), 10).toString() },
info,
sizes
.map((name) => ({ [name]: fs.readdirSync(path.join(basePath, ...info.prefix, name))[0] }))
.reduce((a, b) => Object.assign({}, a, b))
))).forEach((info) => {
sizes.forEach((size) => {
const sourceFile = path.join(basePath, ...info.prefix, size, info[size]);
const targetDir = path.join(targetPath, info.number, targetSuffix, size);
const targetFile = path.join(targetDir, 'img_');
action(sourceFile, targetDir, targetFile);
})
});

14
package.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "media-mover",
"version": "0.0.1",
"description": "Upload things to google cloud storage",
"main": "index.js",
"repository": "git@github.com:nrdli/media-mover.git",
"author": "Kegan Myers <kegan@keganmyers.com>",
"license": "Unlicense",
"dependencies": {
"fs-extra": "^2.1.2",
"lodash": "^4.17.4",
"minimist": "^1.2.0"
}
}

28
yarn.lock Normal file
View File

@ -0,0 +1,28 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
fs-extra@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.1.2.tgz#046c70163cef9aad46b0e4a7fa467fb22d71de35"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^2.1.0"
graceful-fs@^4.1.2, graceful-fs@^4.1.6:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
jsonfile@^2.1.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
optionalDependencies:
graceful-fs "^4.1.6"
lodash@^4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"