GCRC / nunaliit_android

Android application for Nunaliit
MIT License
1 stars 1 forks source link

Sync and view existing document attachments #52

Open ahayes opened 6 years ago

ahayes commented 6 years ago

Documents in web atlases may have attachments. If the document is being synched to device, any attachments should be synched as well.

Users on device should be able to:

In the future, in a UI for choosing what to sync, it would be desirable to include an option for indicating whether or not to include attachments in the sync to device.

jpfiset commented 6 years ago

In the document structure, CouchDb includes meta-data for the attachments under _attachments. For example:

{
  "_id": "d1e26a6e8ce2e9d3ece6021fdc020637",
  "_rev": "13-08e2fa036b74799b6fff4737775fa703",
  "_attachments": {
    "gy44untnxu6_thumb.jpg": {
      "content_type": "image\/jpeg",
      "revpos": 12,
      "digest": "md5-oZbXxsTm1WHQQ\/RWsfTukg==",
      "length": 6106,
      "stub": true
    },
    "gy44untnxu6_original.webm": {
      "content_type": "video\/x-matroska",
      "revpos": 5,
      "digest": "md5-\/6CoQ0lhSyA9EF92NLG1vw==",
      "length": 537562,
      "stub": true
    },
    "gy44untnxu6.mp4": {
      "content_type": "video\/mp4",
      "revpos": 9,
      "digest": "md5-X\/lCrATAiB72JJ\/Y\/gCOjg==",
      "length": 96871,
      "stub": true
    }
  }
}

The name of the attachment is not so important in this feature. Instead, the digest should be used as the identifier for an attachment. The name of an attachment could be changed, or the same attachment might be found in multiple documents. Unfortunately, the way the digest is computed can not be reliably reproduced outside of CouchDb as I have read online that the computation is not consistent across versions/platforms.

If attachments were downloaded, they should be saved to disk and a record should be inserted a database dedicated for this purpose. Each record in this database should include the digest of the attachment and the name of the file where it is stored.

Nunaliit relies on a URL to display an attachment. More specifically, one function performs the translation from docId/attachment-name to URL: CouchDocumentSource.getDocumentAttachmentUrl() [n2.couchDocument.js : 392]. If the media files stored on disk were accessible to the web view via a URL, then this is the place where the special database should be queried.