Add file filter to importer (#426)

This commit is contained in:
Carl Reid 2020-06-23 22:31:49 +02:00 committed by GitHub
parent 041b2dfcc1
commit 4607362e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 5 deletions

View File

@ -5,7 +5,7 @@ RUN npm install && npm install -g pkg
RUN pkg -t node14-alpine-x64 . RUN pkg -t node14-alpine-x64 .
FROM alpine FROM alpine
ENV TEEDY_TAG= TEEDY_ADDTAGS=false TEEDY_LANG=eng TEEDY_URL='http://localhost:8080' TEEDY_USERNAME=username TEEDY_PASSWORD=password TEEDY_COPYFOLDER= ENV TEEDY_TAG= TEEDY_ADDTAGS=false TEEDY_LANG=eng TEEDY_URL='http://localhost:8080' TEEDY_USERNAME=username TEEDY_PASSWORD=password TEEDY_COPYFOLDER= TEEDY_FILEFILTER=
RUN apk add --no-cache \ RUN apk add --no-cache \
libc6-compat \ libc6-compat \
libstdc++ libstdc++

View File

@ -37,7 +37,7 @@ docker build -t teedy-import .
docker run --name teedy-import -d -v /path/to/preferencefile:/root/.config/preferences/com.sismics.docs.importer.pref -v /path/to/import/folder:/import teedy-import docker run --name teedy-import -d -v /path/to/preferencefile:/root/.config/preferences/com.sismics.docs.importer.pref -v /path/to/import/folder:/import teedy-import
``` ```
### Environment variables ### Environment variables
Instead of mounting the preferences file, the options can also be set by setting the environment variables `TEEDY_TAG`, `TEEDY_ADDTAGS`, `TEEDY_LANG`, `TEEDY_COPYFOLDER`, `TEEDY_URL`, `TEEDY_USERNAME` and `TEEDY_PASSWORD`. Instead of mounting the preferences file, the options can also be set by setting the environment variables `TEEDY_TAG`, `TEEDY_ADDTAGS`, `TEEDY_LANG`, `TEEDY_COPYFOLDER`, `TEEDY_FILEFILTER`, `TEEDY_URL`, `TEEDY_USERNAME` and `TEEDY_PASSWORD`.
The latter three have to be set for the importer to work. The value of `TEEDY_TAG` has to be set to the UUID of the tag, not the name (The UUID can be found by visiting `baseUrl/api/tag/list` in your browser). The latter three have to be set for the importer to work. The value of `TEEDY_TAG` has to be set to the UUID of the tag, not the name (The UUID can be found by visiting `baseUrl/api/tag/list` in your browser).
Example usage: Example usage:

View File

@ -7,4 +7,5 @@ sed -i "s,env4,$TEEDY_URL,g" $file
sed -i "s/env5/$TEEDY_USERNAME/g" $file sed -i "s/env5/$TEEDY_USERNAME/g" $file
sed -i "s/env6/$TEEDY_PASSWORD/g" $file sed -i "s/env6/$TEEDY_PASSWORD/g" $file
sed -i "s,env7,$TEEDY_COPYFOLDER,g" $file sed -i "s,env7,$TEEDY_COPYFOLDER,g" $file
sed -i "s,env8,$TEEDY_FILEFILTER,g" $file
echo "Environment variables replaced" echo "Environment variables replaced"

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const recursive = require('recursive-readdir'); const recursive = require('recursive-readdir');
const minimatch = require("minimatch");
const ora = require('ora'); const ora = require('ora');
const inquirer = require('inquirer'); const inquirer = require('inquirer');
const preferences = require('preferences'); const preferences = require('preferences');
@ -142,11 +143,30 @@ const askPath = () => {
recursive(answers.path, function (error, files) { recursive(answers.path, function (error, files) {
spinner.succeed(files.length + ' files in this directory'); spinner.succeed(files.length + ' files in this directory');
askFileFilter();
});
});
});
});
};
// Ask for the file filter
const askFileFilter = () => {
console.log('');
inquirer.prompt([
{
type: 'input',
name: 'fileFilter',
message: 'What pattern do you want to use to match files? (eg. *.+(pdf|txt|jpg))',
default: prefs.importer.fileFilter || "*"
}
]).then(answers => {
// Save fileFilter
prefs.importer.fileFilter = answers.fileFilter;
askTag(); askTag();
}); });
});
});
});
}; };
// Ask for the tag to add // Ask for the tag to add
@ -344,6 +364,8 @@ const start = () => {
// Import the files // Import the files
const importFiles = (remove, filesImported) => { const importFiles = (remove, filesImported) => {
recursive(prefs.importer.path, function (error, files) { recursive(prefs.importer.path, function (error, files) {
files = files.filter(minimatch.filter(prefs.importer.fileFilter ?? "*", {matchBase: true}));
if (files.length === 0) { if (files.length === 0) {
filesImported(); filesImported();
return; return;
@ -471,7 +493,8 @@ if (argv.hasOwnProperty('d')) {
'Add tags given #: ' + prefs.importer.addtags + '\n' + 'Add tags given #: ' + prefs.importer.addtags + '\n' +
'Language: ' + prefs.importer.lang + '\n' + 'Language: ' + prefs.importer.lang + '\n' +
'Daemon mode: ' + prefs.importer.daemon + '\n' + 'Daemon mode: ' + prefs.importer.daemon + '\n' +
'Copy folder: ' + prefs.importer.copyFolder 'Copy folder: ' + prefs.importer.copyFolder + '\n' +
'File filter: ' + prefs.importer.fileFilter
); );
start(); start();
} else { } else {

View File

@ -26,6 +26,7 @@
"preferences": "^1.0.2", "preferences": "^1.0.2",
"qs": "^6.9.4", "qs": "^6.9.4",
"recursive-readdir": "^2.2.2", "recursive-readdir": "^2.2.2",
"minimatch": "^3.0.4",
"request": "^2.83.0", "request": "^2.83.0",
"underscore": "^1.8.3" "underscore": "^1.8.3"
} }

View File

@ -8,3 +8,4 @@ importer:
username: 'env5' username: 'env5'
password: 'env6' password: 'env6'
copyFolder: 'env7' copyFolder: 'env7'
fileFilter: 'env8'