Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport#76 to stable22 #93

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
rules: {
// no object literal shorthand syntax
'object-shorthand': ['warn', 'never'],
},
extends: [
'@nextcloud',
],
}
17 changes: 17 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,25 @@ jobs:
uses: actions/checkout@v2
with:
path: ${{ env.APP_NAME }}

- name: Read package.json node and npm engines version
uses: skjnldsv/[email protected]
id: versions
continue-on-error: false
with:
path: ${{ env.APP_NAME }}

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@v2
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"

- name: Run build
run: cd ${{ env.APP_NAME }} && make appstore

- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@ jobs:
uses: actions/checkout@v2
with:
path: ${{ env.APP_NAME }}

- name: Read package.json node and npm engines version
uses: skjnldsv/[email protected]
id: versions
continue-on-error: false
with:
path: ${{ env.APP_NAME }}

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@v2
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"

- name: Run build
run: cd ${{ env.APP_NAME }} && make appstore

- name: Upload app tarball to release
uses: svenstaro/upload-release-action@v2
id: attach_to_release
Expand All @@ -26,6 +43,7 @@ jobs:
asset_name: ${{ env.APP_NAME }}.tar.gz
tag: ${{ github.ref }}
overwrite: true

- name: Upload app to Nextcloud appstore
uses: R0Wi/nextcloud-appstore-push-action@v1
with:
Expand Down
26 changes: 21 additions & 5 deletions .github/workflows/coverage.yml → .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,28 @@ jobs:
./occ app:enable ${{ env.APP_NAME }}
php -S localhost:8080 &

- name: Run tests with coverage tracking
- name: Read package.json node and npm engines version
uses: skjnldsv/[email protected]
id: versions
continue-on-error: false
with:
path: ./apps/${{ env.APP_NAME }}

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@v2
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"

- name: Run PHP and JS tests with coverage tracking and merge results
working-directory: apps/${{ env.APP_NAME }}
run: make coverage
run: make coverage-all

- name: Upload coverage to Codecov
working-directory: ./apps/${{ env.APP_NAME }}
working-directory: ./apps/${{ env.APP_NAME }}/coverage
run: |
wget https://codecov.io/bash -O codecov.sh
bash codecov.sh -t ${{ secrets.CODECOV_TOKEN }} -f coverage.xml -Z
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${{ secrets.CODECOV_TOKEN }} -Z
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ coverage_html
build
.phpunit.result.cache
*.cov
coverage
node_modules
js
coverage
2 changes: 2 additions & 0 deletions .l10nignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# compiled vue templates
js/
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ $config
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->notPath('node_modules')
->in(__DIR__);
return $config;
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
"args": ["-c", "phpunit.integration.xml"],
"cwd": "${workspaceRoot}",
"port": 9003
},
{
"type": "node",
"request": "launch",
"name": "Debug VUE Unit Test (current file)",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"test:debug",
"${file}"
],
"port": 9229
}
]
}
74 changes: 52 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,10 @@ all: build
.PHONY: build
build:
ifneq (,$(wildcard $(CURDIR)/composer.json))
make composer
make composer-build
endif
ifneq (,$(wildcard $(CURDIR)/package.json))
make npm
endif
ifneq (,$(wildcard $(CURDIR)/js/package.json))
make npm
make npm-install && make npm-build
endif

# Installs and updates the composer dependencies. If composer is not installed
Expand All @@ -87,14 +84,30 @@ composer-build:
composer install --no-dev --prefer-dist

# Installs npm dependencies
.PHONY: npm
npm:
.PHONY: npm-install
npm-install: check-npm
ifeq (,$(wildcard $(CURDIR)/package.json))
cd js && $(npm) run build
cd js && npm run dev-install
else
npm run dev-install
endif

# Runs npm build script
.PHONY: npm-build
npm-build: check-npm
ifeq (,$(wildcard $(CURDIR)/package.json))
cd js && npm run build
else
npm run build
endif

# Checks if npm is installed
.PHONY: check-npm
check-npm:
ifeq (,$(npm))
$(error npm is not installed. Please install Node in version mentioned in package.json on your system)
endif

# Removes the appstore build
.PHONY: clean
clean:
Expand All @@ -106,8 +119,7 @@ clean:
distclean: clean
rm -rf vendor
rm -rf node_modules
rm -rf js/vendor
rm -rf js/node_modules
rm -rf js

