mirror of
https://github.com/KohakuBlueleaf/KohakuHub.git
synced 2026-04-30 09:28:35 -05:00
fix org<>user confusion in frontend
This commit is contained in:
@@ -109,7 +109,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from "vue";
|
import { ref, computed, onMounted } from "vue";
|
||||||
import { onBeforeRouteLeave } from "vue-router";
|
import { useRouter, useRoute, onBeforeRouteLeave } from "vue-router";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import CodeEditor from "@/components/common/CodeEditor.vue";
|
import CodeEditor from "@/components/common/CodeEditor.vue";
|
||||||
import { repoAPI } from "@/utils/api";
|
import { repoAPI } from "@/utils/api";
|
||||||
|
|||||||
@@ -155,6 +155,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { useRoute, useRouter } from "vue-router";
|
||||||
import { repoAPI, settingsAPI } from "@/utils/api";
|
import { repoAPI, settingsAPI } from "@/utils/api";
|
||||||
import { ElMessage, ElMessageBox } from "element-plus";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
|
|||||||
@@ -187,6 +187,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from "vue";
|
import { ref, computed, onMounted } from "vue";
|
||||||
|
import { useRouter, useRoute } from "vue-router";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import { repoAPI } from "@/utils/api";
|
import { repoAPI } from "@/utils/api";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
|
|||||||
@@ -400,7 +400,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { repoAPI } from "@/utils/api";
|
import { repoAPI, orgAPI } from "@/utils/api";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -448,6 +448,19 @@ function goToRepo(type, repo) {
|
|||||||
router.push(`/${type}s/${namespace}/${name}`);
|
router.push(`/${type}s/${namespace}/${name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkIfOrganization() {
|
||||||
|
try {
|
||||||
|
// Check if this name is an organization
|
||||||
|
await orgAPI.get(username.value);
|
||||||
|
// If successful, it's an organization - redirect
|
||||||
|
router.replace(`/organizations/${username.value}/${currentType.value}`);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
// Not an organization, continue as user
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadRepos() {
|
async function loadRepos() {
|
||||||
try {
|
try {
|
||||||
const [models, datasets, spaces] = await Promise.all([
|
const [models, datasets, spaces] = await Promise.all([
|
||||||
@@ -471,7 +484,12 @@ watch(currentType, () => {
|
|||||||
searchQuery.value = "";
|
searchQuery.value = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
|
// Check if this is actually an organization
|
||||||
|
const isOrg = await checkIfOrganization();
|
||||||
|
if (isOrg) return; // Already redirected
|
||||||
|
|
||||||
|
// Continue loading as user
|
||||||
loadRepos();
|
loadRepos();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -99,6 +99,13 @@
|
|||||||
|
|
||||||
<!-- Main Content -->
|
<!-- Main Content -->
|
||||||
<main class="space-y-8">
|
<main class="space-y-8">
|
||||||
|
<!-- User Card (from Username/Username space repo if exists) -->
|
||||||
|
<section v-if="userCard" class="card">
|
||||||
|
<div class="markdown-body">
|
||||||
|
<MarkdownViewer :content="userCard" />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- Models Section -->
|
<!-- Models Section -->
|
||||||
<section class="mb-8">
|
<section class="mb-8">
|
||||||
<div
|
<div
|
||||||
@@ -359,7 +366,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { repoAPI } from "@/utils/api";
|
import { repoAPI, orgAPI } from "@/utils/api";
|
||||||
|
import MarkdownViewer from "@/components/common/MarkdownViewer.vue";
|
||||||
|
import axios from "axios";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -368,6 +377,7 @@ const username = computed(() => route.params.username);
|
|||||||
|
|
||||||
const userInfo = ref(null);
|
const userInfo = ref(null);
|
||||||
const repos = ref({ model: [], dataset: [], space: [] });
|
const repos = ref({ model: [], dataset: [], space: [] });
|
||||||
|
const userCard = ref("");
|
||||||
|
|
||||||
const MAX_DISPLAYED = 6; // 2 per row × 3 rows
|
const MAX_DISPLAYED = 6; // 2 per row × 3 rows
|
||||||
|
|
||||||
@@ -392,6 +402,19 @@ function goToRepo(type, repo) {
|
|||||||
router.push(`/${type}s/${namespace}/${name}`);
|
router.push(`/${type}s/${namespace}/${name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkIfOrganization() {
|
||||||
|
try {
|
||||||
|
// Check if this name is an organization
|
||||||
|
await orgAPI.get(username.value);
|
||||||
|
// If successful, it's an organization - redirect
|
||||||
|
router.replace(`/organizations/${username.value}`);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
// Not an organization, continue as user
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadRepos() {
|
async function loadRepos() {
|
||||||
try {
|
try {
|
||||||
const [models, datasets, spaces] = await Promise.all([
|
const [models, datasets, spaces] = await Promise.all([
|
||||||
@@ -410,7 +433,25 @@ async function loadRepos() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
async function loadUserCard() {
|
||||||
|
try {
|
||||||
|
// Try to fetch README from Username/Username space repo
|
||||||
|
const url = `/spaces/${username.value}/${username.value}/resolve/main/README.md`;
|
||||||
|
const response = await axios.get(url);
|
||||||
|
userCard.value = response.data;
|
||||||
|
} catch (err) {
|
||||||
|
// No user card available - this is fine
|
||||||
|
userCard.value = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
// Check if this is actually an organization
|
||||||
|
const isOrg = await checkIfOrganization();
|
||||||
|
if (isOrg) return; // Already redirected
|
||||||
|
|
||||||
|
// Continue loading as user
|
||||||
loadRepos();
|
loadRepos();
|
||||||
|
loadUserCard();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -139,7 +139,7 @@
|
|||||||
|
|
||||||
<!-- Main Content -->
|
<!-- Main Content -->
|
||||||
<main class="space-y-8">
|
<main class="space-y-8">
|
||||||
<!-- Organization Card (from OrgName/OrgName dataset repo card if exists) -->
|
<!-- Organization Card (from OrgName/OrgName space repo card if exists) -->
|
||||||
<section v-if="orgCard" class="card">
|
<section v-if="orgCard" class="card">
|
||||||
<div class="markdown-body">
|
<div class="markdown-body">
|
||||||
<MarkdownViewer :content="orgCard" />
|
<MarkdownViewer :content="orgCard" />
|
||||||
|
|||||||
@@ -117,6 +117,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { useRoute, useRouter } from "vue-router";
|
||||||
import { orgAPI } from "@/utils/api";
|
import { orgAPI } from "@/utils/api";
|
||||||
import { ElMessage, ElMessageBox } from "element-plus";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
|
|||||||
@@ -102,6 +102,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
import { orgAPI, repoAPI, settingsAPI } from "@/utils/api";
|
import { orgAPI, repoAPI, settingsAPI } from "@/utils/api";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
|
|||||||
@@ -97,6 +97,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
import { orgAPI } from "@/utils/api";
|
import { orgAPI } from "@/utils/api";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
|
|||||||
@@ -139,6 +139,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
import { authAPI, settingsAPI } from "@/utils/api";
|
import { authAPI, settingsAPI } from "@/utils/api";
|
||||||
import { ElMessage, ElMessageBox } from "element-plus";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|||||||
Reference in New Issue
Block a user