Added option to copy a file before it is deleted after being imported (#418)

This commit is contained in:
Gabisonfire 2020-06-07 14:13:04 -04:00 committed by GitHub
parent 612fab2aef
commit e474e7cd75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 6 deletions

View File

@ -6,7 +6,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 ENV TEEDY_TAG= TEEDY_ADDTAGS=false TEEDY_LANG=eng TEEDY_URL='http://localhost:8080' TEEDY_USERNAME=username TEEDY_PASSWORD=password TEEDY_COPYFOLDER=
RUN apk add --no-cache \ RUN apk add --no-cache \
libc6-compat \ libc6-compat \
libstdc++ libstdc++

View File

@ -25,7 +25,7 @@ For the next start, pass the `-d` argument to skip the wizard:
## Daemon mode ## Daemon mode
The daemon mode scan the input directory every 30 seconds for new files. Once a file is found and imported, it is **deleted**. The daemon mode scan the input directory every 30 seconds for new files. Once a file is found and imported, it is **deleted**. You can set a `copyFolder` to copy the file to before deletion.
## Docker ## Docker
@ -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_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_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

@ -6,4 +6,5 @@ sed -i "s/env3/$TEEDY_LANG/g" $file
sed -i "s,env4,$TEEDY_URL,g" $file 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
echo "Environment variables replaced" echo "Environment variables replaced"

View File

@ -241,11 +241,53 @@ const askLang = () => {
]).then(answers => { ]).then(answers => {
// Save tag // Save tag
prefs.importer.lang = answers.lang prefs.importer.lang = answers.lang
askDaemon(); askCopyFolder();
}); });
}); });
}; };
const askCopyFolder = () => {
console.log('');
inquirer.prompt([
{
type: 'input',
name: 'copyFolder',
message: 'Enter a path to copy files before they are deleted or leave empty to disable. The path must end with a \'/\' on MacOS and Linux or with a \'\\\' on Windows. Entering \'undefined\' will disable this again after setting the folder.',
default: prefs.importer.copyFolder
}
]).then(answers => {
// Save path
prefs.importer.copyFolder = answers.copyFolder=='undefined' ? '' : answers.copyFolder;
if (prefs.importer.copyFolder) {
// Test path
const spinner = ora({
text: 'Checking copy folder path',
spinner: 'flips'
}).start();
fs.lstat(answers.copyFolder, (error, stats) => {
if (error || !stats.isDirectory()) {
spinner.fail('Please enter a valid directory path');
askCopyFolder();
return;
}
fs.access(answers.copyFolder, fs.W_OK | fs.R_OK, (error) => {
if (error) {
spinner.fail('This directory is not writable');
askCopyFolder();
return;
}
spinner.succeed('Copy folder set!');
askDaemon();
});
});
}
else {askDaemon();}
});
};
// Ask for daemon mode // Ask for daemon mode
const askDaemon = () => { const askDaemon = () => {
console.log(''); console.log('');
@ -400,7 +442,11 @@ const importFile = (file, remove, resolve) => {
} }
spinner.succeed('Upload successful for ' + file); spinner.succeed('Upload successful for ' + file);
if (remove) { if (remove) {
fs.unlinkSync(file); if (prefs.importer.copyFolder) {
fs.copyFileSync(file, prefs.importer.copyFolder + file.replace(/^.*[\\\/]/, ''));
fs.unlinkSync(file);
}
else {fs.unlinkSync(file);}
} }
resolve(); resolve();
}); });
@ -417,7 +463,8 @@ if (argv.hasOwnProperty('d')) {
'Tag: ' + prefs.importer.tag + '\n' + 'Tag: ' + prefs.importer.tag + '\n' +
'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 'Daemon mode: ' + prefs.importer.daemon + '\n' +
'Copy folder: ' + prefs.importer.copyFolder
); );
start(); start();
} else { } else {

View File

@ -7,3 +7,4 @@ importer:
baseUrl: 'env4' baseUrl: 'env4'
username: 'env5' username: 'env5'
password: 'env6' password: 'env6'
copyFolder: 'env7'