@auto-ai/agent 2.1.120 → 2.1.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +2 -1
- package/dist/404/index.html +1 -1
- package/dist/404.html +1 -1
- package/dist/_next/static/chunks/19aa69c07b3642d5.js +1 -0
- package/dist/_next/static/chunks/24459c7365a2b28b.js +1 -0
- package/dist/_next/static/chunks/{d3e2070a86378cfb.js → 33eeef286c328da0.js} +1 -1
- package/dist/_next/static/chunks/3407244006d6a98a.js +1 -0
- package/dist/_next/static/chunks/566e152e480b267a.js +1 -0
- package/dist/_next/static/chunks/6ad4268160f361a6.js +1 -0
- package/dist/_next/static/chunks/{d9a278a2a26e8ee5.js → 6f9a48a7f83e669a.js} +1 -1
- package/dist/_next/static/chunks/7658b5b9c2865eb1.js +1 -0
- package/dist/_next/static/chunks/7a5fd448b280dd64.js +1 -0
- package/dist/_next/static/chunks/{fa677aa06f1c0539.js → 98f0c5604e839ba2.js} +1 -1
- package/dist/_next/static/chunks/a38eccf0bb5ca1e9.js +1 -0
- package/dist/_next/static/chunks/b29a354245bfc377.css +1 -0
- package/dist/_next/static/chunks/b76778c5811ef7a1.js +1 -0
- package/dist/_next/static/chunks/c2bed9d5fa7be4bd.js +1 -0
- package/dist/_next/static/chunks/c5a4977aae6a008c.js +1 -0
- package/dist/_next/static/chunks/e7bd145455a541af.css +4 -0
- package/dist/_next/static/chunks/f2bb685629307d4d.js +1 -0
- package/dist/_next/static/chunks/f7e71ce1c236f806.js +1 -0
- package/dist/_next/static/chunks/{67acc15b8a448e1a.js → fc4be3bcf72559a0.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/index.txt +16 -16
- package/dist/manage/about/index.html +2 -2
- package/dist/manage/about/index.txt +19 -19
- package/dist/manage/add-account/basic/index.html +2 -2
- package/dist/manage/add-account/basic/index.txt +23 -22
- package/dist/manage/add-account/index.html +2 -2
- package/dist/manage/add-account/index.txt +22 -23
- package/dist/manage/agent-teams/index.html +2 -2
- package/dist/manage/agent-teams/index.txt +21 -21
- package/dist/manage/env/index.html +2 -2
- package/dist/manage/env/index.txt +21 -21
- package/dist/manage/general/index.html +2 -2
- package/dist/manage/general/index.txt +19 -19
- package/dist/manage/index.html +1 -1
- package/dist/manage/index.txt +16 -16
- package/dist/manage/mcp/index.html +2 -2
- package/dist/manage/mcp/index.txt +21 -21
- package/dist/manage/permissions/index.html +2 -2
- package/dist/manage/permissions/index.txt +19 -19
- package/dist/manage/skills/index.html +2 -2
- package/dist/manage/skills/index.txt +21 -21
- package/dist/manage/task/index.html +2 -2
- package/dist/manage/task/index.txt +19 -19
- package/dist/manage/teams/index.html +2 -2
- package/dist/manage/teams/index.txt +19 -19
- package/dist/manage/tools/index.html +2 -2
- package/dist/manage/tools/index.txt +21 -21
- package/dist/ws-test.html +129 -191
- package/mcps-runtime/claude-geelib-channel/.mcp.json +18 -0
- package/mcps-runtime/claude-geelib-channel/server/boot.mjs +32 -0
- package/mcps-runtime/claude-geelib-channel/server/geelib-api.mjs +192 -0
- package/mcps-runtime/claude-geelib-channel/server/geelib-auth.mjs +147 -0
- package/mcps-runtime/claude-geelib-channel/server/geelib-client.mjs +63 -0
- package/mcps-runtime/claude-geelib-channel/server/index.mjs +451 -0
- package/mcps-runtime/claude-geelib-channel/server/poll.mjs +457 -0
- package/mcps-runtime/claude-geelib-channel/server/state.mjs +216 -0
- package/package.json +6 -6
- package/tools-runtime/code-tool/index.cjs +1 -0
- package/tools-runtime/code-tool/src/index.ts +7 -1
- package/tools-runtime/git-tool/index.cjs +69 -5
- package/tools-runtime/git-tool/src/workspace.ts +101 -4
- package/tools-runtime/git-tool/src/wsInit.ts +26 -3
- package/dist/_next/static/chunks/249606605eed1993.js +0 -1
- package/dist/_next/static/chunks/424d3f3f176d43d7.js +0 -1
- package/dist/_next/static/chunks/4302af16b34bf750.js +0 -1
- package/dist/_next/static/chunks/4a073924e062c459.css +0 -1
- package/dist/_next/static/chunks/6209b42cbfcf288a.js +0 -1
- package/dist/_next/static/chunks/83bf6e4bc0aad48b.css +0 -4
- package/dist/_next/static/chunks/8b34d657c6bbb8df.js +0 -1
- package/dist/_next/static/chunks/904ad158fd721117.js +0 -1
- package/dist/_next/static/chunks/99063f8d79783308.js +0 -1
- package/dist/_next/static/chunks/9cd912a1967f10df.js +0 -1
- package/dist/_next/static/chunks/c52dcbe269bb02d0.js +0 -1
- package/dist/_next/static/chunks/d01957b1055b357a.js +0 -1
- package/dist/_next/static/chunks/dacc94cf10289334.js +0 -1
- package/dist/_next/static/chunks/fff9d250e482f00e.js +0 -1
- package/skills-runtime/geelib/SKILL.md +0 -229
- package/skills-runtime/geelib/geelib-poller-state.json +0 -17
- package/skills-runtime/geelib/geelib.mjs +0 -762
- /package/dist/_next/static/{fg4nA8liSSLEgWV4WTZDt → pVB1xZbEW09ksdJlV12Zn}/_buildManifest.js +0 -0
- /package/dist/_next/static/{fg4nA8liSSLEgWV4WTZDt → pVB1xZbEW09ksdJlV12Zn}/_clientMiddlewareManifest.json +0 -0
- /package/dist/_next/static/{fg4nA8liSSLEgWV4WTZDt → pVB1xZbEW09ksdJlV12Zn}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { geelibGet, geelibPost } from './geelib-client.mjs'
|
|
2
|
+
|
|
3
|
+
const PRIORITY_MAP = {
|
|
4
|
+
low: 1,
|
|
5
|
+
medium: 2,
|
|
6
|
+
high: 3,
|
|
7
|
+
urgent: 4,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function cmdGetUserInfo() {
|
|
11
|
+
return geelibGet('/ones/user/userInfo', { need_share: 0 })
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function cmdListProjects(query = '') {
|
|
15
|
+
return geelibGet('/projects/subBusMgr/getCanAccessSubList', {
|
|
16
|
+
query,
|
|
17
|
+
simple: 2,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function cmdGetProjectDetail(subId) {
|
|
22
|
+
return geelibGet('/projects/subBusMgr/getSubDetail', { sub_id: subId })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function cmdListProjectMembers(subId) {
|
|
26
|
+
return geelibGet('/projects/subBusMgr/getSubUserListSortByInitial', {
|
|
27
|
+
sub_id: subId,
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function cmdListMatterTypes(subId) {
|
|
32
|
+
return geelibGet('/matter/Matter/getMatterType', {
|
|
33
|
+
sub_id: subId,
|
|
34
|
+
page: 0,
|
|
35
|
+
pageSize: 9999,
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function cmdListMatterStatuses(subId, typeId) {
|
|
40
|
+
return geelibGet('/matter/matterType/getMatterTypeStatusList', {
|
|
41
|
+
sub_id: subId,
|
|
42
|
+
type_id: typeId,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 从 getMatterList 响应中解析工作项列表(GeeLib 返回 matterList)。 */
|
|
47
|
+
export function extractMatterList(data) {
|
|
48
|
+
if (!data || typeof data !== 'object') {
|
|
49
|
+
return []
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(data.matterList)) {
|
|
52
|
+
return data.matterList
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(data.list)) {
|
|
55
|
+
return data.list
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(data.data)) {
|
|
58
|
+
return data.data
|
|
59
|
+
}
|
|
60
|
+
return []
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function cmdListMatters(opts) {
|
|
64
|
+
const customContent = {}
|
|
65
|
+
if (opts.statusId !== undefined) {
|
|
66
|
+
customContent.status = [opts.statusId]
|
|
67
|
+
}
|
|
68
|
+
if (opts.assigneeId !== undefined) {
|
|
69
|
+
customContent.executor = [opts.assigneeId]
|
|
70
|
+
}
|
|
71
|
+
const body = {
|
|
72
|
+
sub_id: opts.subId,
|
|
73
|
+
type_id: [opts.typeId],
|
|
74
|
+
page: opts.page ?? 1,
|
|
75
|
+
pageSize: opts.pageSize ?? 20,
|
|
76
|
+
title: opts.keyword ?? '',
|
|
77
|
+
order_by: [],
|
|
78
|
+
customContent,
|
|
79
|
+
is_favor: 0,
|
|
80
|
+
simple: 0,
|
|
81
|
+
from_v3: 1,
|
|
82
|
+
tree: 0,
|
|
83
|
+
need_user_name: 1,
|
|
84
|
+
}
|
|
85
|
+
return geelibPost('/matter/Matter/getMatterList', body)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function cmdGetMatter(subId, matterId) {
|
|
89
|
+
return geelibGet('/matter/Matter/getMatterDetail', {
|
|
90
|
+
sub_id: subId,
|
|
91
|
+
id: matterId,
|
|
92
|
+
need_options: 1,
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function cmdUpdateMatter(opts) {
|
|
97
|
+
const results = []
|
|
98
|
+
|
|
99
|
+
const hasOtherFields =
|
|
100
|
+
opts.title !== undefined ||
|
|
101
|
+
opts.description !== undefined ||
|
|
102
|
+
opts.assigneeId !== undefined ||
|
|
103
|
+
opts.priority !== undefined ||
|
|
104
|
+
opts.progress !== undefined ||
|
|
105
|
+
opts.sprintId !== undefined
|
|
106
|
+
|
|
107
|
+
if (hasOtherFields) {
|
|
108
|
+
const body = {
|
|
109
|
+
sub_id: opts.subId,
|
|
110
|
+
id: opts.matterId,
|
|
111
|
+
}
|
|
112
|
+
if (opts.title !== undefined) body.title = opts.title
|
|
113
|
+
if (opts.description !== undefined) body.content = opts.description
|
|
114
|
+
if (opts.assigneeId !== undefined) body.executor = opts.assigneeId
|
|
115
|
+
if (opts.priority !== undefined) {
|
|
116
|
+
body.priority = PRIORITY_MAP[opts.priority] ?? opts.priority
|
|
117
|
+
}
|
|
118
|
+
if (opts.progress !== undefined) body.progress = opts.progress
|
|
119
|
+
if (opts.sprintId !== undefined) body.sprint_id = opts.sprintId
|
|
120
|
+
const r = await geelibPost('/matter/Matter/editMatter', body)
|
|
121
|
+
results.push({ fields: 'other', ...r })
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (opts.statusId !== undefined) {
|
|
125
|
+
const statusBody = {
|
|
126
|
+
sub_id: String(opts.subId),
|
|
127
|
+
id: opts.matterId,
|
|
128
|
+
data: { cf_id: '1', cf_value: String(opts.statusId) },
|
|
129
|
+
additional_attribute: [],
|
|
130
|
+
remark: '',
|
|
131
|
+
toUsers: [],
|
|
132
|
+
}
|
|
133
|
+
const sr = await geelibPost('/matter/Matter/editMatter', statusBody)
|
|
134
|
+
|
|
135
|
+
if (sr.errno === 2000) {
|
|
136
|
+
const detail = await geelibGet('/matter/Matter/getMatterDetail', {
|
|
137
|
+
sub_id: opts.subId,
|
|
138
|
+
id: opts.matterId,
|
|
139
|
+
need_options: 1,
|
|
140
|
+
})
|
|
141
|
+
const actualStatus = detail.data?.matter_status
|
|
142
|
+
if (actualStatus !== opts.statusId) {
|
|
143
|
+
const missingFields = (detail.data?.matterCustomAttributes ?? [])
|
|
144
|
+
.filter(a => a.is_required && a.matterCustomAttributeValue === null)
|
|
145
|
+
.map(a => `「${a.cf_name}」(${a.cf_key})`)
|
|
146
|
+
const hint =
|
|
147
|
+
missingFields.length > 0
|
|
148
|
+
? `原因:工作项存在未填的必填字段:${missingFields.join('、')}。请先在 Geelib 网页端补全后重试。`
|
|
149
|
+
: '状态未变更,可能存在未知的状态流转限制。'
|
|
150
|
+
results.push({
|
|
151
|
+
fields: 'status',
|
|
152
|
+
errno: sr.errno,
|
|
153
|
+
errmsg: `API 返回成功但状态实际未变更(当前状态:${detail.data?.status_name ?? actualStatus})。${hint}`,
|
|
154
|
+
})
|
|
155
|
+
} else {
|
|
156
|
+
results.push({
|
|
157
|
+
fields: 'status',
|
|
158
|
+
errno: 2000,
|
|
159
|
+
errmsg: '状态变更成功',
|
|
160
|
+
actual_status: detail.data?.status_name,
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
results.push({ fields: 'status', ...sr })
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (results.length === 0) {
|
|
169
|
+
return { errno: 2000, errmsg: '无需更新(未提供任何修改字段)' }
|
|
170
|
+
}
|
|
171
|
+
if (results.length === 1) {
|
|
172
|
+
return results[0]
|
|
173
|
+
}
|
|
174
|
+
return results
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function cmdGetComments(subId, matterId) {
|
|
178
|
+
return geelibGet('/bservice/Comment/getList', {
|
|
179
|
+
sub_id: subId,
|
|
180
|
+
type: 'matter',
|
|
181
|
+
id: matterId,
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function cmdAddComment(subId, matterId, content) {
|
|
186
|
+
return geelibPost('/bservice/Comment/add', {
|
|
187
|
+
sub_id: subId,
|
|
188
|
+
type: 'matter',
|
|
189
|
+
id: matterId,
|
|
190
|
+
content,
|
|
191
|
+
})
|
|
192
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** GeeLib SSO 登录与 Cookie 会话管理 */
|
|
2
|
+
|
|
3
|
+
const SSO_LOGIN_URL = 'https://login.ops.qihoo.net:4436/sec/login'
|
|
4
|
+
const GEELIB_DO_LOGIN_URL = 'https://geelib.qihoo.net/ones/Login/doLogin'
|
|
5
|
+
const GEELIB_VERIFY_URL =
|
|
6
|
+
'https://geelib.qihoo.net/ones/user/userInfo?need_share=0'
|
|
7
|
+
const BOUNDARY = '----WebKitFormBoundaryGeelibCli'
|
|
8
|
+
|
|
9
|
+
let sessionCookie = ''
|
|
10
|
+
|
|
11
|
+
export function getCookie() {
|
|
12
|
+
return sessionCookie
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function buildFormData(fields) {
|
|
16
|
+
let body = ''
|
|
17
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
18
|
+
body += `--${BOUNDARY}\r\n`
|
|
19
|
+
body += `Content-Disposition: form-data; name="${name}"\r\n\r\n`
|
|
20
|
+
body += `${value}\r\n`
|
|
21
|
+
}
|
|
22
|
+
body += `--${BOUNDARY}--\r\n`
|
|
23
|
+
return body
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parseCookies(headers) {
|
|
27
|
+
const setCookies = headers.getSetCookie?.() ?? []
|
|
28
|
+
const cookies = {}
|
|
29
|
+
for (const c of setCookies) {
|
|
30
|
+
const [pair] = c.split(';')
|
|
31
|
+
const [name, ...rest] = pair.trim().split('=')
|
|
32
|
+
cookies[name.trim()] = rest.join('=').trim()
|
|
33
|
+
}
|
|
34
|
+
return cookies
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** SSO 换取 sid */
|
|
38
|
+
async function ssoLogin(user, passwd) {
|
|
39
|
+
const body = buildFormData({
|
|
40
|
+
user,
|
|
41
|
+
passwd,
|
|
42
|
+
src: 'qihoo',
|
|
43
|
+
syzm: '',
|
|
44
|
+
ref: 'https://geelib.qihoo.net/geelib/',
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const resp = await fetch(SSO_LOGIN_URL, {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
headers: {
|
|
50
|
+
'Content-Type': `multipart/form-data; boundary=${BOUNDARY}`,
|
|
51
|
+
Accept: 'application/json, text/plain, */*',
|
|
52
|
+
Cookie: 'SSO_PREFERED_DOMAIN=qihoo',
|
|
53
|
+
Referer: 'https://login.ops.qihoo.net:4436/sec/login',
|
|
54
|
+
'User-Agent':
|
|
55
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
56
|
+
},
|
|
57
|
+
body,
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
if (!resp.ok) {
|
|
61
|
+
throw new Error(`SSO login failed: ${resp.status} ${resp.statusText}`)
|
|
62
|
+
}
|
|
63
|
+
const data = await resp.json()
|
|
64
|
+
if (data.status !== 0) {
|
|
65
|
+
throw new Error(`SSO login error: ${JSON.stringify(data)}`)
|
|
66
|
+
}
|
|
67
|
+
return data.sid
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** sid 换 GeeLib Cookie */
|
|
71
|
+
async function doLogin(sid) {
|
|
72
|
+
const resp = await fetch(GEELIB_DO_LOGIN_URL, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: {
|
|
75
|
+
'Content-Type': 'application/json',
|
|
76
|
+
Accept: 'application/json, text/plain, */*',
|
|
77
|
+
Referer: 'https://geelib.qihoo.net/geelib/',
|
|
78
|
+
Origin: 'https://geelib.qihoo.net',
|
|
79
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
80
|
+
'User-Agent':
|
|
81
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
82
|
+
},
|
|
83
|
+
body: JSON.stringify({ sid, ref: 'https://geelib.qihoo.net/geelib/' }),
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
if (!resp.ok) {
|
|
87
|
+
throw new Error(`doLogin failed: ${resp.status}`)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const cookies = parseCookies(resp.headers)
|
|
91
|
+
const data = await resp.json()
|
|
92
|
+
|
|
93
|
+
if (data.errno !== 2000) {
|
|
94
|
+
throw new Error(`doLogin error: errno=${data.errno} errmsg=${data.errmsg}`)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const cookieStr = Object.entries(cookies)
|
|
98
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
99
|
+
.join('; ')
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
cookieStr,
|
|
103
|
+
userName: data.data?.real_name ?? data.data?.name ?? '',
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function verifyCookie(cookieStr) {
|
|
108
|
+
try {
|
|
109
|
+
const resp = await fetch(GEELIB_VERIFY_URL, {
|
|
110
|
+
headers: {
|
|
111
|
+
Cookie: cookieStr,
|
|
112
|
+
Referer: 'https://geelib.qihoo.net/geelib/',
|
|
113
|
+
'User-Agent':
|
|
114
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
115
|
+
Accept: 'application/json, text/plain, */*',
|
|
116
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
const data = await resp.json()
|
|
120
|
+
return data.errno === 2000
|
|
121
|
+
} catch {
|
|
122
|
+
return false
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 使用 GEELIB_USER / GEELIB_PASSWD 登录 */
|
|
127
|
+
export async function login() {
|
|
128
|
+
const user = process.env.GEELIB_USER
|
|
129
|
+
const passwd = process.env.GEELIB_PASSWD
|
|
130
|
+
|
|
131
|
+
if (!user || !passwd) {
|
|
132
|
+
throw new Error('请配置 GEELIB_USER 和 GEELIB_PASSWD 环境变量')
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const sid = await ssoLogin(user, passwd)
|
|
136
|
+
const { cookieStr } = await doLogin(sid)
|
|
137
|
+
sessionCookie = cookieStr
|
|
138
|
+
return cookieStr
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Cookie 失效时自动重新登录 */
|
|
142
|
+
export async function ensureAuth() {
|
|
143
|
+
if (sessionCookie && (await verifyCookie(sessionCookie))) {
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
await login()
|
|
147
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ensureAuth, getCookie } from './geelib-auth.mjs'
|
|
2
|
+
|
|
3
|
+
const DEFAULT_BASE_URL = 'https://geelib.qihoo.net'
|
|
4
|
+
|
|
5
|
+
/** 解析 GeeLib API 根地址;未配置或占位符未展开时使用官方默认域名 */
|
|
6
|
+
function resolveBaseUrl() {
|
|
7
|
+
const raw = process.env.GEELIB_BASE_URL?.trim() ?? ''
|
|
8
|
+
if (raw.length === 0 || raw.includes('${')) {
|
|
9
|
+
return DEFAULT_BASE_URL
|
|
10
|
+
}
|
|
11
|
+
return raw.replace(/\/$/, '')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function buildHeaders() {
|
|
15
|
+
const baseUrl = resolveBaseUrl()
|
|
16
|
+
return {
|
|
17
|
+
Cookie: getCookie(),
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
Accept: 'application/json, text/plain, */*',
|
|
20
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
21
|
+
Referer: `${baseUrl}/geelib/`,
|
|
22
|
+
'User-Agent':
|
|
23
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function request(fn) {
|
|
28
|
+
await ensureAuth()
|
|
29
|
+
let resp = await fn()
|
|
30
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
31
|
+
await ensureAuth()
|
|
32
|
+
resp = await fn()
|
|
33
|
+
}
|
|
34
|
+
if (!resp.ok) {
|
|
35
|
+
throw new Error(`HTTP ${resp.status} ${resp.statusText} — ${resp.url}`)
|
|
36
|
+
}
|
|
37
|
+
return resp.json()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function geelibGet(path, params) {
|
|
41
|
+
const url = new URL(path, resolveBaseUrl())
|
|
42
|
+
if (params) {
|
|
43
|
+
for (const [k, v] of Object.entries(params)) {
|
|
44
|
+
if (v !== undefined) {
|
|
45
|
+
url.searchParams.set(k, String(v))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return request(() =>
|
|
50
|
+
fetch(url.toString(), { method: 'GET', headers: buildHeaders() }),
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function geelibPost(path, body) {
|
|
55
|
+
const url = new URL(path, resolveBaseUrl())
|
|
56
|
+
return request(() =>
|
|
57
|
+
fetch(url.toString(), {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: buildHeaders(),
|
|
60
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
61
|
+
}),
|
|
62
|
+
)
|
|
63
|
+
}
|