Skip to content

Commit 84eb588

Browse files
Validate input URL is from civitai
1 parent 547aa7d commit 84eb588

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/platform/assets/components/UploadModelDialog.vue

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<template>
22
<div class="upload-model-dialog flex flex-col justify-between gap-6 p-4 pt-6">
33
<!-- Step 1: Enter URL -->
4-
<UploadModelUrlInput v-if="currentStep === 1" v-model="wizardData.url" />
4+
<UploadModelUrlInput
5+
v-if="currentStep === 1"
6+
v-model="wizardData.url"
7+
:error="uploadError"
8+
/>
59

610
<!-- Step 2: Confirm Metadata -->
711
<UploadModelConfirmation
@@ -73,7 +77,7 @@
7377
</template>
7478

7579
<script setup lang="ts">
76-
import { computed, onMounted, ref } from 'vue'
80+
import { computed, onMounted, ref, watch } from 'vue'
7781
7882
import IconTextButton from '@/components/button/IconTextButton.vue'
7983
import TextButton from '@/components/button/TextButton.vue'
@@ -120,6 +124,14 @@ const selectedModelType = ref<string>('loras')
120124
121125
const { modelTypes, fetchModelTypes } = useModelTypes()
122126
127+
// Clear error when URL changes
128+
watch(
129+
() => wizardData.value.url,
130+
() => {
131+
uploadError.value = ''
132+
}
133+
)
134+
123135
// Validation
124136
const canFetchMetadata = computed(() => {
125137
return wizardData.value.url.trim().length > 0
@@ -132,6 +144,24 @@ const canUploadModel = computed(() => {
132144
async function handleFetchMetadata() {
133145
if (!canFetchMetadata.value) return
134146
147+
// Validate that URL is from Civitai domain
148+
const isCivitaiUrl = (url: string): boolean => {
149+
try {
150+
const urlObj = new URL(url)
151+
return (
152+
urlObj.hostname === 'civitai.com' ||
153+
urlObj.hostname.endsWith('.civitai.com')
154+
)
155+
} catch {
156+
return false
157+
}
158+
}
159+
160+
if (!isCivitaiUrl(wizardData.value.url)) {
161+
uploadError.value = 'Only Civitai URLs are supported'
162+
return
163+
}
164+
135165
isFetchingMetadata.value = true
136166
try {
137167
const metadata = await assetService.getAssetMetadata(wizardData.value.url)

src/platform/assets/components/UploadModelUrlInput.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
:placeholder="$t('assetBrowser.civitaiLinkPlaceholder')"
2020
:disable-validation="true"
2121
/>
22-
<p class="text-xs text-muted">
22+
<p v-if="error" class="text-xs text-error">
23+
{{ error }}
24+
</p>
25+
<p v-else class="text-xs text-muted">
2326
{{ $t('assetBrowser.civitaiLinkExample') }}
2427
</p>
2528
</div>
@@ -33,6 +36,7 @@ import UrlInput from '@/components/common/UrlInput.vue'
3336
3437
const props = defineProps<{
3538
modelValue: string
39+
error?: string
3640
}>()
3741
3842
const emit = defineEmits<{

0 commit comments

Comments
 (0)