限制初始密码强制范围并修复后台图片加载
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import { fetchAdminFileBlob, fetchFileBlobByURL } from '@/shared/api/files'
|
||||
import { isAdminPath } from '@/shared/utils/adminPath'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -33,6 +34,7 @@ const failed = ref(false)
|
||||
const createdURLs: string[] = []
|
||||
|
||||
const usePreview = computed(() => !!props.previewSrcList?.length)
|
||||
const effectiveAdmin = computed(() => props.admin || isAdminPath(window.location.pathname))
|
||||
const fallbackText = computed(() => (failed.value ? '图片加载失败' : '图片加载中'))
|
||||
const imageStyleValue = computed(() => {
|
||||
if (!props.fit) return props.imageStyle
|
||||
@@ -52,18 +54,22 @@ function shouldFetchWithAuth(value: string) {
|
||||
return value.includes('/api/files/object') || value.includes('/api/admin/files/object')
|
||||
}
|
||||
|
||||
function shouldFetchAsAdmin(value: string) {
|
||||
return effectiveAdmin.value || value.includes('/api/admin/files/object')
|
||||
}
|
||||
|
||||
async function resolveURL(url: string): Promise<string> {
|
||||
if (!url || !shouldFetchWithAuth(url)) return url
|
||||
const key = extractObjectKey(url)
|
||||
const blob =
|
||||
props.admin && key ? await fetchAdminFileBlob(key) : await fetchFileBlobByURL(url)
|
||||
shouldFetchAsAdmin(url) && key ? await fetchAdminFileBlob(key) : await fetchFileBlobByURL(url)
|
||||
const blobURL = URL.createObjectURL(blob)
|
||||
createdURLs.push(blobURL)
|
||||
return blobURL
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
createdURLs.forEach((u) => URL.revokeObjectURL(u))
|
||||
createdURLs.forEach(u => URL.revokeObjectURL(u))
|
||||
createdURLs.length = 0
|
||||
}
|
||||
|
||||
@@ -88,7 +94,7 @@ async function loadImage() {
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => [props.source, props.admin, props.previewSrcList] as const, loadImage, {
|
||||
watch(() => [props.source, effectiveAdmin.value, props.previewSrcList] as const, loadImage, {
|
||||
immediate: true,
|
||||
deep: true,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user