diff options
author | patrick <patrick@westberliner.net> | 2021-03-13 16:09:39 +0300 |
---|---|---|
committer | patrick <patrick@westberliner.net> | 2021-03-13 16:09:39 +0300 |
commit | 870b016ebb36ae2ced5425a1689fd4c55c56077b (patch) | |
tree | 365f7ada60b6a99747e1a4b23feed1fd16638612 | |
parent | 72ebdeb5fb1843fbae77ef97cb4215e8928365c3 (diff) | |
parent | d39945094f539a4ddcddbff4490349ed372c645d (diff) |
Merge branch 'master' of github-westberliner:westberliner/checksum into typescript
# Conflicts:
# package.json
-rw-r--r-- | .eslintrc.js | 9 | ||||
-rw-r--r-- | Changelog.md | 5 | ||||
-rw-r--r-- | appinfo/info.xml | 2 | ||||
-rw-r--r-- | lib/Controller/ChecksumController.php | 28 | ||||
-rw-r--r-- | package.json | 8 | ||||
-rw-r--r-- | src/main.ts | 2 | ||||
-rw-r--r-- | src/model/Algorithms.ts | 12 | ||||
-rw-r--r-- | src/shims-checksum.d.ts | 4 | ||||
-rw-r--r-- | src/views/ChecksumTab.vue | 19 | ||||
-rw-r--r-- | src/views/ChecksumTab20.vue | 19 | ||||
-rw-r--r-- | tsconfig.json | 5 | ||||
-rw-r--r-- | webpack.common.js | 3 |
12 files changed, 62 insertions, 54 deletions
diff --git a/.eslintrc.js b/.eslintrc.js index 36e7509..aeb49d4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,12 @@ module.exports = { extends: [ '@nextcloud' - ] + ], + settings: { + 'import/resolver': { + 'node': { + 'extensions': ['.js', '.ts', 'vue'] + } + } + } }; diff --git a/Changelog.md b/Changelog.md index 1ed159d..2d49899 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,11 @@ Changelog ========= +**1.1.2** +- Fixes wrong label for sha512 checksum. (thx to @st3iny) +- Refactor checksum controller to appropriate nc folder class. (thx to @st3iny) +- Centralize algorithms in javascript. + **1.1.1** - NC 20|21: Fixes issue on checksum files in folders not working. - NC 21: Fixed issue on fileinfo change not resetting view. diff --git a/appinfo/info.xml b/appinfo/info.xml index a4de3cc..6df22e4 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -12,7 +12,7 @@ Select a algorithm and it will try to generate a hash. If you want an other algorithm, just click on the reload button. </description> - <version>1.1.1</version> + <version>1.1.2</version> <licence>agpl</licence> <author>westberliner</author> <types> diff --git a/lib/Controller/ChecksumController.php b/lib/Controller/ChecksumController.php index ec69913..0f7d78d 100644 --- a/lib/Controller/ChecksumController.php +++ b/lib/Controller/ChecksumController.php @@ -4,9 +4,13 @@ declare(strict_types=1); namespace OCA\Checksum\Controller; +use OC\User\NoUserException; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; -use OCP\Files\Mount\IMountManager; +use OCP\Files\FileInfo; +use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OCP\IL10N; use OCP\IRequest; use OCP\IUserSession; @@ -20,9 +24,9 @@ class ChecksumController extends Controller { private $language; /** - * @var IMountManager + * @var IRootFolder */ - private $mountManager; + private $rootFolder; /** * @var IUserSession @@ -35,20 +39,20 @@ class ChecksumController extends Controller { * @param string $appName * @param IRequest $request * @param IFactory $languageFactory - * @param IMountManager $mountManager + * @param IRootFolder $rootFolder * @param IUserSession $userSession */ public function __construct( string $appName, IRequest $request, IFactory $languageFactory, - IMountManager $mountManager, + IRootFolder $rootFolder, IUserSession $userSession ) { parent::__construct($appName, $request); $this->language = $languageFactory->get('checksum'); - $this->mountManager = $mountManager; + $this->rootFolder = $rootFolder; $this->userSession = $userSession; } @@ -97,18 +101,18 @@ class ChecksumController extends Controller { return null; } - $absPath = $user->getUID() . '/files/' . $source; - $mount = $this->mountManager->find($absPath); - if (!$mount) { + try { + $home = $this->rootFolder->getUserFolder($user->getUID()); + $node = $home->get($source); + } catch (NotPermittedException | NoUserException | NotFoundException $e) { return null; } - $internalPath = $mount->getInternalPath($absPath); - $file = $mount->getStorage()->fopen($internalPath, 'rb'); - if (!$file) { + if ($node->getType() !== FileInfo::TYPE_FILE) { return null; } + $file = $node->fopen('rb'); $hash = hash_init($type); hash_update_stream($hash, $file); fclose($file); diff --git a/package.json b/package.json index a572132..d78c13e 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "checksum", - "version": "1.1.1", - "private": true, "description": "Checksum app for Nextcloud", + "version": "1.1.2", "author": "westberliner", + "license": "agpl", + "private": true, "scripts": { "build": "NODE_ENV=production webpack --config webpack.prod.js", "deploy": "rm -rf js/* && yarn install && yarn build && cd .. && tar -cvzf checksum.tar.gz -X checksum/.exclude checksum && cd checksum", @@ -55,6 +56,5 @@ }, "browserslist": [ "extends @nextcloud/browserslist-config" - ], - "license": "agpl" + ] } diff --git a/src/main.ts b/src/main.ts index 8760961..0de694c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -49,8 +49,6 @@ window.addEventListener('DOMContentLoaded', function() { icon: 'icon-category-auth', mount(el: HTMLElement, fileInfo: Checksum.FileInfo, context: any) { - console.log('context') - console.log(context) if (tabInstance) { tabInstance.$destroy() } diff --git a/src/model/Algorithms.ts b/src/model/Algorithms.ts new file mode 100644 index 0000000..fabd597 --- /dev/null +++ b/src/model/Algorithms.ts @@ -0,0 +1,12 @@ +import { translate as t } from '@nextcloud/l10n' + +export default [ + { id: '', label: t('checksum', 'Choose Algorithm') }, + { id: 'md5', label: 'MD5' }, + { id: 'sha1', label: 'SHA1' }, + { id: 'sha256', label: 'SHA256' }, + { id: 'sha384', label: 'SHA384' }, + { id: 'sha512', label: 'SHA512' }, + { id: 'crc32', label: 'CRC32' }, + { id: 'crc32b', label: 'CRC32b' }, +] diff --git a/src/shims-checksum.d.ts b/src/shims-checksum.d.ts index ac2683a..211eb3a 100644 --- a/src/shims-checksum.d.ts +++ b/src/shims-checksum.d.ts @@ -21,5 +21,9 @@ declare global { interface IntrinsicElements { [elem: string]: any } + interface HashType { + id: string; + label: string; + } } } diff --git a/src/views/ChecksumTab.vue b/src/views/ChecksumTab.vue index 3465efd..42de059 100644 --- a/src/views/ChecksumTab.vue +++ b/src/views/ChecksumTab.vue @@ -19,7 +19,6 @@ - along with this program. If not, see <http://www.gnu.org/licenses/>. - --> - <template> <div> <!-- checksum content --> @@ -41,17 +40,7 @@ import { generateUrl } from '@nextcloud/router' import axios from '@nextcloud/axios' import Multiselect from '@nextcloud/vue/dist/Components/Multiselect' - -const algorithms = [ - { id: '', label: t('checksum', 'Choose Algorithm') }, - { id: 'md5', label: 'MD5' }, - { id: 'sha1', label: 'SHA1' }, - { id: 'sha256', label: 'SHA256' }, - { id: 'sha384', label: 'SHA384' }, - { id: 'sha512', label: 'SHA1' }, - { id: 'crc32', label: 'CRC32' }, - { id: 'crc32b', label: 'CRC32b' }, -] +import Algorithms from '../model/Algorithms.ts' export default { name: 'ChecksumTab', @@ -65,8 +54,8 @@ export default { data() { return { loading: false, - algorithm: algorithms[0], - algorithms, + algorithm: Algorithms[0], + algorithms: Algorithms, hash: '', } }, @@ -128,7 +117,7 @@ export default { */ resetState() { this.loading = false - this.algorithm = algorithms[0] + this.algorithm = this.algorithms[0] this.hash = '' }, }, diff --git a/src/views/ChecksumTab20.vue b/src/views/ChecksumTab20.vue index bbd972b..6a8b405 100644 --- a/src/views/ChecksumTab20.vue +++ b/src/views/ChecksumTab20.vue @@ -19,7 +19,6 @@ - along with this program. If not, see <http://www.gnu.org/licenses/>. - --> - <template> <Tab :id="id" :icon="icon" @@ -44,17 +43,7 @@ import { generateUrl } from '@nextcloud/router' import axios from '@nextcloud/axios' import Multiselect from '@nextcloud/vue/dist/Components/Multiselect' import Tab from '@nextcloud/vue/dist/Components/AppSidebarTab' - -const algorithms = [ - { id: '', label: t('checksum', 'Choose Algorithm') }, - { id: 'md5', label: 'MD5' }, - { id: 'sha1', label: 'SHA1' }, - { id: 'sha256', label: 'SHA256' }, - { id: 'sha384', label: 'SHA384' }, - { id: 'sha512', label: 'SHA1' }, - { id: 'crc32', label: 'CRC32' }, - { id: 'crc32b', label: 'CRC32b' }, -] +import Algorithms from '../model/Algorithms.ts' export default { name: 'ChecksumTab20', @@ -80,8 +69,8 @@ export default { icon: (this.fileInfo.type === 'file') ? 'icon-category-auth' : '', name: t('checksum', 'Checksum'), loading: false, - algorithm: algorithms[0], - algorithms, + algorithm: Algorithms[0], + algorithms: Algorithms, hash: '', } }, @@ -153,7 +142,7 @@ export default { */ resetState() { this.loading = false - this.algorithm = algorithms[0] + this.algorithm = this.Algorithms[0] this.hash = '' }, }, diff --git a/tsconfig.json b/tsconfig.json index 8c93ef5..428fa50 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,10 +29,7 @@ }, "include": [ "src/**/*.ts", - "src/**/*.tsx", - "src/**/*.vue", - "tests/**/*.ts", - "tests/**/*.tsx" + "src/**/*.vue" ], "exclude": [ "node_modules" diff --git a/webpack.common.js b/webpack.common.js index 2d35679..c2c79ba 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -10,6 +10,9 @@ module.exports = merge(webpackConfig, { path: path.resolve(__dirname, 'js'), filename: 'checksum.[name].js', }, + resolve: { + extensions: ['.ts', '.vue', '.js'] + }, module: { rules: [ { |