Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update script version to v1.30 #12

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "primorina",
"version": "1.21",
"version": "1.6",
"description": "log primogems",
"main": "index.js",
"devDependencies": {
Expand Down
146 changes: 124 additions & 22 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// for license and source, visit https://github.com/3096/primorina

const SCRIPT_VERSION = "1.21";
const SCRIPT_VERSION = "1.6";

const SHEET_SOURCE_ID = '1p-SkTsyzoxuKHqqvCJSUCaFBUmxd5uEEvCtb7bAqfDk';
const SHEET_SOURCE_SUPPORTED_LOCALE = "en_GB";
Expand Down Expand Up @@ -31,23 +31,32 @@ const SHEET_NAME_ARTIFACT_MONTHLY_REPORT = "Artifact Monthly Report";
const SHEET_NAME_WEAPON_LOG = "Weapon Log";
const SHEET_NAME_WEAPON_YEARLY_REPORT = "Weapon Yearly Report";
const SHEET_NAME_WEAPON_MONTHLY_REPORT = "Weapon Monthly Report";
const SHEET_NAME_MASTERLESS_LOG = "Masterless Log";
const SHEET_NAME_MASTERLESS_YEARLY_REPORT = "Masterless Yearly Report";
const SHEET_NAME_MASTERLESS_MONTHLY_REPORT = "Masterless Monthly Report";
const SHEET_NAME_STARGLITTER_LOG = "Starglitter Log";
const SHEET_NAME_STARDUST_LOG = "Stardust Log";
const SHEET_NAME_KEY_ITEMS = "Key Items";
const SHEET_NAME_REASON_MAP = "Reason Map";

const MONTHLY_SHEET_NAME = [
SHEET_NAME_PRIMOGEM_MONTHLY_REPORT,
SHEET_NAME_CRYSTAL_MONTHLY_REPORT,
SHEET_NAME_RESIN_MONTHLY_REPORT,
SHEET_NAME_ARTIFACT_MONTHLY_REPORT,
SHEET_NAME_WEAPON_MONTHLY_REPORT,
SHEET_NAME_MORA_MONTHLY_REPORT
SHEET_NAME_MORA_MONTHLY_REPORT,
SHEET_NAME_MASTERLESS_MONTHLY_REPORT
];

const NAME_OF_LOG_HISTORIES = [
SHEET_NAME_PRIMOGEM_LOG,
SHEET_NAME_CRYSTAL_LOG,
SHEET_NAME_RESIN_LOG,
SHEET_NAME_ARTIFACT_LOG,
SHEET_NAME_WEAPON_LOG
SHEET_NAME_WEAPON_LOG,
SHEET_NAME_STARGLITTER_LOG,
SHEET_NAME_STARDUST_LOG
];

const NAME_OF_LOG_HISTORIES_HOYOLAB = [
Expand All @@ -59,54 +68,143 @@ const LOG_CACHE_PREFIX = "CACHED";
// sheet info
interface ILogSheetInfo {
sheetName: string,
apiPaths: { [serverDivide in ServerDivide]: string }
endpointType: string,
apiPaths: { [serverDivide in ServerDivide]: string },
header: { [headerName in HeaderName]: string }
}

const PRIMOGEM_SHEET_INFO: ILogSheetInfo = {
sheetName: SHEET_NAME_PRIMOGEM_LOG,
endpointType: "feedback",
apiPaths: {
cn: "/ysulog/api/getPrimogemLog",
os: "/ysulog/api/getPrimogemLog",
cn: "/common/hk4e_self_help_query/User/GetPrimogemLog",
os: "/common/hk4e_self_help_query/User/GetPrimogemLog",
},
header: {
id: "id",
datetime: "datetime",
total: "add_num",
quantity: "quantity",
reasonId: "reason_id",
reasonDetail: "reason"
}
}

const CRYSTAL_SHEET_INFO: ILogSheetInfo = {
sheetName: SHEET_NAME_CRYSTAL_LOG,
endpointType: "feedback",
apiPaths: {
cn: "/ysulog/api/getCrystalLog",
os: "/ysulog/api/getCrystalLog",
cn: "/common/hk4e_self_help_query/User/GetCrystalLog",
os: "/common/hk4e_self_help_query/User/GetCrystalLog",
},
header: {
id: "id",
datetime: "datetime",
total: "add_num",
reasonId: "reason_id",
reasonDetail: "reason"
}
}

const RESIN_SHEET_INFO: ILogSheetInfo = {
sheetName: SHEET_NAME_RESIN_LOG,
endpointType: "feedback",
apiPaths: {
cn: "/ysulog/api/getResinLog",
os: "/ysulog/api/getResinLog",
cn: "/common/hk4e_self_help_query/User/GetResinLog",
os: "/common/hk4e_self_help_query/User/GetResinLog",
},
header: {
id: "id",
datetime: "datetime",
total: "add_num",
reasonId: "reason_id",
reasonDetail: "reason"
}
}

const ARTIFACT_SHEET_INFO: ILogSheetInfo = {
sheetName: SHEET_NAME_ARTIFACT_LOG,
endpointType: "feedback",
apiPaths: {
cn: "/ysulog/api/getArtifactLog",
os: "/ysulog/api/getArtifactLog",
cn: "/common/hk4e_self_help_query/User/GetArtifactLog",
os: "/common/hk4e_self_help_query/User/GetArtifactLog",
},
header: {
id: "id",
datetime: "datetime",
total: "add_num",
reasonId: "reason_id",
reasonDetail: "reason",
itemName: "name",
itemLevel: "level",
itemRarity: "quality"
}
}

const MORA_SHEET_INFO: ILogSheetInfo = {
sheetName: SHEET_NAME_MORA_LOG,
endpointType: "diary",
apiPaths: {
cn: "/event/ys_ledger/monthDetail",
os: "/event/ysledgeros/month_detail",
os: "/event/ysledgeros/month_detail"
},
header: {
id: "id",
datetime: "time",
total: "num",
reasonId: "action_id",
reasonDetail: "action"
}
}

const WEAPON_SHEET_INFO: ILogSheetInfo = {
sheetName: SHEET_NAME_WEAPON_LOG,
endpointType: "feedback",
apiPaths: {
cn: "/ysulog/api/getWeaponLog",
os: "/ysulog/api/getWeaponLog",
cn: "/common/hk4e_self_help_query/User/GetWeaponLog",
os: "/common/hk4e_self_help_query/User/GetWeaponLog",
},
header: {
id: "id",
datetime: "datetime",
total: "add_num",
reasonId: "reason_id",
reasonDetail: "reason",
itemName: "name",
itemLevel: "level",
itemRarity: "quality"
}
}

const MASTERLESS_STARGLITTER_SHEET_INFO: ILogSheetInfo = {
sheetName: SHEET_NAME_STARGLITTER_LOG,
endpointType: "feedback",
apiPaths: {
cn: "/common/hk4e_self_help_query/User/GetStarglitter",
os: "/common/hk4e_self_help_query/User/GetStarglitter",
},
header: {
id: "id",
datetime: "datetime",
quantity: "quantity",
reasonDetail: "sub_action_name",
battlePathType: "battle_path_type"
}
}

const MASTERLESS_STARDUST_SHEET_INFO: ILogSheetInfo = {
sheetName: SHEET_NAME_STARDUST_LOG,
endpointType: "feedback",
apiPaths: {
cn: "/common/hk4e_self_help_query/User/GetStardustLog",
os: "/common/hk4e_self_help_query/User/GetStardustLog",
},
header: {
id: "id",
datetime: "datetime",
quantity: "quantity",
reasonDetail: "sub_action_name",
battlePathType: "battle_path_type"
}
}

Expand All @@ -117,12 +215,14 @@ const USER_PREFERENCE_MONTHLY_REPORT = "Monthly Report";
const USER_PREFERENCE_YEARLY_REPORT = "Yearly Report";
// User Preferences
const userPreferences = {
"Primogem Log": { "Monthly Report": "B35", "Yearly Report": "B36"},
"Crystal Log": { "Monthly Report": "B38", "Yearly Report": "B39"},
"Resin Log": { "Monthly Report": "B41", "Yearly Report": "B42"},
"Mora Log": { "Monthly Report": "B44", "Yearly Report": "B45"},
"Artifact Log": { "Monthly Report": "B47", "Yearly Report": "B48"},
"Weapon Log": { "Monthly Report": "B50", "Yearly Report": "B51"}
"Primogem Log": { "Monthly Report": "B35", "Yearly Report": "B36", "Log Max Columns": 5},
"Crystal Log": { "Monthly Report": "B38", "Yearly Report": "B39", "Log Max Columns": 5},
"Resin Log": { "Monthly Report": "B41", "Yearly Report": "B42", "Log Max Columns": 5},
"Mora Log": { "Monthly Report": "B44", "Yearly Report": "B45", "Log Max Columns": 5},
"Artifact Log": { "Monthly Report": "B47", "Yearly Report": "B48", "Log Max Columns": 8},
"Weapon Log": { "Monthly Report": "B50", "Yearly Report": "B51", "Log Max Columns": 8},
"Starglitter Log": { "Monthly Report": "B53", "Yearly Report": "B54", "Log Max Columns": 5},
"Stardust Log": { "Monthly Report": "B53", "Yearly Report": "B54", "Log Max Columns": 5}
}
// Remove when using the 'Available' sheet from source, this is for backwards compatibility for v1.0 less. Artifact is done via 'Available' sheet from source
const userPreferencesForReport = {
Expand All @@ -149,7 +249,9 @@ const languageSettingsForImport = {
"Korean": { "code": "ko", "full_code": "ko-kr", "4_star": " (★4)", "5_star": " (★5)" },
"Portuguese": { "code": "pt", "full_code": "pt-pt", "4_star": " (4★)", "5_star": " (5★)" },
"Thai": { "code": "th", "full_code": "th-th", "4_star": " (4 ดาว)", "5_star": " (5 ดาว)" },
"Russian": { "code": "ru", "full_code": "ru-ru", "4_star": " (4★)", "5_star": " (5★)" }
"Russian": { "code": "ru", "full_code": "ru-ru", "4_star": " (4★)", "5_star": " (5★)" },
"Italian": { "code": "it", "full_code": "it-it", "4_star": " (4 ★)", "5_star": " (5 ★)" },
"Turkish": { "code": "tr", "full_code": "tr-tr", "4_star": " (4 Yıldızlı)", "5_star": " (5 Yıldızlı)" }
};

// region
Expand Down
38 changes: 29 additions & 9 deletions src/genshinApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ type LocaleCode =
"ja-jp" | "vi-vn" | "ko-kr" | "pt-pt" | "th-th" | "ru-ru";

const API_DOMAINS_BY_SERVER_DIVIDE = {
cn: "hk4e-api.mihoyo.com",
os: "hk4e-api-os.hoyoverse.com",
feedback: {
cn: "public-operation-hk4e.mihoyo.com",
os: "public-operation-hk4e-sg.hoyoverse.com",
},
diary: {
cn: "hk4e-api.mihoyo.com",
os: "sg-hk4e-api.hoyolab.com",
}
}

const KNOWN_DOMAIN_LIST = [
{ domain: "user.mihoyo.com", serverDivide: "cn" },
{ domain: "account.mihoyo.com", serverDivide: "os" },
{ domain: "cs.hoyoverse.com", serverDivide: "os" },
{ domain: "gs.hoyoverse.com", serverDivide: "os" },
{ domain: "account.hoyoverse.com", serverDivide: "os" },

{ domain: "webstatic.mihoyo.com", serverDivide: "cn" },
Expand Down Expand Up @@ -76,8 +84,12 @@ interface ImServiceLogEntry {
id: string,
uid: string,
time: string,
datetime: string,
add_num: string,
reason: string,
quantity: number,
sub_action_name: string,
battle_path_type: string
}

interface ImServiceLogData {
Expand All @@ -99,11 +111,19 @@ interface ImServiceApiResponse {
// ledger

interface LedgerCookieCn extends Cookies {
account_id: string, cookie_token: string
account_id: string,
cookie_token: string,
bind_uid: string,
bind_region: string,
ltuid_v2: string,
ltoken_v2: string,
ltmid_v2: string,
}

interface LedgerCookieOs extends Cookies {
ltoken: string, ltuid: string
ltuid_v2: string,
ltoken_v2: string,
ltmid_v2: string,
}

interface LedgerParams extends Params {
Expand Down Expand Up @@ -210,24 +230,24 @@ function getApiRequest(endpoint: string, params: Params, cookies: Cookies = null
return request;
}

function getReasonMap(config = getConfig()) {
const LANG_MAP_URL = `https://mi18n-os.mihoyo.com/webstatic/admin/mi18n/hk4e_global/m02251421001311/m02251421001311-${config.languageCode}.json`;
function getReasonMap(config = getConfig()): Map<string, number> {
const LANG_MAP_URL = `https://webstatic.hoyoverse.com/admin/mi18n/hk4e_global/m02251421001311/m02251421001311-${config.languageCode}.json`;
const REASON_PREFIX = "selfinquiry_general_reason_";

const langMap = JSON.parse(UrlFetchApp.fetch(LANG_MAP_URL).getContentText());

const result = new Map<number, string>();
const result = new Map<string, number>();
for (const key in langMap) {
if (!key.includes(REASON_PREFIX)) continue;

const reasonId = parseInt(key.substring(REASON_PREFIX.length));
result.set(reasonId, langMap[key]);
result.set(langMap[key], reasonId);
}
return result;
}

function getApiEndpoint(logSheetInfo: ILogSheetInfo, serverDivide: ServerDivide) {
return "https://" + API_DOMAINS_BY_SERVER_DIVIDE[serverDivide] + logSheetInfo.apiPaths[serverDivide];
return "https://" + API_DOMAINS_BY_SERVER_DIVIDE[logSheetInfo.endpointType][serverDivide] + logSheetInfo.apiPaths[serverDivide];
}

function getServerDivideFromUrl(url: string) {
Expand Down
Loading