feat: api.php를 sammoAPI()로 통일
This commit is contained in:
+10
-61
@@ -265,6 +265,7 @@ import _ from "lodash";
|
|||||||
import { InvalidResponse } from "@/defs";
|
import { InvalidResponse } from "@/defs";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import NumberInputWithInfo from "@/components/NumberInputWithInfo.vue";
|
import NumberInputWithInfo from "@/components/NumberInputWithInfo.vue";
|
||||||
|
import { sammoAPI } from "./util/sammoAPI";
|
||||||
|
|
||||||
type InheritanceType =
|
type InheritanceType =
|
||||||
| "previous"
|
| "previous"
|
||||||
@@ -505,24 +506,11 @@ export default defineComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result: InvalidResponse;
|
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
await sammoAPI("InheritAction/BuyHiddenBuff", {
|
||||||
url: "api.php",
|
type: buffKey,
|
||||||
method: "post",
|
level,
|
||||||
responseType: "json",
|
|
||||||
data: {
|
|
||||||
path: "InheritAction/BuyHiddenBuff",
|
|
||||||
args: {
|
|
||||||
type: buffKey,
|
|
||||||
level,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
result = response.data;
|
|
||||||
if (!result.result) {
|
|
||||||
throw result.reason;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert(`실패했습니다: ${e}`);
|
alert(`실패했습니다: ${e}`);
|
||||||
@@ -561,21 +549,8 @@ export default defineComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result: InvalidResponse;
|
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
await sammoAPI(`InheritAction/${type}`, {});
|
||||||
url: "api.php",
|
|
||||||
method: "post",
|
|
||||||
responseType: "json",
|
|
||||||
data: {
|
|
||||||
path: `InheritAction/${type}`,
|
|
||||||
args: {},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
result = response.data;
|
|
||||||
if (!result.result) {
|
|
||||||
throw result.reason;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert(`실패했습니다: ${e}`);
|
alert(`실패했습니다: ${e}`);
|
||||||
@@ -608,23 +583,10 @@ export default defineComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result: InvalidResponse;
|
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
await sammoAPI(`InheritAction/SetNextSpecialWar`, {
|
||||||
url: "api.php",
|
type: this.nextSpecialWar,
|
||||||
method: "post",
|
|
||||||
responseType: "json",
|
|
||||||
data: {
|
|
||||||
path: `InheritAction/SetNextSpecialWar`,
|
|
||||||
args: {
|
|
||||||
type: this.nextSpecialWar,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
result = response.data;
|
|
||||||
if (!result.result) {
|
|
||||||
throw result.reason;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert(`실패했습니다: ${e}`);
|
alert(`실패했습니다: ${e}`);
|
||||||
@@ -653,24 +615,11 @@ export default defineComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result: InvalidResponse;
|
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
await sammoAPI(`InheritAction/BuySpecificUnique`, {
|
||||||
url: "api.php",
|
item: this.specificUnique,
|
||||||
method: "post",
|
amount,
|
||||||
responseType: "json",
|
|
||||||
data: {
|
|
||||||
path: `InheritAction/BuySpecificUnique`,
|
|
||||||
args: {
|
|
||||||
item: this.specificUnique,
|
|
||||||
amount,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
result = response.data;
|
|
||||||
if (!result.result) {
|
|
||||||
throw result.reason;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert(`실패했습니다: ${e}`);
|
alert(`실패했습니다: ${e}`);
|
||||||
|
|||||||
+2
-14
@@ -318,6 +318,7 @@ import { clone, shuffle, sum } from "lodash";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { InvalidResponse } from "@/defs";
|
import { InvalidResponse } from "@/defs";
|
||||||
import NumberInputWithInfo from "@/components/NumberInputWithInfo.vue";
|
import NumberInputWithInfo from "@/components/NumberInputWithInfo.vue";
|
||||||
|
import { sammoAPI } from "./util/sammoAPI";
|
||||||
|
|
||||||
declare const nationList: {
|
declare const nationList: {
|
||||||
nation: number;
|
nation: number;
|
||||||
@@ -534,21 +535,8 @@ export default defineComponent({
|
|||||||
async submitForm() {
|
async submitForm() {
|
||||||
//검증은 언제 되어야 하는가?
|
//검증은 언제 되어야 하는가?
|
||||||
const args = clone(this.args);
|
const args = clone(this.args);
|
||||||
let result: InvalidResponse;
|
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
await sammoAPI(["General", "Join"], args);
|
||||||
url: "api.php",
|
|
||||||
method: "post",
|
|
||||||
responseType: "json",
|
|
||||||
data: {
|
|
||||||
path: ["General", "Join"],
|
|
||||||
args,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
result = response.data;
|
|
||||||
if (!result.result) {
|
|
||||||
throw result.reason;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert(`실패했습니다: ${e}`);
|
alert(`실패했습니다: ${e}`);
|
||||||
|
|||||||
+29
-35
@@ -12,16 +12,22 @@ import { InvalidResponse } from '@/defs';
|
|||||||
import { delay } from '@util/delay';
|
import { delay } from '@util/delay';
|
||||||
import { Modal } from 'bootstrap';
|
import { Modal } from 'bootstrap';
|
||||||
import '@/gateway/common';
|
import '@/gateway/common';
|
||||||
|
import { sammoAPI } from '@/util/sammoAPI';
|
||||||
|
import { isString } from 'lodash';
|
||||||
|
|
||||||
type LoginResponse = {
|
type LoginResponse = {
|
||||||
result: true,
|
result: true,
|
||||||
nextToken: [number, string] | undefined,
|
nextToken: [number, string] | undefined,
|
||||||
} | {
|
}
|
||||||
|
|
||||||
|
type LoginFailed = {
|
||||||
result: false,
|
result: false,
|
||||||
reqOTP: boolean,
|
reqOTP: boolean,
|
||||||
reason: string,
|
reason: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LoginResponseWithKakao = LoginResponse | LoginFailed;
|
||||||
|
|
||||||
type OTPResponse = {
|
type OTPResponse = {
|
||||||
result: true,
|
result: true,
|
||||||
validUntil: string,
|
validUntil: string,
|
||||||
@@ -31,15 +37,18 @@ type OTPResponse = {
|
|||||||
reason: string,
|
reason: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type AutoLoginNonceResponse = {
|
type AutoLoginNonceResponse = {
|
||||||
result: true,
|
result: true,
|
||||||
loginNonce: string,
|
loginNonce: string,
|
||||||
} | InvalidResponse;
|
};
|
||||||
|
|
||||||
type AutoLoginResponse = {
|
type AutoLoginResponse = {
|
||||||
result: true,
|
result: true,
|
||||||
nextToken: [number, string] | undefined,
|
nextToken: [number, string] | undefined,
|
||||||
} | {
|
}
|
||||||
|
|
||||||
|
type AutoLoginFailed = {
|
||||||
result: false,
|
result: false,
|
||||||
silent: boolean,
|
silent: boolean,
|
||||||
reason: string,
|
reason: string,
|
||||||
@@ -92,36 +101,26 @@ async function tryAutoLogin() {
|
|||||||
|
|
||||||
const [tokenID, token] = tokenInfo;
|
const [tokenID, token] = tokenInfo;
|
||||||
|
|
||||||
const result = await axios.post<AutoLoginNonceResponse>('api.php', {
|
const result = await sammoAPI<AutoLoginNonceResponse, AutoLoginFailed>(["Login", "ReqNonce"], {}, true);
|
||||||
path: ["Login", "ReqNonce"]
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
//api 에러.
|
//api 에러.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.data.result) {
|
if (!result.result) {
|
||||||
resetToken();
|
resetToken();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nonce = result.data.loginNonce;
|
const nonce = result.loginNonce;
|
||||||
|
|
||||||
const hashedToken = sha512(token + nonce);
|
const hashedToken = sha512(token + nonce);
|
||||||
const _loginResult = await axios.post<AutoLoginResponse>('api.php', {
|
const loginResult = await sammoAPI<AutoLoginResponse, AutoLoginFailed>(["Login", "LoginByToken"], {
|
||||||
path: ["Login", "LoginByToken"],
|
'hashedToken': hashedToken,
|
||||||
args: {
|
'token_id': tokenID,
|
||||||
'hashedToken': hashedToken,
|
}, true);
|
||||||
'token_id': tokenID,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!_loginResult) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const loginResult = _loginResult.data;
|
|
||||||
if (!loginResult.result) {
|
if (!loginResult.result) {
|
||||||
if (!loginResult.silent) {
|
if (!loginResult.silent) {
|
||||||
alert(loginResult.reason);
|
alert(loginResult.reason);
|
||||||
@@ -137,6 +136,9 @@ async function tryAutoLogin() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
if (isString(e)) {
|
||||||
|
alert(e);
|
||||||
|
}
|
||||||
console.error(e);
|
console.error(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -201,7 +203,7 @@ async function sendTempPasswordToKakaoTalk(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function doLoginUsingOAuth() {
|
async function doLoginUsingOAuth() {
|
||||||
let result: LoginResponse;
|
let result: LoginResponseWithKakao;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
const response = await axios({
|
||||||
@@ -307,22 +309,14 @@ $(async function ($) {
|
|||||||
const salt = unwrap_any<string>($('#global_salt').val());
|
const salt = unwrap_any<string>($('#global_salt').val());
|
||||||
const hash_pw = sha512(salt + raw_password + salt);
|
const hash_pw = sha512(salt + raw_password + salt);
|
||||||
|
|
||||||
let result: LoginResponse;
|
let result: LoginResponse | LoginFailed;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
result = await sammoAPI<LoginResponse, LoginFailed>(["Login", "LoginByID"], {
|
||||||
url: 'api.php',
|
username: values.username,
|
||||||
responseType: 'json',
|
password: hash_pw,
|
||||||
method: 'post',
|
|
||||||
data: {
|
}, true);
|
||||||
path: ["Login", "LoginByID"],
|
|
||||||
args: {
|
|
||||||
username: values.username,
|
|
||||||
password: hash_pw,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
result = response.data;
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
+10
-3
@@ -2,11 +2,15 @@ import axios from "axios";
|
|||||||
import { isArray } from "lodash";
|
import { isArray } from "lodash";
|
||||||
import { InvalidResponse } from '@/defs';
|
import { InvalidResponse } from '@/defs';
|
||||||
|
|
||||||
type ValidResponse = {
|
export type ValidResponse = {
|
||||||
result: true
|
result: true
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sammoAPI<ResultType extends ValidResponse>(path: string | string[], args?: Record<string, unknown>): Promise<ResultType> {
|
export async function sammoAPI<ResultType extends ValidResponse>(path: string | string[], args?: Record<string, unknown>): Promise<ResultType>;
|
||||||
|
export async function sammoAPI<ResultType extends ValidResponse>(path: string | string[], args: Record<string, unknown> | undefined, returnError: false): Promise<ResultType>;
|
||||||
|
export async function sammoAPI<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(path: string | string[], args: Record<string, unknown> | undefined, returnError: true): Promise<ResultType | ErrorType>;
|
||||||
|
|
||||||
|
export async function sammoAPI<ResultType extends ValidResponse, ErrorType extends InvalidResponse>(path: string | string[], args?: Record<string, unknown>, returnError = false): Promise<ResultType | ErrorType> {
|
||||||
if (isArray(path)) {
|
if (isArray(path)) {
|
||||||
path = path.join('/');
|
path = path.join('/');
|
||||||
}
|
}
|
||||||
@@ -20,8 +24,11 @@ export async function sammoAPI<ResultType extends ValidResponse>(path: string |
|
|||||||
args,
|
args,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const result: InvalidResponse | ResultType = response.data;
|
const result: ErrorType | ResultType = response.data;
|
||||||
if (!result.result) {
|
if (!result.result) {
|
||||||
|
if (returnError) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
throw result.reason;
|
throw result.reason;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+10
-26
@@ -1,9 +1,5 @@
|
|||||||
import '@scss/processing.scss';
|
import '@scss/processing.scss';
|
||||||
|
|
||||||
import axios from 'axios';
|
|
||||||
import { setAxiosXMLHttpRequest } from '@util/setAxiosXMLHttpRequest';
|
|
||||||
import { convertFormData } from '@util/convertFormData';
|
|
||||||
import { InvalidResponse } from '@/defs';
|
|
||||||
import { unwrap } from "@util/unwrap";
|
import { unwrap } from "@util/unwrap";
|
||||||
import BootstrapVue3 from 'bootstrap-vue-3'
|
import BootstrapVue3 from 'bootstrap-vue-3'
|
||||||
import Multiselect from 'vue-multiselect';
|
import Multiselect from 'vue-multiselect';
|
||||||
@@ -13,36 +9,24 @@ import { App, createApp } from 'vue';
|
|||||||
import { auto500px } from './util/auto500px';
|
import { auto500px } from './util/auto500px';
|
||||||
import { isString } from 'lodash';
|
import { isString } from 'lodash';
|
||||||
import { Args, testSubmitArgs } from './processing/args';
|
import { Args, testSubmitArgs } from './processing/args';
|
||||||
|
import { sammoAPI, ValidResponse } from './util/sammoAPI';
|
||||||
|
|
||||||
declare const turnList: number[];
|
declare const turnList: number[];
|
||||||
|
|
||||||
setAxiosXMLHttpRequest();
|
async function submitCommand<T extends ValidResponse>(isChiefTurn: boolean, turnList: number[], action: string, arg: Args): Promise<T> {
|
||||||
|
const target = isChiefTurn ? 'Command/ReserveCommand' : 'NationCommand/ReserveCommand';
|
||||||
async function submitCommand<T>(isChiefTurn: boolean, turnList: number[], command: string, args: Args): Promise<T> {
|
|
||||||
|
|
||||||
|
|
||||||
const target = isChiefTurn ? 'j_set_chief_command.php' : 'j_set_general_command.php';
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const testResult = testSubmitArgs(args);
|
const testResult = testSubmitArgs(arg);
|
||||||
if (testResult !== true) {
|
if (testResult !== true) {
|
||||||
throw new TypeError(`Invalied Type ${testResult[0]}, ${testResult[2]} should be ${testResult[1]}`);
|
throw new TypeError(`Invalied Type ${testResult[0]}, ${testResult[2]} should be ${testResult[1]}`);
|
||||||
}
|
}
|
||||||
console.log('trySubmit', args);
|
console.log('trySubmit', arg);
|
||||||
const response = await axios({
|
const response = await sammoAPI(target, {
|
||||||
url: target,
|
action,
|
||||||
responseType: 'json',
|
turnList,
|
||||||
method: 'post',
|
arg,
|
||||||
data: convertFormData({
|
|
||||||
action: command,
|
|
||||||
turnList: turnList,
|
|
||||||
arg: JSON.stringify(args)
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
const data = response.data as InvalidResponse;
|
|
||||||
if (!data.result) {
|
|
||||||
throw data.reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isChiefTurn) {
|
if (!isChiefTurn) {
|
||||||
window.location.href = './';
|
window.location.href = './';
|
||||||
@@ -50,7 +34,7 @@ async function submitCommand<T>(isChiefTurn: boolean, turnList: number[], comman
|
|||||||
window.location.href = 'v_chiefCenter.php';
|
window.location.href = 'v_chiefCenter.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
return data as unknown as T;
|
return response as T;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user