How to setup a custom sync server

The Cartograph app can sync data using a custom web server. The following tutorial describes how to setup a sync server.

WARNING: This tutorial covers only the basic setup which is NOT secure. You have to employ custom measures, such as authentication (e.g. HTTPS, “.htaccess”, etc.), for securing the server.

You can download an example PHP implementation here. The example MUST NOT be run on a public web server because it provides full file access.


Setup

Add a new “Custom webserver” to the cloud services. A popup dialog will show:

  • Name: An arbitrary name for identifying the server.
  • Server address: The address of the sync server.
  • Download url: The url where all files are located.
  • Username/Password: The username and password for accessing the web server (for instance defined in the .htaccess file).

Server API

The custom sync server uses a simple query-based API for all operations. Commands are passed via the GET “cmd” argument:

getFileList

Gets a list of all files in a directory.

Example:

[GET] http://localhost:801/cartograph3/syncserver.php?token=sfndj23jsdfnksd28392&cmd=getFileList&subDir=ele_res

Parameters:

  • subDir“: The directory to be queried.

Result:

{
   "error":false,
   "file_list":[
      {
         "name":"p_aboriginal_lands.svg",
         "size":1048,
         "mod_time":"2021-11-03T07:12:45+00:00",
         "is_dir":false,
         "url":"http:\/\/localhost:801\/cartograph3.\/data\/ele_res\/p_aboriginal_lands.svg"
      },
      {
         "name":"wm_frg_yellow_x.svg",
         "size":528,
         "mod_time":"2021-11-03T07:12:45+00:00",
         "is_dir":false,
         "url":"http:\/\/localhost:801\/cartograph3.\/data\/ele_res\/wm_frg_yellow_x.svg"
      }
   ]
}

createDirectory

Creates a new directory.

Example:

[GET] http://localhost:801/cartograph3/syncserver.php?token=sfndj23jsdfnksd28392&cmd=createDirectory&subDir=ele_res&newDir=test

Parameters:

  • subDir“: The parent directory where the new directory will be created in.
  • newDir“: The name of the new directory.

Result:

{
   "error":false
}

deleteFile

Deletes a file or directory.

Example:

[GET] http://localhost:801/cartograph3/syncserver.php?token=sfndj23jsdfnksd28392&cmd=deleteFile&filePath=ele_res/test

Parameters:

  • filePath“: The file or directory which will be deleted.

Result:

{
   "error":false
}

renameFile

Renames a file or directory.

Example:

[GET] http://localhost:801/cartograph3/syncserver.php?token=sfndj23jsdfnksd28392&cmd=renameFile&oldFilePath=ele_res/test&newFilePath=ele_res/test2

Parameters:

  • oldFilePath“: The file or directory to be renamed.
  • newFilePath“: The new file or directory after renaming.

Result:

{
   "error":false
}

uploadFile

Uploads a file to the server.

Example:

[POST] http://localhost:801/cartograph3/syncserver.php?token=sfndj23jsdfnksd28392&cmd=uploadFile&subDir=ele_res&overwrite=true

Parameters:

  • subDir“: The directory where the file is saved to.
  • overwrite“: If true then an eventually existing file shall be overwritten.

Result:

{
   "error":false
}

Leave a Reply

Your email address will not be published. Required fields are marked *