Skip to content

Commit

Permalink
Merged dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey18106 committed Oct 22, 2021
2 parents a927cfb + 02d6442 commit 665b717
Show file tree
Hide file tree
Showing 19 changed files with 245 additions and 64 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file.

## [0.1.6 - 2021-10-22]

### Added

- Added Delete file confirmation setting (sidebar settings)

### Fixed

- Fixed MediaDC not working if specified another apps directory in Nextcloud config (apps_paths)
- Fixed MediaDC install fails on Configuration page on some server configs
- Changed function callbacks syntax to support PHP 7.3

## [0.1.5 - 2021-10-12]

### Added
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This app allows to find duplicate or similar 📸📹 photos and videos
Quick start guide and further information in our [Wiki](https://github.com/andrey18106/mediadc/wiki).
]]>
</description>
<version>0.1.5</version>
<version>0.1.6</version>
<licence>agpl</licence>
<author mail="andrey18106x@gmail.com" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
<author mail="bigcat88@icloud.com" homepage="https://github.com/bigcat88">Alexander Piskun</author>
Expand Down
4 changes: 2 additions & 2 deletions js/mediadc-main.js

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions js/mediadc-main.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,28 @@
*
*/

/**
* @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.16.1
Expand Down
2 changes: 1 addition & 1 deletion js/mediadc-main.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions lib/Migration/AppDataInitializationStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCA\MediaDC\AppInfo\Application;
use OCA\MediaDC\Db\Setting;
use OCA\MediaDC\Db\SettingMapper;
use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

Expand All @@ -40,8 +41,12 @@ class AppDataInitializationStep implements IRepairStep {
/** @var SettingMapper */
private $settingMapper;

