41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
|
|
import type { PeqEqUi } from "./types";
|
||
|
|
|
||
|
|
export type ShareApiAction = "create" | "query" | "accept" | "list";
|
||
|
|
|
||
|
|
export function resolveShareApiMessage(
|
||
|
|
action: ShareApiAction,
|
||
|
|
res: { code: number; msg?: string },
|
||
|
|
eqUi: PeqEqUi,
|
||
|
|
): string {
|
||
|
|
if (res.code === 200) return "";
|
||
|
|
|
||
|
|
if (action === "list") {
|
||
|
|
return eqUi.mySharesLoadFail ?? "Failed to load share list";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (res.code === 0) {
|
||
|
|
if (action === "create") {
|
||
|
|
return eqUi.shareActiveExists ?? eqUi.shareCreateFail ?? "Failed to generate share code";
|
||
|
|
}
|
||
|
|
return eqUi.importCodeNotFound ?? "Share code not found or expired";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (res.code === 400) {
|
||
|
|
return eqUi.shareInvalidParams ?? eqUi.shareCreateFail ?? "Invalid request";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (res.code === 500) {
|
||
|
|
return eqUi.shareSystemError ?? eqUi.shareCreateFail ?? "System error";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (action === "create") {
|
||
|
|
return eqUi.shareCreateFail ?? "Failed to generate share code";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (action === "accept") {
|
||
|
|
return eqUi.importFail ?? eqUi.importCodeNotFound ?? "Failed to import EQ";
|
||
|
|
}
|
||
|
|
|
||
|
|
return eqUi.importCodeNotFound ?? "Share code not found or expired";
|
||
|
|
}
|