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

Desktop,CLI: Fixes #10653: Change Resource filetype detecting strategy #10907

Merged
merged 12 commits into from
Nov 7, 2024

Conversation

pedr
Copy link
Collaborator

@pedr pedr commented Aug 21, 2024

Fixes #10653

Description

It is not a very big change, I'm exchanging the requirement of Desktop and CLI by changing the detecting filetype library to file-type Github NPM

The library is from the same author from the image-type that we were using until this point, but it isn't needed anymore since file-type is a "super set" of image-type detection.

Important: I chose to use an older version of file-type since the current version only supports ESM, which our project has not fully supported yet.

https://github.com/sindresorhus/file-type/releases/tag/v16.5.4

Testing

  1. Get a valid PDF file
  2. Rename it, removing the .pdf extension from the file name
  3. Try to attach the PDF to a note on Desktop app
  4. It should be able to attach file and the local database should have the resource with mime as "application/pdf" (previously the file type would not be detected)

image

@pedr pedr added bug It's a bug desktop All desktop platforms labels Aug 21, 2024
@pedr pedr requested a review from laurent22 August 21, 2024 12:58
const isUpdate = !!options.destinationResourceId;

const uuid = require('./uuid').default;
const { fromFile } = await import('file-type');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new code all imports should be at the top of the file. Also can we not "await" the import? Not sure what it's for, but I don't see the need for it - imports are done synchronously.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And should be fromFile as fileTypeFromFile

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamic imports returns a promise but since the import should be at the top of the file, this doesn't matter here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new code all imports should be at the top of the file. Also can we not "await" the import? Not sure what it's for, but I don't see the need for it - imports are done synchronously.

I think the await import is to allow importing ESM from CommonJS. @pedr Does await import allow us to use an up-to-date version of the library?

Edit: From meeting: It doesn't.

@@ -8,8 +8,7 @@ import shim from '@joplin/lib/shim';
import * as pathUtils from '@joplin/lib/path-utils';
import { getEncryptionEnabled, localSyncInfo } from '@joplin/lib/services/synchronizer/syncInfoUtils';
import { generateMasterKeyAndEnableEncryption, loadMasterKeysFromSettings, masterPasswordIsValid, setupAndDisableEncryption } from '@joplin/lib/services/e2ee/utils';
const imageType = require('image-type');
const readChunk = require('read-chunk');
import { fromFile } from 'file-type';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromFile as fileTypeFromFile

@laurent22
Copy link
Owner

Any reason why there's no unit tests?

@pedr
Copy link
Collaborator Author

pedr commented Aug 22, 2024

Any reason why there's no unit tests?

Sorry, I thought it would be harder to test shim-init-node, but adding a file to test the function make it easier.

but I couldn't find a way to test command-e2ee, I guess I need to create a note, attach a resource to it, enable encryption and then run the decrypt-file command, right? I'm still working on this, I'm having some trouble figuring out how to attach the resource to the note in the test environment.

@@ -0,0 +1,198 @@
%PDF-1.3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support test files should go in packages/app-cli/tests/support which you can then access using the supportDir constant

@laurent22 laurent22 closed this Oct 26, 2024
@laurent22 laurent22 reopened this Oct 26, 2024
@laurent22
Copy link
Owner

@pedr there are some conflicts that need to be resolved

@laurent22 laurent22 merged commit 0aba14f into laurent22:dev Nov 7, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It's a bug desktop All desktop platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set mime type of non-images when creating resources from API
3 participants