|
| 1 | +[Table of contents](README.md#table-of-contents) |
| 2 | + |
| 3 | +# Accept from Flagship |
| 4 | + |
| 5 | +Flagship app is a mobile app that allows users to access all their Cozy from their phone (see [here](https://github.com/cozy/cozy-flagship-app) for more details). |
| 6 | + |
| 7 | +When the Flagship app is installed on the user's phone, then they can share a document with the app to upload it in their Cozy. |
| 8 | + |
| 9 | +When doing so, the user will have to chose which cozy-app should receive the shared document from a list of elligible cozy-apps (i.e. cozy-drive, mespapiers, etc) |
| 10 | + |
| 11 | +To be elligible, a cozy-app has to declare what it can receive. This is done in its `manifest.webapp` file. |
| 12 | + |
| 13 | +## The manifest |
| 14 | + |
| 15 | +The `manifest.webapp` file is used to declare the cozy-app's ability to receive files |
| 16 | + |
| 17 | +### `accept_from_flagship` field |
| 18 | + |
| 19 | +First field to declare is `accept_from_flagship`. It should be set to `true` to make the cozy-app visible in the list of elligible cozy-apps |
| 20 | + |
| 21 | +Example: |
| 22 | +```json |
| 23 | +{ |
| 24 | + "name": "Drive", |
| 25 | + "name_prefix": "Cozy", |
| 26 | + "slug": "drive", |
| 27 | + //... |
| 28 | + "accept_from_flagship": true, |
| 29 | + //... |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +### `accept_documents_from_flagship` field |
| 34 | + |
| 35 | +Declaring `accept_from_flagship: true` is not enough to be able to receive files from the Flagship app. The app should also declare which kind of files it can handle. |
| 36 | + |
| 37 | +The field `accept_documents_from_flagship` is an object containing all criteria that a file or a list of files should meet to be sharable with the cozy-app. |
| 38 | + |
| 39 | +#### `accepted_mime_types` criteria |
| 40 | + |
| 41 | +`accepted_mime_types` is used to declare each file type that can be handled by the cozy-app. |
| 42 | + |
| 43 | +This field should contain a list of all mime types that are supported by the cozy-app. |
| 44 | + |
| 45 | +Example of a cozy-app accepting PDF, and pictures: |
| 46 | +```json |
| 47 | +{ |
| 48 | + //... |
| 49 | + "accept_from_flagship": true, |
| 50 | + "accept_documents_from_flagship": { |
| 51 | + "accepted_mime_types": ["application/pdf", "image/jpeg", "image/png"], |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +In order to accept all files types, it is possible to use `'*/*'` mime type |
| 57 | + |
| 58 | +Example of a cozy-app accepting all types of documents: |
| 59 | +```json |
| 60 | +{ |
| 61 | + //... |
| 62 | + "accept_from_flagship": true, |
| 63 | + "accept_documents_from_flagship": { |
| 64 | + "accepted_mime_types": ["*/*"], |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +#### `max_number_of_files` criteria |
| 70 | + |
| 71 | +`max_number_of_files` is used to declare the maximum number of files that can be shared simultaneously with the cozy-app. |
| 72 | + |
| 73 | +Example of a cozy-app accepting only 1 document at a time: |
| 74 | +```json |
| 75 | +{ |
| 76 | + //... |
| 77 | + "accept_from_flagship": true, |
| 78 | + "accept_documents_from_flagship": { |
| 79 | + "max_number_of_files": 10, |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +Example of a cozy-app accepting up to 10 documents at a time: |
| 85 | +```json |
| 86 | +{ |
| 87 | + //... |
| 88 | + "accept_from_flagship": true, |
| 89 | + "accept_documents_from_flagship": { |
| 90 | + "max_number_of_files": 10, |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +Setting a limit is mandatory. The Flagship app doesn't support unlimited file number. |
| 96 | + |
| 97 | +#### `max_size_per_file_in_MB` criteria |
| 98 | + |
| 99 | +`max_size_per_file_in_MB` is used to declare the maximum size of files that can be handled by the cozy-app. |
| 100 | + |
| 101 | +The size limit is declared in MB. |
| 102 | + |
| 103 | +The size limit is per file. If multiple files are shared with the cozy-app, then each file size should be under that limit. |
| 104 | + |
| 105 | +Example of a cozy-app accepting documents up to 10MB: |
| 106 | +```json |
| 107 | +{ |
| 108 | + //... |
| 109 | + "accept_from_flagship": true, |
| 110 | + "accept_documents_from_flagship": { |
| 111 | + "max_size_per_file_in_MB": 10, |
| 112 | + } |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +Setting a limit is mandatory. The Flagship app doesn't support unlimited file size. |
| 117 | + |
| 118 | +#### `route_to_upload` criteria |
| 119 | + |
| 120 | +`route_to_upload` is used to declare the cozy-app's route that should be used by the Flagship app when sharing files with the cozy-app. |
| 121 | + |
| 122 | +The app should then implement a page on that route that will be responsible to handle those documents (i.e. ask the user where to save the document, analyse the document etc) |
| 123 | + |
| 124 | +Example: |
| 125 | +```json |
| 126 | +{ |
| 127 | + //... |
| 128 | + "accept_from_flagship": true, |
| 129 | + "accept_documents_from_flagship": { |
| 130 | + "route_to_upload": "/#/upload?fromFlagshipUpload=true", |
| 131 | + } |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +#### The complete manifest |
| 136 | + |
| 137 | +Here is an example of a `manifest.webapp` file for an app accepting only up to 10 picture files, with a maximum of 10MB: |
| 138 | +```json |
| 139 | +{ |
| 140 | + "name": "Drive", |
| 141 | + "name_prefix": "Cozy", |
| 142 | + "slug": "drive", |
| 143 | + //... |
| 144 | + "accept_from_flagship": true, |
| 145 | + "accept_documents_from_flagship": { |
| 146 | + "accepted_mime_types": ["image/jpeg", "image/png"], |
| 147 | + "max_number_of_files": 10, |
| 148 | + "max_size_per_file_in_MB": 10, |
| 149 | + "route_to_upload": "/#/upload?fromFlagshipUpload=true" |
| 150 | + } |
| 151 | + //... |
| 152 | +} |
| 153 | +``` |
| 154 | + |
| 155 | +Note that `accept_from_flagship` may seems to be redundant if `accept_documents_from_flagship` exists. This field is an optimization to allow cozy-client queries to filter only cozy-apps that accept sharings. |
| 156 | + |
| 157 | +## The API |
| 158 | + |
| 159 | +When a cozy-app is selected by the user to receive a shared file, this cozy-app is opened using the `route_to_upload` route. |
| 160 | + |
| 161 | +Then the cozy-app can use the Flagship OsReceive API to handle shared files. |
| 162 | + |
| 163 | +This API is documented [here](https://github.com/cozy/cozy-flagship-app/tree/master/src/app/domain/osReceive/os-receive-api.md) |
0 commit comments