Coder Social home page Coder Social logo

raudius / files_scripts Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 11.0 3.14 MB

Custom file actions app for Nextcloud

License: GNU Affero General Public License v3.0

PHP 74.94% Makefile 1.19% Vue 13.28% Hack 0.01% TypeScript 4.97% CSS 0.10% Lua 5.31% Gherkin 0.20%

files_scripts's People

Contributors

0xfaul avatar badmanmassive avatar denisbessa avatar feefladder avatar heisian avatar nextcloud-bot avatar rakekniven avatar raudius avatar silopolis avatar valdnet avatar vitstradal avatar zeitee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

files_scripts's Issues

Add option to run scripts in background

  • Add option to run scripts in a background job
  • When the action is triggered, instead of running straight away: add script to a queue
  • Background job should run each minute and run some of the tasks from the queue
  • Run all Flow events in background (?)

Add different input types

Currently its only possible to create input in textboxes. Would be nice to include a way to add different input types

  • File/folder select
    • Would remove the need for the "request target directory" option
  • Checkbox (true/false)
  • Dropdown (multi + single select)

meta_data() doesn't works with folders on external storage

The issue locate in

/var/www/nextcloud/apps/files_scripts/lib/Interpreter/Functions/Files/Meta_Data.php:41

Call of $node->getStorage()->getLocalFile() for folder generate exception InvalidTypeException, and it doesn't catch in your code.

file_move_unsafe is broken

It seems to me the function "file_move_unsafe" was broken in a recent update, probably with the introduction of folder support? From my testing, the function works fine when files are moved within the directory owned by the executing user but not to another user's directory (purpose of the function).

Add functions to edit collaborative Tags

It would be great to have the capability to edit tags on files.

This would allow for a (limited) integration with other flows.

My personal usecase here is to split and merge multiple PDFs and tag the resulting file for further processing with the "Workflow external scripts" to send the result to a printer.

tags_find broken with Nextcloud 25.0.1

I was working my way up to creating a script that would allow users to tag files for ocr-scanning.
And it was working.
But at some point, I could create a new public tag called ocr in the admin-panel, but

