(origin, token, groupName)
| 167 | } |
| 168 | |
| 169 | async function getGroupByName(origin, token, groupName) { |
| 170 | const targetName = (groupName || SUB2API_DEFAULT_GROUP_NAME).trim() || SUB2API_DEFAULT_GROUP_NAME; |
| 171 | const groups = await requestJson(origin, '/api/v1/admin/groups/all', { |
| 172 | method: 'GET', |
| 173 | token, |
| 174 | }); |
| 175 | |
| 176 | const normalized = targetName.toLowerCase(); |
| 177 | const group = (groups || []).find((item) => { |
| 178 | const itemName = String(item?.name || '').trim().toLowerCase(); |
| 179 | if (!itemName) return false; |
| 180 | if (itemName !== normalized) return false; |
| 181 | return !item.platform || item.platform === 'openai'; |
| 182 | }); |
| 183 | |
| 184 | if (!group) { |
| 185 | throw new Error(`SUB2API 中未找到名为“${targetName}”的 openai 分组。`); |
| 186 | } |
| 187 | |
| 188 | return group; |
| 189 | } |
| 190 | |
| 191 | function buildDraftAccountName(groupName) { |
| 192 | const prefix = (groupName || SUB2API_DEFAULT_GROUP_NAME) |
no test coverage detected