# Builds the source and appstore package
.PHONY: dist
Expand All @@ -132,10 +144,11 @@ source:
.PHONY: appstore
appstore:
make distclean
make composer-build
make build
rm -rf $(appstore_build_directory)
mkdir -p $(appstore_build_directory)
tar cvzf $(appstore_package_name).tar.gz \
--no-wildcards-match-slash \
--exclude-vcs \
--exclude="../$(app_name)/build" \
--exclude="../$(app_name)/tests" \
Expand All @@ -144,6 +157,8 @@ appstore:
--exclude="../$(app_name)/phpunit*xml" \
--exclude="../$(app_name)/coverage*xml" \
--exclude="../$(app_name)/composer.*" \
--exclude="../$(app_name)/coverage_html" \
--exclude="../$(app_name)/coverage" \
--exclude="../$(app_name)/js/node_modules" \
--exclude="../$(app_name)/js/tests" \
--exclude="../$(app_name)/js/test" \
Expand All @@ -152,12 +167,19 @@ appstore:
--exclude="../$(app_name)/js/bower.json" \
--exclude="../$(app_name)/js/karma.*" \
--exclude="../$(app_name)/js/protractor.*" \
--exclude="../$(app_name)/js/*.map" \
--exclude="../$(app_name)/js/.*" \
--exclude="../$(app_name)/package.json" \
--exclude="../$(app_name)/bower.json" \
--exclude="../$(app_name)/karma.*" \
--exclude="../$(app_name)/protractor\.*" \
--exclude="../$(app_name)/.*" \
--exclude="../$(app_name)/js/.*" \
--exclude="../$(app_name)/src" \
--exclude="../$(app_name)/node_modules" \
--exclude="../$(app_name)/*.js" \
--exclude="../$(app_name)/*.json" \
--exclude="../$(app_name)/*.lock" \
--exclude="../$(app_name)/*.cov" \
../$(app_name) \