tags = tags_find({name = "ocr"})
log(#tags)

started to return 0.

And where I was getting a single tag before (tags_find({id = 5}))
became Nil (The id is identical to the one in the headers of the network traffic when modifying it)

Limit action to certain mimetypes

  • Allow selecting a set of valid Mimetypes for the action
  • Only allow running the action when the selected files all match the Mimetype
    • Only show valid actions in the selection modal

Make file actions optionally available through public shares

Add an option to make file actions available through public shares.

  • Option per file action
  • Create secure controller method so that unauthenticated file actions may only run on shared files for a corresponding share token.
  • Check behavior of file-system functions (since there is no filesystem mounted they might fail)
  • If app is not enabled for a user, their shares should not allow running the file actions
  • Should only be available on shares with write permissions (if possible allow writing to public share itself via the script)

File-picker does not work on directories

As described here:

โš ๏ธ DEPRECATED: Replace usage with user input of type "file-picker".
Hint: set the accepted mimetypes to just httpd/unix-directory to limit file picker to directories.

and here:

Note: to allow a user to pick a folder the httpd/unix-directory mimetype must be added to the filepick options.

one should replace the "Request target folder" mechanism, linked to get_target-folder() with the Filepicker from the "User inputs" mechanism, linked to get_input().

Now to the issue:

  • The Filepicker window opens, I can select folders but it ain't possible to choose the folder. The blue "choose" button stays darkens. When no mime type restriction is given, only files are posible to choos as well, no directories.

QoL: save script on Ctrl-S

It would be nice to be able to save scripts on Ctrl-S. If this is not difficult to implement, I can add it to my existing PR.

file_unlock() not working as expected

Since nextcloud is sometimes having issues regarding dead file locks, I wanted to write a file action to force unlock. I built the following script:

local nodes = get_input_files()

for key, node in ipairs(nodes) 
do
	if(file_unlock(node, false)) 
        then
    	        add_message(node.name .." unlocked", "success")
        else
      	        add_message(node.name .." could not be unlocked", "warning") 
  	end
end

Since video files are locked as soon as you play them, I started a video, closed the player, tried to rename the file. File cannot be renamed (as expected since it is locked). Executed the Unlock file action, got success. Tried to rename the file again. Still impossible. Did I get sth wrong or is it a bug? I'm using experimental interpreter.

Inputs (QoL)

Hey,
here are some QoL ideas that is got while using it.

Ordering Inputs

It's possible to postpone the input options to the bottom but not up or 1 step down/up

Currently, I have to move everything to the bottom after each other to sort it. If a var is renamed, it automatically goes to the bottom and u have to reorder it.

Multiple Choice options

Sorting the options in multiple choice input

Currently u have to delete and recreate the different options to reorder it if for example a new option is added

both might be possible with drag & drop to move/sort things more freely

Optional Label

A optional label for inputs

Currently the inputs just have an placeholder witch isn't visible on input.

Add a new example script: OCR document

Hi! Let me suggest to add a new example to the list of scripts: OCR document.
With it a user may select some PDF document, select languages, and select output file (either to use the same or create a new file (optionally)). The tesseract and installed languages are required.

Will it be possible to do it?

Question for functionality

Hello there!

I'm looking for functionality to send selected filenames to certain email. Is it doable with this plugin? I can manage simple scripting based on documentation.

Thanks!

Additional types of user input

It would be nice to have two additional types: textarea and true multiselect. Textarea is much more convenient for multi-line comments. The current multiselect itself is just a select, there is no multiselect. Is it possible?

Executing Merge PDFs example script leads to errors

Hi! I have set up file actions app, install lua according to the updated readme as of today,
I have added row extension=lua.so both to /etc/php/8.1/apache2/conf.d/@20-lua.ini and /etc/php/8.1/cli/conf.d/@20-lua.ini

image

I do not see either the folder or the resulting file prompt at all if to compare with the screenshot from the app description:
image

Trying to test it with the Merge PDFs example script, which is provided with the app, I am constantly getting error
[string "line"]:8: attempt to call a nil value (global 'get_target_folder')

Ubuntu 22.04
Apache2.4.52
PHP 8.1.2
Nextcloud 26.0.5
qpdf 10.6.3

What may be wrong?

Install from app store only

Hi,

Would it be possible to use the app direct from the app store and only for specific features additional software will be needed.

I have a managed nextcloud where I can install apps, but no option to install additional software.

share handling

Hello,

I haven't found anything in the documentation related to share handling. It would be really useful to be able deal with share the same was we can deal with files and folder: list shares (in a given folder, as a whole?) check if a node is a share, move share, delete share, create_share.

Is that already possible and if not, is that something that could be done sometimes?

Thanks!

Not passing make test

Hi! I have followed the installation manual and found that make test prompts at least 3 errors:

$ make test

Build complete.
Don't forget to run 'make test'.


=====================================================================
PHP         : /usr/bin/php8.1
PHP_SAPI    : cli
PHP_VERSION : 8.1.2-1ubuntu2.14
ZEND_VERSION: 4.1.2
PHP_OS      : Linux - Linux a3.local 6.2.0-26-generic #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jul 13 16:27:29 UTC 2 x86_64
INI actual  : /home/server/php-lua/tmp-php.ini
More .INIs  :
CWD         : /home/server/php-lua
Extra dirs  :
VALGRIND    : Not used
=====================================================================
TIME START 2023-08-26 07:54:14
=====================================================================
PASS Basic lua check [tests/001.phpt]
PASS Check for Table Pass vic-a-verse [tests/0014.phpt]
FAIL Set and read properties [tests/002.phpt]
PASS Call lua functions [tests/003.phpt]
FAIL Type conversion from lua to PHP [tests/004.phpt]
PASS Lua phpinfo() block [tests/005.phpt]
PASS Lua::include() [tests/006.phpt]
PASS Lua return function [tests/007.phpt]
PASS register php function to lua [tests/008.phpt]
PASS Bug (eval and include compute wrong return value number) [tests/009.phpt]
PASS LuaClosure exception [tests/010.phpt]
PASS register invalid php callback to lua [tests/011.phpt]
PASS Lua::include() with error codes [tests/012.phpt]
PASS PHP Closures from Lua [tests/013.phpt]
PASS PHP Object to lua [tests/016.phpt]
PASS Bug #65097 (nApplyCount release missing) [tests/bug65097.phpt]
PASS Bug #71997 (One-Dimensional arrays cause segmentation faults) [tests/bug71997.phpt]
FAIL Bug #73964 (Segmentation fault (11)) [tests/bug73964.phpt]
PASS ISSUE #022 (Boolean FALSE is always TRUE) [tests/issue012.phpt]
PASS ISSUE #040 (segmentation fault) [tests/issue040.phpt]
PASS test basic print() functionality [tests/print.phpt]
PASS print with tables - 1 [tests/print_tables-1.phpt]
PASS print with tables - 2 [tests/print_tables-2.phpt]
=====================================================================
TIME END 2023-08-26 07:54:19

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :    0
Exts tested     :   16
---------------------------------------------------------------------

Number of tests :   23                23
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    3 ( 13.0%) ( 13.0%)
Tests passed    :   20 ( 87.0%) ( 87.0%)
---------------------------------------------------------------------
Time taken      :    5 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Set and read properties [tests/002.phpt]
Type conversion from lua to PHP [tests/004.phpt]
Bug #73964 (Segmentation fault (11)) [tests/bug73964.phpt]
=====================================================================

You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it.  You can then email it to [email protected] later.
Do you want to send this report now? [Yns]:

New function: move/copy file as root

  • a simple extension/addtion to file_move and copy_file to allow moving files as root for automated collaborations without shares (e.g. moving files to another department)

api-request: new_folder

Hi,

I'm trying to create a new folder in a script, but there doesn't seem to be a function for that case. There is a new_file function in the api, but i can't find one regarding folders. Would it be possible to implement one or is there another workaround?

Actions in context menu

I find the possiblity to link file actions in the file menu extremely useful and it's greatly appreciated. However, I would prefer to be able to define it for every file action separately, otherwise the menu gets cluttered. So the "More actions" should always be there but you can also link/highlight individual actions in the menu which would make it more tidy imo.

cannot move / delete / rename files in flow

To Reproduce:

  • create an action with the code:
files = get_input_files()

for i, file in ipairs(files) do
  name = file.name
  
  if name == "a.txt" then
    file_move(file, nil, "b.txt")
  end
end
  • create a flow like this

image

  • create a text file named a.txt, notice how it doesn't rename
  • run the action, it should rename now
  • rename it again to a.txt, it should rename but it doesn't

Script repository

Would it be useful to have a script repository with file_actions which you can activate if wanted or at least which users can use as template for there needs.

Or at least a link to a repository where you can get some inspiration.

I'm thinking on something like
https://store.kde.org/browse?cat=102&ord=latest

Multi-select - strange behaviour

When selecting with the Multi-select mechanism, the first option returns (when selected) an error.
Also, the selected item does not remain visible in the list after it has been selected.

Reproduce with:

image

Testing this action returns the choosen animal but dog. When choosing dog, it returns "Action failed unexpectedly"

Confusing: no matter what animal i choose, only "dog" is visible.

Did I missunderstand something again?

Can't add script in Nextcloud 25.0.4 + php8.1/lua5.4 extension enabled

Hi! Unable to add Lua script in File Actions app. This is an error:

Screenshot_20230307_150624

Error message in Nextcloud log:

{
"reqId": "MCZrWjVXp2fM883AJdfp",
"level": 3,
"time": "2023-03-07T11:09:17+00:00",
"remoteAddr": "192.168.6.29",
"user": "serg",
"app": "files_scripts",
"method": "POST",
"url": "/apps/files_scripts/scripts",
"message": "File scripts insert error",
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
"version": "25.0.4.1",
"data": {
"app": "files_scripts",
"trace": "#0 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(329): OC\DB\Exceptions\DbalException::wrap()#1 /var/www/nextcloud/lib/public/AppFramework/Db/QBMapper.php(139): OC\DB\QueryBuilder\QueryBuilder->executeStatement()\n#2 /var/www/nextcloud/apps/files_scripts/lib/Controller/ScriptController.php(104): OCP\AppFramework\Db\QBMapper->insert()\n#3 /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php(225): OCA\FilesScripts\Controller\ScriptController->create()\n#4 /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php(133): OC\AppFramework\Http\Dispatcher->executeController()\n#5 /var/www/nextcloud/lib/private/AppFramework/App.php(172): OC\AppFramework\Http\Dispatcher->dispatch()\n#6 /var/www/nextcloud/lib/private/Route/Router.php(298): OC\AppFramework\App::main()\n#7 /var/www/nextcloud/lib/base.php(1047): OC\Route\Router->match()\n#8 /var/www/nextcloud/index.php(36): OC::handleRequest()\n#9 {main}"
}
}

  • Nextcloud 25.0.4
  • PHP 8.1.2
  • Lua 5.4
  • Installation done as described in "Recommended" section in documentation.

what am I doing wrong?

Is it possible to get Node by file path?

I need to get a list of Nodes in an arbitrary folder. There is a directory_listing() function here, but it needs to pass an argument of type Node, not a string. How to solve this problem?

Function "get_file_tags" confuses

Hi Raul,

first of all: thank you so much for this great app. I am a big fan and use it at a daily basis for a growing number of solutions.

The only thing that drives me nuts, is the new get_file_tags() function.

In the Scripting Api it says:

image

I gues that is a tipo (get_tags instead of get_file_tags), same in this line:

* local tags = get_tags(get_input_files()[1])

But now to my issue:
I am trying to get the tags from a previously tagged file.
My first step to understand how things work, is to return the echo into a text-file, like it works with all the meta_data etc. but in this case it does not work.
Since get_file_tags() returns a table, I used table.concat() to get a coma separated list of tags like this:

local files = get_input_files()
for _, input_file in ipairs(files) do
  local output_filename = input_file.name .. '.tags.txt'
  local out_folder = get_parent(input_file)
  if exists(out_folder, output_filename) then
    abort('Output file "' .. output_filename .. '" already exists. Skipping...')
    goto continue
  end
  local tags = get_file_tags(input_file)
  local tags_str = table.concat(tags, ',')
  new_file(out_folder, output_filename, tags_str)
  ::continue::
end

.. but it does not work.

But when I do:

  local tags = get_file_tags(input_file)
--  local tags_str = table.concat(tags, ',')
  new_file(out_folder, output_filename, #tags)

it returns the correct number of tags.

What am I doing wrong?

lua extension not installed

Error Message "lua extension not installed on server" shown although lua is listed when executing php -m on server.
Any hints for a cause/solution?

tag_file_unassign function question

Hi,

Tried to add very simple script (for flows) to remove tags under certain conditions.
However, it seems that function unassign works only of tag ID ( in the form od argument i.e "{ID=1}", but it ignores name= or just plain tagname as string.

Kind Regards,
Adhai

Snap php.ini

The installation instructions tell to append extension=lua.so to your php.ini, but how do you do that on the Snap package? I've tried editing the php.ini within the /snap/nextcloud/current/config/php directory, but it doesn't work since snap files are in a read-only filesystem.

file_open

Would be nice to build out scripts which end up opening specified files for editing or viewing purposes.

[Checkbox] unsatisfactory behavior

When using the user input "Checkbox", a litlle slider appears and when clicking once on it, it returns true but no optical feedback if checkbox is "Set".
Once the input is clicked, it is impossible to unset the checkbox again, once clicked, it stays returning "true".

How to reproduce:

image

Behaviour
Not set:

image

Set:

image

Feature: Dynamic inputs

This is maybe a bit difficult, but it would be nice to be able to have inputs that are added/removed based on some input, like a file/folder. For example, in the directory tree example, you'd be able to select which files in the specific folder you want printed to the txt file.

I think this would be possible with a script that creates a script on-the-fly that adds necessary inputs. Any pointers welcome!

Improvement to the UI/UX

After working with the app and coding with the help of @Raudius several scripts let me give some suggestions how to improve the app's UX:

  • add the functionality to set default values to variables;
  • make possible to move custom variables upper and lower;
  • made possible define mutual dependence on variables, eg, if a switcher is on not to show another field;
  • export/import scripts to JSON;
  • add the link to the documentation on coding the scripts;
  • create collection of open scripts and ready made functions (eg verification of open/closed files, applying to sole or several files etc);
  • make possible to add the functionality to apply the script immediately from the user's in files;
    ....?

You are welcome to add your own ideas.

Function to get absolute path to file

When running certain commands from shell I need to pass the full path to the selected file, I made a workaround but it doesn't work with group folders, maybe a full_path_unlocked() function?

File activities

It would be a great enhancement if the API allowed access to file activity as well.
My aim is to export a file approval protocol based on the approval flow in the file activities.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.