public function __construct(SettingMapper $settingMapper) {
/** @var IConfig */
private $config;

public function __construct(SettingMapper $settingMapper, IConfig $config) {
$this->settingMapper = $settingMapper;
$this->config = $config;
}

public function getName(): string {
Expand All @@ -50,7 +55,7 @@ public function getName(): string {

public function run(IOutput $output) {
$output->startProgress(1);
$data_file = getcwd() . '/apps//' . Application::APP_ID . "/lib/Migration/data/app_data_Version0001Date20210627153636.json";
$data_file = $this->getCustomAppsDirectory() . Application::APP_ID . "/lib/Migration/data/app_data_Version0001Date20210627153636.json";
$app_data = json_decode(file_get_contents($data_file), true);

if (count($this->settingMapper->findAll()) === 0) {
Expand All @@ -70,4 +75,18 @@ public function run(IOutput $output) {
$output->finishProgress();
}

private function getCustomAppsDirectory() {
$apps_directory = $this->config->getSystemValue('apps_paths');
if ($apps_directory !== "" && is_array($apps_directory) && count($apps_directory) > 0) {
foreach ($apps_directory as $custom_apps_dir) {
$mediadcDir = $custom_apps_dir['path'] . '/' . Application::APP_ID;
if (file_exists($custom_apps_dir['path']) && is_dir($custom_apps_dir['path']) && $custom_apps_dir['writable']
&& file_exists($mediadcDir) && is_dir($mediadcDir)) {
return $custom_apps_dir['path'] . '/';
}
}
}
return getcwd() . '/apps/';
}

}
17 changes: 13 additions & 4 deletions lib/Service/CleanupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*!
*
*/

namespace OCA\MediaDC\Service;
Expand All @@ -50,15 +50,24 @@ public function __construct(IDBConnection $db, ISchemaWrapper $schema)
}

public function dropAppTables() {
$tables = array_filter($this->schema->getTableNames(),
fn($tableName): bool => strpos($tableName, Application::APP_ID) !== false
);
$tables = array_filter($this->schema->getTableNames(), '\OCA\MediaDC\Service\CleanupService::tablesCallback');
foreach ($tables as $table) {
$this->db->dropTable($table);
}
$this->removeAppMigrations();
}

/**
* Callback for tables filter
*
* @param string $tableName
*
* @return bool
*/
static function tablesCallback($tableName) {
return strpos($tableName, Application::APP_ID) !== false;
}

private function removeAppMigrations() {
/** @var IQueryBuilder */
$qb = $this->db->getQueryBuilder();
Expand Down
13 changes: 12 additions & 1 deletion lib/Service/CollectorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function restart($params = []) {
/** @var Setting */
$pyLimitSetting = $this->settingsMapper->findByName('python_limit');
$processesRunning = $this->tasksMapper->findAllRunning();
$taskIdsRunning = array_map(fn($task) => $task->getId(), $processesRunning);
$taskIdsRunning = array_map('\OCA\MediaDC\Service\CollectorService::taskIdCallback', $processesRunning);
/** @var CollectorTask */
$collectorTask = $this->tasksMapper->find($taskId);
$taskData = $this->getTargetDirectoriesData($params['targetDirectoryIds'], intval($params['collectorSettings']['target_mtype']), $excludeList);
Expand Down Expand Up @@ -213,6 +213,17 @@ public function restart($params = []) {
return ['success' => $collectorTask !== null, 'queued' => $queuedTask !== null];
}

/**
* Callback to extract ColectorTask id
*
* @param CollectorTask $task
*
* @return int
*/
static function taskIdCallback($task) {
return $task->getId();
}

/**
* Terminate CollectorTask background Python process
*
Expand Down
54 changes: 48 additions & 6 deletions lib/Service/PythonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*!
*
*/

namespace OCA\MediaDC\Service;
Expand All @@ -32,6 +32,7 @@
use OCA\MediaDC\Db\Setting;
use OCA\MediaDC\Db\SettingMapper;
use OCA\MediaDC\Exception\PythonNotValidException;
use OCP\IConfig;


class PythonService {
Expand All @@ -42,12 +43,16 @@ class PythonService {
/** @var string */
private $pythonCommand;

public function __construct(SettingMapper $settingMapper)
/** @var IConfig */
private $config;

public function __construct(SettingMapper $settingMapper, IConfig $config)
{
$this->config = $config;
/** @var Setting */
$pythonCommand = $settingMapper->findByName('python_command');
$this->pythonCommand = $pythonCommand->getValue();
$this->cwd = getcwd() . '/apps/' . Application::APP_ID . '/lib/Service/python';
$this->cwd = $this->getCustomAppsDirectory() . Application::APP_ID . '/lib/Service/python';
if (!$this->isPythonCompatible()) {
throw new PythonNotValidException("Python version is lower then 3.6.8 or not available");
}
Expand All @@ -69,14 +74,13 @@ public function __construct(SettingMapper $settingMapper)
*/
public function run($scriptName, $scriptParams, $nonBlocking = false, $env = []) {
if (count($scriptParams) > 0) {
$callback = fn(string $k, string $v): string => $v !== '' ? "$k $v " : "$k";
$params = array_map($callback, array_keys($scriptParams), array_values($scriptParams));
$params = array_map('\OCA\MediaDC\Service\PythonService::scriptParamsCallback', array_keys($scriptParams), array_values($scriptParams));
$cmd = $this->pythonCommand . ' ' . $this->cwd . $scriptName . ' ' . join(' ', $params);
} else {
$cmd = $this->pythonCommand . ' ' . $this->cwd . $scriptName;
}
if (count($env) > 0) {
$envVariables = join(' ', array_map(fn(string $k, string $v): string => "$k=\"$v\" ", array_keys($env), array_values($env)));
$envVariables = join(' ', array_map('\OCA\MediaDC\Service\PythonService::scriptEnvsCallback', array_keys($env), array_values($env)));
} else {
$envVariables = '';
}
Expand All @@ -91,6 +95,30 @@ public function run($scriptName, $scriptParams, $nonBlocking = false, $env = [])
}
}

/**
* Callback for concatinating Python script params
*
* @param string $key
* @param string $value
*
* @return string
*/
static function scriptParamsCallback($key, $value) {
return $value !== '' ? "$key $value " : "$key";
}

/**
* Callback for concatinating Python environment variables
*
* @param string $key
* @param string $value
*
* @return string
*/
static function scriptEnvsCallback($key, $value) {
return "$key=\"$value\" ";
}

/**
* @param string @listName
*
Expand Down Expand Up @@ -303,4 +331,18 @@ private function parsePythonOutput($pythonResult) {
];
}

private function getCustomAppsDirectory() {
$apps_directory = $this->config->getSystemValue('apps_paths');
if ($apps_directory !== "" && is_array($apps_directory) && count($apps_directory) > 0) {
foreach ($apps_directory as $custom_apps_dir) {
$mediadcDir = $custom_apps_dir['path'] . '/' . Application::APP_ID;
if (file_exists($custom_apps_dir['path']) && is_dir($custom_apps_dir['path']) && $custom_apps_dir['writable']
&& file_exists($mediadcDir) && is_dir($mediadcDir)) {
return $custom_apps_dir['path'] . '/';
}
}
}
return getcwd() . '/apps/';
}

}
9 changes: 6 additions & 3 deletions lib/Service/python/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ def is_pip_present(only_global: bool = False) -> bool:
if m_groups is None:
return False
pip_version = tuple(map(int, str(m_groups.groups()[0]).split('.')))
if pip_version[0] < 19:
return False
return True
if pip_version[0] > 19:
return True
if len(pip_version) > 1:
if pip_version[1] >= 3:
return True
return False
except (OSError, ValueError, TypeError, subprocess.TimeoutExpired) as exception_info:
log_error(f'pip_version raised {type(exception_info).__name__}: {str(exception_info)}')
return False
Expand Down
1 change: 0 additions & 1 deletion lib/Service/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ pillow_heif
asn1crypto
cryptography
pynacl
hexhamming
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mediadc",
"description": "Collect photo and video duplicates to save your cloud storage",
"version": "0.1.5",
"version": "0.1.6",
"author": "Andrey Borysenko <andrey18106x@gmail.com>",
"contributors": [
"Andrey Borysenko <andrey18106x@gmail.com>",
Expand Down
56 changes: 32 additions & 24 deletions src/components/details/DetailsGroupList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,45 @@ export default {
computed: {
...mapGetters([
'detailsGridSize',
'deleteFileConfirmation',
]),
},
methods: {
deleteGroupFile(file) {
if (confirm(t('mediadc', 'Are you sure, you want delete this file?'))) {
this.$emit('update:updating', true)
axios.delete(generateUrl(`/apps/mediadc/api/v1/tasks/${file.taskId}/files/${file.detailId}/${file.fileid}`))
.then(res => {
if (res.data.success) {
const files = this.files
const fileidIndex = files.findIndex(f => f.fileid === file.fileid)
files.splice(fileidIndex, 1)
this.$emit('update:files', files)
emit('updateTaskInfo')
this.$store.dispatch('setTask', res.data.task).then(() => {
this.$emit('update:updating', false)
})
} else if ('locked' in res.data && res.data.locked) {
showWarning(t('mediadc', 'Wait until file loaded before deleting'))
this.$emit('update:updating', false)
} else {
showError(t('mediadc', 'Some error occured while deleting file'))
if (this.deleteFileConfirmation) {
if (confirm(t('mediadc', 'Are you sure, you want delete this file?'))) {
this._deleteGroupFile(file)
}
} else {
this._deleteGroupFile(file)
}
},
_deleteGroupFile(file) {
this.$emit('update:updating', true)
axios.delete(generateUrl(`/apps/mediadc/api/v1/tasks/${file.taskId}/files/${file.detailId}/${file.fileid}`))
.then(res => {
if (res.data.success) {
const files = this.files
const fileidIndex = files.findIndex(f => f.fileid === file.fileid)
files.splice(fileidIndex, 1)
this.$emit('update:files', files)
emit('updateTaskInfo')
this.$store.dispatch('setTask', res.data.task).then(() => {
this.$emit('update:updating', false)
}
})
.catch(err => {
console.debug(err)
})
} else if ('locked' in res.data && res.data.locked) {
showWarning(t('mediadc', 'Wait until file loaded before deleting'))
this.$emit('update:updating', false)
} else {
showError(t('mediadc', 'Some error occured while deleting file'))
this.$emit('update:updating', false)
})
}
}
})
.catch(err => {
console.debug(err)
showError(t('mediadc', 'Some error occured while deleting file'))
this.$emit('update:updating', false)
})
},
},
}
Expand Down
Loading

0 comments on commit 665b717

Please sign in to comment.