Skip to content

Commit

Permalink
fix types and error
Browse files Browse the repository at this point in the history
  • Loading branch information
EdamAme-x committed Sep 24, 2024
1 parent dedd8e8 commit 1c1a350
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/linejs/client/clients/e2ee/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class E2EE extends TalkClient {
try {
return JSON.parse(this.storage.get("e2eeKeys:" + keyId) as string);
} catch (_e) {
/* DoNothing */
/* Do Nothing */
}
}
public saveE2EESelfKeyDataByKeyId(keyId: string | number, value: LooseType) {
Expand Down
8 changes: 4 additions & 4 deletions packages/linejs/client/clients/internal/liff-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export class LiffClient extends BaseClient {
lang,
});
return liff[3];
} catch (e) {
this.log("liff-error", { ...e.data });
if (e.data.code === 3 && tryConsent) {
const data: LINETypes.LiffException = e.data;
} catch (error) {
this.log("liff-error", { ...error.data });
if (error.data.code === 3 && tryConsent) {
const data: LINETypes.LiffException = error.data;
const payload = data.payload;
const consentRequired = payload.consentRequired;
const channelId = consentRequired.channelId;
Expand Down
4 changes: 3 additions & 1 deletion packages/linejs/client/libs/storage/base-storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { LooseType } from "../../entities/common.ts";

export interface Storage {
Key: string;
Value: string | number | boolean | null | undefined;
Value: string | number | boolean | null | Record<string | number, LooseType>;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions packages/linejs/client/libs/storage/cache-manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { BaseStorage } from "../../../storage/index.ts";
import type { LooseType } from "../../entities/common.ts";

interface Storage {
Key: string;
Value: string | number | boolean | null | Record<string | number, any>;
Value: string | number | boolean | null | Record<string | number, LooseType>;
}

type CacheInfo = Record<Storage["Key"], number>;
Expand Down Expand Up @@ -52,7 +53,7 @@ export class CacheManager {
*/
public setCache(
requestName: string,
request: Record<string, any>,
request: Record<string, LooseType>,
response: Storage["Value"],
): void {
this.set(requestName + JSON.stringify(request), response);
Expand All @@ -69,7 +70,7 @@ export class CacheManager {
try {
this.cacheInfo[key] = new Date().getTime();
return JSON.parse(this.storage.get("cache:" + key) as string);
} catch (error) {}
} catch (_e) {/* Do Nothing */}
}

/**
Expand All @@ -81,7 +82,7 @@ export class CacheManager {
*/
public getCache(
requestName: string,
request: Record<string, any>,
request: Record<string, LooseType>,
): Storage["Value"] | undefined {
return this.get(requestName + JSON.stringify(request));
}
Expand Down
16 changes: 5 additions & 11 deletions packages/linejs/client/libs/storage/dir-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ export class DirStorage extends BaseStorage {
public get(key: Storage["Key"]): Storage["Value"] | undefined {
try {
return this.getValue(fs.readFileSync(this.getPath(key), "utf-8"));
} catch (_error) {}
} catch (_e) {/* Do Nothing */}
}

public delete(key: Storage["Key"]): void {
try {
fs.rmSync(this.getPath(key));
} catch (_e) {}
} catch (_e) {/* Do Nothing */}
}

public clear(): void {
fs.readdirSync(this.path).forEach((e) => {
try {
fs.rmSync(e);
} catch (_e) {}
} catch (_e) {/* Do Nothing */}
});
}

Expand All @@ -90,33 +90,27 @@ export class DirStorage extends BaseStorage {
switch (typeof obj) {
case "string":
return "s" + obj.toString();
break;
case "number":
return "n" + obj.toString();
break;
case "boolean":
return "b" + obj.toString();
break;
default:
return "x";
break;
}
}

public getValue(value: string): Storage["Value"] {
switch (value[0]) {
case "s":
return value.substring(1);
break;
case "n":
return Number(value.substring(1));
break;
case "b":
return Boolean(value.substring(1));
break;
case "x":
return null;
break;
default:
return null;
}
}
}

0 comments on commit 1c1a350

Please sign in to comment.