.PHONY: test
Expand All @@ -173,23 +195,31 @@ unittest: composer
integrationtest: composer
$(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml

.PHONY: coverage-php
coverage-php:
XDEBUG_MODE=coverage $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.xml --coverage-php coverage/coverage_unittests.cov
XDEBUG_MODE=coverage $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml --coverage-php coverage/coverage_integrationtests.cov
XDEBUG_MODE=coverage $(CURDIR)/vendor/phpunit/phpcov/phpcov merge --clover ./coverage/php-coverage.xml ./coverage

.PHONY: html-coverage
html-coverage: composer
XDEBUG_MODE=coverage $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.xml --coverage-php coverage_unittests.cov
XDEBUG_MODE=coverage $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml --coverage-php coverage_integrationtests.cov
html-coverage: composer coverage-php
XDEBUG_MODE=coverage $(CURDIR)/vendor/phpunit/phpcov/phpcov merge --html coverage_html .

.PHONY: coverage
coverage: composer
XDEBUG_MODE=coverage $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.xml --coverage-php coverage_unittests.cov
XDEBUG_MODE=coverage $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml --coverage-php coverage_integrationtests.cov
XDEBUG_MODE=coverage $(CURDIR)/vendor/phpunit/phpcov/phpcov merge --clover coverage.xml .
# Coverage PHP and JS + merge coverage
.PHONY: coverage-all
coverage-all: composer npm-install coverage-php js-test

.PHONY: lint
lint: composer
lint: composer npm-install
composer run lint
composer run cs:check
npm run lint

.PHONY: lint-fix
lint-fix: composer
lint-fix: composer npm-install
composer run cs:fix
npm run lint:fix

.PHONY: js-test
js-test:
npm run test:unit
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
- [Nextcloud background jobs](#nextcloud-background-jobs)
- [Backend](#backend)
- [Usage](#usage)
- [Trigger OCR if file was created or updated](#trigger-ocr-if-file-was-created-or-updated)
- [Trigger OCR on tag assigning](#trigger-ocr-on-tag-assigning)
- [Useful triggers](#useful-triggers)
- [Trigger OCR if file was created or updated](#trigger-ocr-if-file-was-created-or-updated)
- [Trigger OCR on tag assigning](#trigger-ocr-on-tag-assigning)
- [Settings](#settings)
- [Per workflow settings](#per-workflow-settings)
- [Global settings](#global-settings)
- [Testing your configuration](#testing-your-configuration)
- [How it works](#how-it-works)
- [General](#general)
Expand Down Expand Up @@ -71,7 +75,9 @@ You can configure the OCR processing via Nextcloud's workflow engine. Therefore
<img width="50%" src="doc/img/usage_1.jpg" alt="Usage setup">
</p>

### Trigger OCR if file was created or updated
### Useful triggers

#### Trigger OCR if file was created or updated

If you want a newly uploaded file to be processed via OCR or if you want to process a file which was updated, use the **When**-conditions `File created` or `File updated` or both.

Expand All @@ -83,7 +89,7 @@ A typical setup for processing incoming PDF-files and adding a text-layer to the

> :warning: Please ensure to use the `File MIME type` &#8594; **`is`** &#8594; `PDF documents` operator, otherwise you might not be able to save the workflow like discussed [here](https://github.com/R0Wi/workflow_ocr/issues/41).

### Trigger OCR on tag assigning
#### Trigger OCR on tag assigning

If you have existing files which you want to process after they have been created, or if you want to filter manually which files are processed, you can use the `Tag assigned` event to trigger the OCR process if a user adds a specific tag to a file. Such a setup might look like this:

Expand All @@ -100,6 +106,36 @@ After that you should be able to add a file to the OCR processing queue by assig
<img width="50%" src="doc/img/assign_tag_2.png" alt="Tag assign frontend 2">
</p>

### Settings

#### Per workflow settings
Anyone who can create new workflows (admin or regular user) can configure settings for the OCR processing for a specific workflow. These settings are only applied to the specific workflow and do not affect other workflows.

<p align="center">
<img width="75%" src="doc/img/per_workflow_settings.png" alt="Per workflow settings">
</p>

Currently the following settings are available per workflow:

Name | Description
--- | ---
Languages | The languages to be used for OCR processing. The languages can be choosen from a dropdown list. For PDF files this setting corresponds to the `-l` parameter of `ocrmypdf`. **Please note** that you'll have to install the appropriate languages like described in the [`ocrmypdf` documentation](https://ocrmypdf.readthedocs.io/en/latest/languages.html).
Remove background | If the switch is set, the OCR processor will try to remove the background of the document before processing and instead set a white background. For PDF files this setting corresponds to the [`--remove-background`](https://ocrmypdf.readthedocs.io/en/latest/cookbook.html?highlight=remove-background#image-processing) parameter of `ocrmypdf`. **Please note** that without setting this option, the [`--redo-ocr`](https://ocrmypdf.readthedocs.io/en/latest/errors.html?highlight=redo-ocr#page-already-has-text) option will be set, which is **not** compatible to the mentioned `--remove-background`-parameter. So if you set this switch to "on", make sure your PDF documents do not already contain text, otherwise you might find errors in your NC logs and OCR is not possible.

#### Global settings
As a Nextcloud administrator you're able to configure global settings which apply to all configured OCR-workflows on the current system.
Go to `Settings` &#8594; `Flow` and scroll down to `Workflow OCR`:

<p align="center">
<img width="75%" src="doc/img/global_settings.png" alt="Global settings">
</p>

Currently the following settings can be applied globally:

Name | Description
-----|------------
Processor cores | Defines the number of processor cores to use for OCR processing. When the input is a PDF file, this corresponds to the [`ocrmypdf` CPU limit](https://ocrmypdf.readthedocs.io/en/latest/pdfsecurity.html?highlight=%22-j%22#limiting-cpu-usage). This setting can be especially useful if you have a small backend system which has only limited power.

### Testing your configuration

To **test** if your file gets processed properly you can do the following steps:
Expand All @@ -124,6 +160,7 @@ For processing PDF files, the external command line tool [`OCRmyPDF`](https://gi
### Dev setup
Tools and packages you need for development:
* `make`
* `node` and `npm`
* [`composer`](https://getcomposer.org/download/) (Will be automatically installed when running `make build`)
* Properly setup `php`-environment
* Webserver (like [`Apache`](https://httpd.apache.org/))
Expand Down Expand Up @@ -279,7 +316,7 @@ public static function registerOcrProcessors(IRegistrationContext $context) : vo
}
```

That's all. If you now create a new workflow based on your added mimetype, your implementation should be triggered by the app. The return value of `ocrFile(string $fileContent)` will be interpreted as the file content of the scanned file. This one is used to create a new file version in Nextcloud.
That's all. If you now create a new workflow based on your added mimetype, your implementation should be triggered by the app. The return value of `ocrFile(string $fileContent, WorkflowSettings $settings, GlobalSettings $globalSettings)` will be interpreted as the file content of the scanned file. This one is used to create a new file version in Nextcloud.

## Limitations
* **Currently only pdf documents (`application/pdf`) can be used as input.** Other mimetypes are currently ignored but might be added in the future.
Expand All @@ -301,4 +338,5 @@ That's all. If you now create a new workflow based on your added mimetype, your
|---|---|---|
| OCRmyPDF (commandline) | >= 9.6.0 | https://github.com/jbarlow83/OCRmyPDF On Debian, you might need to manually install a more recent version as described in https://ocrmypdf.readthedocs.io/en/latest/installation.html#ubuntu-18-04-lts; see https://github.com/R0Wi/workflow_ocr/issues/46 |
| php-shellcommand | >= 1.6 | https://github.com/mikehaertl/php-shellcommand |
| chain | >= 0.9.0 | https://packagist.org/packages/cocur/chain |
| PHPUnit | >= 8.0 | https://phpunit.de/ |
Loading