summaryrefslogblamecommitdiffstats
path: root/server/lib/external-backends/external-backends.js
blob: be32c13b71cf9ae554c2ca16f2a8ff1dcb0cb4b1 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                     

                            

                        





                                                                                           

                                                                                                              









                                                          
     



                                                                                                       
 



                   
                                   


                                                                                                               




                                                                           

 
                                 
/* global __appdir */
const fs = require('fs')
const path = require('path')

class ExternalBackends {
  getBackends () {
    var files = fs.readdirSync(path.join(__appdir, 'lib', 'external-backends', 'backends'))
    return files
  }

  getCredentials () {
    console.log('If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!')
    return null
  }

  getInstance (type) {
    const bList = this.getBackends()
    const bType = type + '-backend.js'

    // Check if it's a valid backend type.
    if (bList.indexOf(bType) === -1) {
      console.log(bType + ' is not a valid backend type.')
      return null
    }

    const backend = new (require(path.join(__appdir, 'lib', 'external-backends', 'backends', bType)))()
    return backend
  }

  getSyncTypes () {
    return []
  }

  async checkConnection (backend) {
    console.log('If this method gets called the backend class has NOT IMPLEMENTED the checkConnection method!')
    return null
  }

  // Return an empty array [] if the backends doesn't have such a function.
  async getObjectTypes (credentials) {
    return []
  }
}

module.exports = ExternalBackends