mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 09:39:03 +08:00
fix: 修复云空间用量Failed to fetch
This commit is contained in:
@@ -206,7 +206,7 @@ export function ContentArea({
|
||||
|
||||
try {
|
||||
const api = (window as any).api
|
||||
if (!api?.oauthLoadLoginState) {
|
||||
if (!api?.oauthLoadLoginState || !api?.oauthGetStorageUsage) {
|
||||
setStorageUsage(null)
|
||||
setStorageUsageError("当前环境不支持云用量查询")
|
||||
return
|
||||
@@ -229,37 +229,24 @@ export function ContentArea({
|
||||
return
|
||||
}
|
||||
|
||||
const params = new URLSearchParams({
|
||||
client_id: platformId,
|
||||
user_id: oauthState.user_id,
|
||||
})
|
||||
|
||||
const response = await fetch(
|
||||
`https://appwrite.sectl.top/api/cloud/storage/usage?${params.toString()}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${oauthState.access_token}`,
|
||||
},
|
||||
}
|
||||
const usageRes = await api.oauthGetStorageUsage(
|
||||
oauthState.access_token,
|
||||
platformId,
|
||||
oauthState.user_id
|
||||
)
|
||||
|
||||
const responseText = await response.text()
|
||||
let payload: any = {}
|
||||
try {
|
||||
payload = responseText ? JSON.parse(responseText) : {}
|
||||
} catch {
|
||||
payload = {}
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(payload?.error_description || payload?.message || "获取云空间用量失败")
|
||||
if (!usageRes?.success || !usageRes.data) {
|
||||
throw new Error(usageRes?.message || "获取云空间用量失败")
|
||||
}
|
||||
|
||||
setStorageUsage({
|
||||
used_storage_formatted: String(payload?.used_storage_formatted || "0 B"),
|
||||
total_storage_formatted: String(payload?.total_storage_formatted || "0 B"),
|
||||
percentage: Number.isFinite(payload?.percentage) ? Number(payload.percentage) : 0,
|
||||
file_count: Number.isFinite(payload?.file_count) ? Number(payload.file_count) : 0,
|
||||
used_storage_formatted: String(usageRes.data.used_storage_formatted || "0 B"),
|
||||
total_storage_formatted: String(usageRes.data.total_storage_formatted || "0 B"),
|
||||
percentage: Number.isFinite(usageRes.data.percentage)
|
||||
? Number(usageRes.data.percentage)
|
||||
: 0,
|
||||
file_count: Number.isFinite(usageRes.data.file_count)
|
||||
? Number(usageRes.data.file_count)
|
||||
: 0,
|
||||
})
|
||||
} catch (error: any) {
|
||||
setStorageUsage(null)
|
||||
@@ -697,3 +684,4 @@ export function ContentArea({
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -565,6 +565,24 @@ const api = {
|
||||
data: string
|
||||
message?: string
|
||||
}> => invoke("oauth_get_device_uuid"),
|
||||
oauthGetStorageUsage: (
|
||||
accessToken: string,
|
||||
platformId: string,
|
||||
userId: string
|
||||
): Promise<{
|
||||
success: boolean
|
||||
data: {
|
||||
used_storage: number
|
||||
used_storage_formatted: string
|
||||
total_storage: number
|
||||
total_storage_formatted: string
|
||||
available_storage: number
|
||||
available_storage_formatted: string
|
||||
percentage: number
|
||||
file_count: number
|
||||
}
|
||||
message?: string
|
||||
}> => invoke("oauth_get_storage_usage", { accessToken, platformId, userId }),
|
||||
oauthSaveLoginState: (state: {
|
||||
access_token: string
|
||||
refresh_token: string
|
||||
@@ -846,3 +864,4 @@ const api = {
|
||||
|
||||
export default api
|
||||
export { api }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user