Skip to content

[SUPPORT] Best approach for attachments like ".txt"? #7

Description

@MySkeletonHurts

General question for your thoughts on something I ran into while getting this Android app setup and looking into #6 . I found some loose files treated like notes (also in Nextcloud Notes Android app since they share the same nextcloud/notes API). I did some digging and it looks like that API has no way to exclude special folders like /attachments or /media that QOwnNotes desktop obviously handles properly. There's just a simple isNote function that whitelists 5 extensions as notes.

// NotesService.php
private static function isNote(FileInfo $file, string $customExtension) : bool {
    static $allowedExtensions = ['txt', 'org', 'markdown', 'md', 'note'];
    $ext = strtolower(pathinfo($file->getName(), PATHINFO_EXTENSION));
    return $file->getType() === 'file' && (in_array($ext, $allowedExtensions) || $ext === $customExtension);
}

The best fix is probably for the API to support excluding certain directory paths. I could open a PR for nextcloud/notes to do that.

Some kind of marker file would probably be ideal, like a .notesignore. That way QOwnNotes desktop could drop the file itself, without users needing to configure anything (other parts of the Nextcloud stack do this already like the .sync-exclude.lst for the desktop sync client). If upstream didn't like that, a persisted per-user setting of folder exclusions could work (like how they handle the hidden file setting today).

Another option would be to leverage the existing option in Nextcloud Notes to not show hidden files.

foreach ($nodes as $node) {
    $hidden = str_starts_with($node->getName(), '.');
    if ($hidden && !$showHidden) {
        continue;   // fires for a hidden file or directory, before isNote() is ever reached
    }

An option (off by default) in QOwnNotes desktop to use /.attachments and /.media so their content never gets treated like individual notes could work, with a side benefit of those special folders not being fully mixed in with the note hierarchy folders in a standard file manager view. I realize that may not be an attractive option for you though.

Not a huge deal either way. I can always clean up my impacted files and either change file extensions (e.g. .txt -> .log) or prepend a "." and adjust the links in the notes. But I like the marker file approach, so maybe I'll file something upstream in nextcloud/notes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions