aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/zulip/index.js
blob: ea3944f33e073d79891beeaf1c65044955eed343 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module.exports = Ferdium =>
  class Zulip extends Ferdium {
    async validateUrl(url) {
      const baseUrl = new window.URL(url);
      const apiVersion = 'api/v1';
      try {
        const resp = await window.fetch(
          `${baseUrl.origin}/${apiVersion}/server_settings`,
          {
            method: 'GET',
            headers: {
              'Content-Type': 'application/json',
            },
          },
        );
        const data = await resp.json();

        return Object.hasOwnProperty.call(data, 'realm_uri');
      } catch (error) {
        console.error(error);
      }

      return false;
    }
  };