PageSourceSearch

https://perbonelog.com.br/enderecosServico/nodeApi/ApiEnd.js?v=1700656921

js perbonelog.com.br collected 2026-10-02 01:18:58 UTC 6,429 bytes, 212 lines download raw bytes

1/**
2 * Função responsável por consumir a API do Node
3 * @param {string} token Token JWT para efetuar a requisição
4 * @returns Retorna um `object` com os métodos necessários para consumir a API
5 */
6function ApiEnd(token) {
7  var urlBase = `https://elasticend.appmapp.com.br/api/v1`;
8  // if (
9  //   location.hostname == "tutts.com.br" ||
10  //   location.hostname == "www.tutts.com.br" ||
11  //   location.hostname == "www.mototaxionline.srv.br" ||
12  //   location.hostname == "mototaxionline.srv.br"
13  // ) {
14  //   urlBase = `https://elasticaws.mappsistemas.com/api/v1`;
15  // }
16
17  // if (location.hostname == "localhost") {
18  //   urlBase = `https://elasticaws.mappsistemas.com/api/v1`;
19  // }
20  // var urlBase = `http://127.0.0.1:4545/api/v1`;
21
22  /**
23   * Função responsável por enviar a requisição
24   * @param {string} uri URI que será enviada a requisição
25   * @param {object} options Opções para que seja efetuada a requisição
26   * @returns Retorna um `object` ou `false` caso haja erro
27   */
28  async function request(uri, options) {
29    const timeout = 2000;
30    const controller = new AbortController();
31    const id = setTimeout(() => controller.abort(), timeout);
32    const res = await fetch(urlBase + uri, {
33      ...options,
34      signal: controller.signal,
35    })
36      .then((res) => (res.ok ? res.json() : false))
37      .catch((err) => console.log("Houve um erro ao enviar a requisição", err));
38
39    clearTimeout(id);
40    return res;
41  }
42
43  async function requestEndSalvo(uri, options, idEndBanco) {
44    const timeout = 2000;
45    const controller = new AbortController();
46    const id = setTimeout(() => controller.abort(), timeout);
47    const res = await fetch(urlBase + uri, {
48      ...options,
49      signal: controller.signal,
50    })
51      .then((res) => res.json())
52      .catch((err) => console.log("Houve um erro ao enviar a requisição", err));
53
54    clearTimeout(id);
55    return res;
56  }
57
58  return {
59    /**
60     * Função responsável por consumir a rota de autocomplete da API do Node
61     * @param {object} params Parâmetros que serão enviados na requisição
62     * @returns Retorna um `object` ou `false` caso haja erro
63     */
64    autocomplete: async (params) => {
65      var uri = "/autocomplete?" + new URLSearchParams(params).toString();
66
67      var headers = new Headers({
68        "Content-Type": "application/json",
69        Authorization: `Bearer ${token}`,
70      });
71
72      // if (
73      //   location.hostname == "tutts.com.br" ||
74      //   location.hostname == "www.tutts.com.br" ||
75      //   location.hostname == "www.mototaxionline.srv.br" ||
76      //   location.hostname == "mototaxionline.srv.br"
77      // ) {
78      //   headers = new Headers({
79      //     "Content-Type": "application/json",
80      //   });
81      // }
82
83      // if (location.hostname == "localhost") {
84      //   headers = new Headers({
85      //     "Content-Type": "application/json",
86      //   });
87      // }
88
89      return await request(uri, {
90        method: "GET",
91        headers: headers,
92      });
93    },
94
95    autocomplete2: async (params) => {
96      var uri = "/autocomplete2?" + new URLSearchParams(params).toString();
97
98      var headers = new Headers({
99        "Content-Type": "application/json",
100        Authorization: `Bearer ${token}`,
101      });
102
103      // if (
104      //   location.hostname == "tutts.com.br" ||
105      //   location.hostname == "www.tutts.com.br" ||
106      //   location.hostname == "www.mototaxionline.srv.br" ||
107      //   location.hostname == "mototaxionline.srv.br"
108      // ) {
109      //   headers = new Headers({
110      //     "Content-Type": "application/json",
111      //   });
112      // }
113
114      // if (location.hostname == "localhost") {
115      //   headers = new Headers({
116      //     "Content-Type": "application/json",
117      //   });
118      // }
119
120      return await request(uri, {
121        method: "GET",
122        headers: headers,
123      });
124    },
125    autocomplete3: async (params) => {
126      var uri = "/autocomplete3?" + new URLSearchParams(params).toString();
127
128      var headers = new Headers({
129        "Content-Type": "application/json",
130        Authorization: `Bearer ${token}`,
131      });
132
133      // if (
134      //   location.hostname == "tutts.com.br" ||
135      //   location.hostname == "www.tutts.com.br" ||
136      //   location.hostname == "www.mototaxionline.srv.br" ||
137      //   location.hostname == "mototaxionline.srv.br"
138      // ) {
139      //   headers = new Headers({
140      //     "Content-Type": "application/json",
141      //   });
142      // }
143
144      // if (location.hostname == "localhost") {
145      //   headers = new Headers({
146      //     "Content-Type": "application/json",
147      //   });
148      // }
149
150      return await request(uri, {
151        method: "GET",
152        headers: headers,
153      });
154    },
155    inserir: async (body) => {
156      console.log("INSERINDO ENDEREÇO PELO JAVASCRIPT");
157      const options = {
158        method: "POST",
159        body: JSON.stringify(body),
160        headers: new Headers({
161          "Content-Type": "application/json",
162          Authorization: `Bearer ${token}`,
163        }),
164      };
165
166      request("/elastic/inserir", options);
167    },
168    inserirEndSalvo: async (body, idEndBanco) => {
169      console.log("INSERINDO ENDEREÇO PELO JAVASCRIPT- EndereSalvo");
170      const options = {
171        method: "POST",
172        body: JSON.stringify(body),
173        headers: new Headers({
174          "Content-Type": "application/json",
175          Authorization: `Bearer ${token}`,
176        }),
177      };
178
179      return await requestEndSalvo(
180        "/elastic/inserir-async",
181        options,
182        idEndBanco
183      );
184    },
185    atualizar: async (_id, body) => {
186      console.log("ATUALIZANDO ENDEREÇO PELO JAVASCRIPT");
187      const options = {
188        method: "PUT",
189        body: JSON.stringify(body),
190        headers: new Headers({
191          "Content-Type": "application/json",
192          Authorization: `Bearer ${token}`,
193        }),
194      };
195
196      request(`/elastic/atualizar/${_id}`, options);
197    },
198    atualizarTodosCampos: async (_id, body) => {
199      console.log("ATUALIZANDO ENDEREÇO PELO JAVASCRIPT");
200      const options = {
201        method: "PUT",
202        body: JSON.stringify(body),
203        headers: new Headers({
204          "Content-Type": "application/json",
205          Authorization: `Bearer ${token}`,
206        }),
207      };
208
209      return await request(`/elastic/atualizarTodosCampos/${_id}`, options);
210    },
211  };
212}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.