First of all, you should use better analyzing-tools when hacking.
I made a tool to get verbose file information about any file at any moment:
It is based on the file_script app
It passes file information about selected files, say “file[i]”, gathered by the server (from a server side point of view) and gives it to a script, that echoes it back into a file “file[i].fileinfo.txt” in the same directory and in adition it gives information gathered by system tools such as file and mimetype (os point of view). Here an example of the output:
Give it a try:
Create a file /usr/local/bin/nc-get-fileinfo
:
#!/bin/bash
echo "$(date +"%Y-%m-%d %H:%M:%S %Z")"
if [ $# -lt 10 ]; then
digits=1
elif [ $# -lt 100 ]; then
digits=2
else
digits=3
fi
# iterate over the arguments
for (( i=0; i<=$#; i++ )); do
# format the index with leading zeros
index=$(printf "%0*d" $digits $i)
# get the i-th argument
arg=${!i}
# echo the argument with its index
echo " - arg $index = $arg"
if echo "$arg" | grep -q "meta.local_path"; then
lp="${arg##*= }"
fi
done
echo
echo "information gathered by file:"
echo " file = $(file -bL "$lp")"
echo " -k, --keep-going = $(file -bLk "$lp")"
echo " -z, --uncompress = $(file -bLz "$lp")"
echo " -Z, --uncompress-noreport = $(file -bLZ "$lp")"
echo " -i, --mime = $(file -bLi "$lp")"
echo " --mime-type = $(file -bL --mime-type "$lp")"
echo " --extension = $(file -bL --extension "$lp")"
echo
echo "information gathered by mimetype:"
echo " mimetype = $(mimetype -b "$lp")"
echo " -a, --all = $(mimetype -ba "$lp" | uniq | sed ':a;N;$!ba;s/\n/, /g')"
echo " --file-compat = $(mimetype -b --file-compat "$lp")"
exit 0
(updated 08.03.2023; 19:15)
and make it executable.
Now go to the admin section of “File actions” (/settings/admin/files_scripts), create a New action, name it “Get Fileinfo”, paste this lua script into the code-window:
-- Process the files
local files = get_input_files()
local arguments = {}
for _, input_file in ipairs(files) do
local output_filename = input_file.name .. '.fileinfo.txt'
local out_folder = get_parent(input_file)
-- Check if the output file already exists
if exists(out_folder, output_filename) then
abort('Output file "' .. output_filename .. '" already exists. Skipping...')
-- Skip to the next iteration of the loop
goto continue
end
local arguments = {}
if is_file(input_file) then
-- only for analyzing purpose:
local users = users_find(nil, nil)
local num_users = #users
-- user invoking this actionscript
local current_user = users_find(nil, nil)[1].uuid
-- to enable UID's with spaces:
-- local current_user = '"' .. users_find(nil, nil)[1].uuid .. '"'
-- finding out nextclouds installation dir with shell_command `pwd`
local current_dir = shell_command('pwd').output
-- provides full path as seen by nextcloud
local filename = "'" .. full_path(input_file) .. "'"
-- to enable filenames (input_files) with spaces:
-- local filename = '"' .. full_path(input_file):gsub('"', '\\"') .. '"'
-- meta_data part:
local metadata = meta_data(input_file)
local size = metadata.size or ""
local mimetype = metadata.mimetype or ""
local etag = metadata.etag or ""
local utime = metadata.utime or ""
local mtime = metadata.mtime or ""
local can_read = metadata.can_read or ""
local can_delete = metadata.can_delete or ""
local can_update = metadata.can_update or ""
local storage_path = metadata.storage_path or ""
local local_path = metadata.local_path or ""
local owner_id = metadata.owner_id or ""
-- tags part.
local tags = get_file_tags(input_file)
local assigned_tags = #tags
local metadata_args = {
"'found_users = " .. num_users .. "'",
"'invoking_nc_user = " .. current_user .. "'",
-- obtained from shell_command('pwd')
"'nextcloud_dir = " .. current_dir .. "'",
-- full_path(input_file):
"'filename = " .. filename .. "'",
-- gathered from meta_data:
"'meta.size = " .. size .. "'",
"'meta.mimetype = " .. mimetype .. "'",
"'meta.etag = " .. etag .. "'",
"'meta.utime = " .. utime .. "'",
"'meta.mtime = " .. mtime .. "'",
"'meta.can_read = " .. tostring(can_read) .. "'",
"'meta.can_delete = " .. tostring(can_delete) .. "'",
"'meta.can_update = " .. tostring(can_update) .. "'",
"'meta.storage_path = " .. storage_path .. "'",
"'meta.local_path = " .. local_path .. "'",
"'meta.owner_id = " .. owner_id .. "'",
"'assigned_tags = " .. assigned_tags .. "'",
}
-- Add each tag as its own string in the metadata_args array
for i, tag in ipairs(tags) do
local tag_str = "' - tag-" .. i .. " details = id=" .. tag.id .. ", name=" .. tag.name .. ", user_assignable=" .. tostring(tag.user_assignable) .. ", user_visible=" .. tostring(tag.user_visible) .. ", access_level=" .. tag.access_level .. "'"
table.insert(metadata_args, tag_str)
end
-- Concatenate the metadata_args array into a single string with spaces between each argument
local arguments_string = table.concat(metadata_args, " ")
table.insert(arguments, arguments_string)
end
-- Construct the command string with quotes around each argument
local command = "/usr/local/bin/nc-get-fileinfo " .. table.concat(arguments, " ")
-- Run the command
local result = shell_command(command)
-- Create output file with the same name as the input file but with .fileinfo.txt extension
local output_file = new_file(out_folder, output_filename, result.output .. "\n" .. result.errors)
if output_file == nil then
abort("Could not create output file: " .. output_filename)
end
::continue::
end
(updated 08.03.2023; 19:15)
activate and save it.
Now you can go to whatever file you want in your cloud and you’ll find “More actions” in the context menu, when you choose “Get Fileinfo” and click “Execute”, the magic happens.
Now to your Issue. I got the same result without messing around in the codebase of the server, only withChanges to config/mimetypemapping.json
The problematic of your approach is that you don’t understand yourself, why one or the other works now. Messing around in the codebase of the server gives errors like “Some files have not passed the integrity check.” etc.
You should always first completely understand how things work together and then, when you want to change things, create a theme in the /themes directory and activate it.
To create previews of the .psb files, it only needed this line to be added to config/mimetypemapping.json:
"psb": ["application/x-photoshop"],
thats all.
After you did occ maintenance:mimetype:update-js
, you will see, that as soon as you change a file in your cloud to *.psb, and you look (with my analising tool) to the mimetype as seen by the server, you’ll see that it now is seen as “application/x-photoshop” which is automaticaly recognized to create previews. No aditional preview provider, no changes to the code in lib/private/PreviewManager.php, no aditional file lib/private/Preview/PhotoshopPSB.php, nothing.
My advice for further experiments:
Think thoroughly first and only make changes if you really understand how everything interlocks
Happy hacking