Support multiple format-aware document identifiers in KOSync

Open
#52 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
28/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Active
Tech stack
lua

Research direction

No files or tests are named. Start by tracing the current document-matching request and identifier handling, then review how clients and formats could supply multiple identifiers; done requires an agreed API and matching behavior, including tests for content, filename, and format-specific identifiers.

Written by the indexing model from the issue text.

Description

Problem

KOSync currently matches a document using either the file-content hash or the filename hash. The user must choose one.

Both methods are useful, but both are fragile:

  • Content matching breaks when the same book is recompressed, optimized, or repackaged.
  • Filename matching breaks when the file is renamed.
  • Choosing one method discards the matching value of the other.
  • Some KOSync clients do not support filename matching at all.

My use case

I encountered this when trying to synchronize reading progress between Readest and CrossInk.

CrossInk renames and compresses an EPUB when preparing it for the device. Compressing the EPUB makes sense for a storage-constrained reader, but it changes the file contents. Renaming it also changes the filename.

As a result, neither of KOSync's current identifiers matches the original EPUB:

  • The content hash no longer matches because the EPUB was compressed.
  • The filename hash no longer matches because the file was renamed.
  • Even preserving the filename would not fully solve the problem because not every KOSync client supports filename-based matching.

The EPUB still represents the same book and retains metadata such as its title, author, and publisher. A metadata-derived identifier could have allowed it to match.

Suggestion

Could KOSync support multiple identifiers for the same document and match when any of them identifies an existing record?

Instead of choosing:

content OR filename

a client could provide:

content AND filename AND any identifiers supported by the format

Conceptually, a request might include something like:

{
  "document": "primary-document-hash",
  "identifiers": [
    {
      "type": "content",
      "value": "partial-content-hash"
    },
    {
      "type": "filename",
      "value": "filename-hash"
    },
    {
      "type": "epub-package-id",
      "value": "package-identifier-hash"
    },
    {
      "type": "metadata",
      "value": "title-author-publisher-language-hash"
    },
    {
      "type": "title-author",
      "value": "title-author-hash"
    }
  ],
  "percentage": 0.42,
  "progress": "/body/DocFragment[20]/body/p[22]"
}

This JSON is only intended to illustrate the idea, not prescribe a particular API.

Different formats could provide the identifiers available to them:

  • EPUB could use content, filename, package identifier, ISBN, title, author, publisher, and language.
  • Audio formats could use content, filename, and their own embedded metadata or identifiers.
  • Plain text files might remain limited to content and filename.

The exact identifiers would depend on the format and what each client can reliably extract. Metadata-derived identifiers could remain locally hashed, so the server would not need to receive titles, authors, or filenames in plaintext.

This would preserve exact content matching while allowing renamed, recompressed, or optimized copies of the same document to match through another identifier.

Would multiple format-aware identifiers be a reasonable direction for KOSync?

Dominant language
Lua
Stars
824
Forks
66
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from koreader/koreader-sync-server

All issues in koreader/koreader-sync-server

Similar issues

More Lua issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.