Skip to content

Commit

Permalink
test(sagi): fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ipy committed Oct 7, 2019
1 parent 2dd9c98 commit 1eebdc7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/renderer/libs/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ApiError extends Error {
public message: string;
}

const fetcher = new Fetcher({ timeout: 1000 * 10 });
const fetcher = new Fetcher();

async function getEndpoint() {
const api = await apiOfAccountService();
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/libs/sagi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,8 @@ export class Sagi {
// check sagi-api health, return UNKNOWN(0), SERVING(1) or XXXXX
public healthCheck(): Promise<HealthCheckResponse.AsObject> {
const client = new HealthClient(Sagi.endpoint, this.creds);
console.log('client', Sagi.endpoint, this.creds); // eslint-disable-line
return new Promise((resolve, reject) => {
console.log('promise'); // eslint-disable-line
client.check(new HealthCheckRequest(), (err, response) => {
console.log('checked', err, response); // eslint-disable-line
if (err) reject(err);
else {
const status = response.getStatus();
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export async function checkForUpdate(
const skipVersion = localStorage.getItem('skip-check-for-update');
const url = isBetaVersion
? 'https://beta.splayer.org/beta/latest.json' : 'https://www.splayer.org/stable/latest.json';
const fetcher = new Fetcher({ timeout: 10000 });
const fetcher = new Fetcher();
const res = await fetcher.fetch(url);
const data = await res.json();
const result = {
Expand Down
11 changes: 9 additions & 2 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,31 @@ if (process.type === 'browser') {
};
}
function crossThreadCache(key, fn) {
return async () => {
const func = async () => {
if (typeof app.getCrossThreadCache !== 'function') return fn();
let val = app.getCrossThreadCache(key);
if (val) return val;
val = await fn();
app.setCrossThreadCache(key, val);
return val;
};
func.noCache = fn;
return func;
}

export const getIP = crossThreadCache('ip', async () => {
const res = await fetcher.fetch('https://ip.xindong.com/myip');
const res = await fetcher.get('https://ip.xindong.com/myip');
const ip = await res.text();
return ip;
});

export const getClientUUID = crossThreadCache(
'clientUUID',
() => new Promise((resolve) => {
if (process.env.NODE_ENV === 'testing') {
resolve('00000000-0000-0000-0000-000000000000');
return;
}
storage.get('user-uuid', (err, userUUID) => {
if (err || Object.keys(userUUID).length === 0) {
if (err) console.error(err);
Expand Down

0 comments on commit 1eebdc7

Please sign in to comment.