game/website/assets/game-api.js

43 lines
1.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 宇森游戏 · 前端与 Odoo 通信层
// 所有接口同源yt.pengyuthon.cn由 nginx 代理 /game/* 到 Odoo(game 库)。
// 关键点Odoo 通过 URL 上的 ?db=game 选定数据库(与 game.conf 的 /web/login?db=game 一致),
// 否则请求到达时未选中库,控制器路由找不到 → 404。因此所有调用都带 ?db=game。
// 登录态通过 Odoo session cookie 保持fetch 带 credentials:'same-origin'。
const API = {
async me() {
return (await fetch('/game/api/me?db=game', { credentials: 'same-origin' })).json();
},
async login(login, password) {
return (await fetch('/game/api/login?db=game', {
method: 'POST', credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ login, password }),
})).json();
},
async register(payload) {
return (await fetch('/game/api/register?db=game', {
method: 'POST', credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})).json();
},
async logout() {
return (await fetch('/game/api/logout?db=game', {
method: 'POST', credentials: 'same-origin',
})).json();
},
async codex() {
return (await fetch('/game/api/codex?db=game', { credentials: 'same-origin' })).json();
},
async rules() {
return (await fetch('/game/api/rules?db=game', { credentials: 'same-origin' })).json();
},
async threads() {
return (await fetch('/game/api/threads?db=game', { credentials: 'same-origin' })).json();
},
async announcements() {
return (await fetch('/game/api/announcements?db=game', { credentials: 'same-origin' })).json();
},
};