feat(modpack): added curseforge import by url
This commit is contained in:
@@ -14,24 +14,39 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Метод импорта</label>
|
||||||
|
<div class="radio-group">
|
||||||
|
<label><input type="radio" v-model="form.importMethod" value="file" /> Файл</label>
|
||||||
|
<label
|
||||||
|
><input type="radio" v-model="form.importMethod" value="url" :disabled="form.importerType !== 'curseforge'" />
|
||||||
|
URL</label
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Поля для метаданных -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="name">Системное имя (латиница, без пробелов)</label>
|
<label for="name">Системное имя (латиница, без пробелов)</label>
|
||||||
<input id="name" v-model="form.name" type="text" required pattern="^[a-zA-Z0-9_]+$" />
|
<input id="name" v-model="form.name" type="text" required pattern="^[a-zA-Z0-9_]+$" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="displayName">Отображаемое имя</label>
|
<label for="displayName">Отображаемое имя</label>
|
||||||
<input id="displayName" v-model="form.displayName" type="text" required />
|
<input id="displayName" v-model="form.displayName" type="text" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="mcVersion">Версия Minecraft</label>
|
<label for="mcVersion">Версия Minecraft</label>
|
||||||
<input id="mcVersion" v-model="form.mcVersion" type="text" required />
|
<input id="mcVersion" v-model="form.mcVersion" type="text" required />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<!-- Поля для источника -->
|
||||||
|
<div v-if="form.importMethod === 'file'" class="form-group">
|
||||||
<label for="modpack-file">Файл модпака (.zip)</label>
|
<label for="modpack-file">Файл модпака (.zip)</label>
|
||||||
<input id="modpack-file" type="file" @change="onFileSelected" required accept=".zip" />
|
<input id="modpack-file" type="file" @change="onFileSelected" :required="form.importMethod === 'file'" accept=".zip" />
|
||||||
|
</div>
|
||||||
|
<div v-if="form.importMethod === 'url'" class="form-group">
|
||||||
|
<label for="sourceUrl">URL страницы модпака на CurseForge</label>
|
||||||
|
<input id="sourceUrl" v-model="form.sourceUrl" type="url" :required="form.importMethod === 'url'" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="error" class="error-message">{{ error }}</div>
|
<div v-if="error" class="error-message">{{ error }}</div>
|
||||||
@@ -46,7 +61,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive } from "vue";
|
import { ref, reactive, watch } from "vue";
|
||||||
import apiClient from "@/api/axios";
|
import apiClient from "@/api/axios";
|
||||||
|
|
||||||
const form = reactive({
|
const form = reactive({
|
||||||
@@ -54,13 +69,24 @@ const form = reactive({
|
|||||||
displayName: "",
|
displayName: "",
|
||||||
mcVersion: "",
|
mcVersion: "",
|
||||||
file: null as File | null,
|
file: null as File | null,
|
||||||
importerType: "simple", // Тип импортера по умолчанию
|
importerType: "simple",
|
||||||
|
importMethod: "file",
|
||||||
|
sourceUrl: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
const error = ref<string | null>(null);
|
const error = ref<string | null>(null);
|
||||||
const successMessage = ref<string | null>(null);
|
const successMessage = ref<string | null>(null);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => form.importerType,
|
||||||
|
(newType) => {
|
||||||
|
if (newType !== "curseforge" && form.importMethod === "url") {
|
||||||
|
form.importMethod = "file";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const onFileSelected = (event: Event) => {
|
const onFileSelected = (event: Event) => {
|
||||||
const target = event.target as HTMLInputElement;
|
const target = event.target as HTMLInputElement;
|
||||||
if (target.files && target.files[0]) {
|
if (target.files && target.files[0]) {
|
||||||
@@ -69,10 +95,14 @@ const onFileSelected = (event: Event) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleImport = async () => {
|
const handleImport = async () => {
|
||||||
if (!form.file) {
|
if (form.importMethod === "file" && !form.file) {
|
||||||
error.value = "Пожалуйста, выберите файл для импорта.";
|
error.value = "Пожалуйста, выберите файл для импорта.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (form.importMethod === "url" && !form.sourceUrl) {
|
||||||
|
error.value = "Пожалуйста, введите URL.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
error.value = null;
|
error.value = null;
|
||||||
@@ -82,9 +112,14 @@ const handleImport = async () => {
|
|||||||
formData.append("name", form.name);
|
formData.append("name", form.name);
|
||||||
formData.append("displayName", form.displayName);
|
formData.append("displayName", form.displayName);
|
||||||
formData.append("mcVersion", form.mcVersion);
|
formData.append("mcVersion", form.mcVersion);
|
||||||
formData.append("file", form.file);
|
|
||||||
formData.append("importerType", form.importerType);
|
formData.append("importerType", form.importerType);
|
||||||
formData.append("importMethod", "file"); // Пока поддерживаем только импорт файла
|
formData.append("importMethod", form.importMethod);
|
||||||
|
|
||||||
|
if (form.importMethod === "file" && form.file) {
|
||||||
|
formData.append("file", form.file);
|
||||||
|
} else if (form.importMethod === "url") {
|
||||||
|
formData.append("sourceUrl", form.sourceUrl);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.post("/admin/modpacks/import", formData, {
|
const response = await apiClient.post("/admin/modpacks/import", formData, {
|
||||||
@@ -122,6 +157,10 @@ const handleImport = async () => {
|
|||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
.radio-group label {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 1rem;
|
||||||
|
}
|
||||||
.error-message,
|
.error-message,
|
||||||
.success-message {
|
.success-message {
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user