mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-18 18:50:49 +08:00
refactor(api): add raw request helper and centralize headers
This commit is contained in:
@@ -724,16 +724,11 @@ export const authFilesModule = {
|
||||
this.vertexImportState.loading = true;
|
||||
this.updateVertexImportButtonState();
|
||||
|
||||
const response = await fetch(`${this.apiUrl}/vertex/import`, {
|
||||
const response = await this.apiClient.requestRaw('/vertex/import', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.managementKey}`
|
||||
},
|
||||
body: formData
|
||||
});
|
||||
|
||||
this.updateVersionFromHeaders(response.headers);
|
||||
|
||||
if (!response.ok) {
|
||||
let errorMessage = `HTTP ${response.status}`;
|
||||
try {
|
||||
@@ -879,13 +874,7 @@ export const authFilesModule = {
|
||||
|
||||
async downloadAuthFile(filename) {
|
||||
try {
|
||||
const response = await fetch(`${this.apiUrl}/auth-files/download?name=${encodeURIComponent(filename)}`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.managementKey}`
|
||||
}
|
||||
});
|
||||
|
||||
this.updateVersionFromHeaders(response.headers);
|
||||
const response = await this.apiClient.requestRaw(`/auth-files/download?name=${encodeURIComponent(filename)}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
@@ -1017,16 +1006,11 @@ export const authFilesModule = {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file, file.name);
|
||||
|
||||
const response = await fetch(`${this.apiUrl}/auth-files`, {
|
||||
const response = await this.apiClient.requestRaw('/auth-files', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.managementKey}`
|
||||
},
|
||||
body: formData
|
||||
});
|
||||
|
||||
this.updateVersionFromHeaders(response.headers);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.error || `HTTP ${response.status}`);
|
||||
|
||||
Reference in New Issue
Block a user