Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Csghub file too large can not preview #786

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion frontend/src/components/shared/Blob.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</div>
</div>
<div
v-if="!lfs"
v-if="!lfs && previewCode !== 1"
class="border border-t-0 border-gray-200 rounded-b"
>
<div
Expand Down Expand Up @@ -132,6 +132,26 @@
/>
</div>
</div>
<div v-else-if="!lfs && previewCode === 1 ">
<div
class="text-xs text-gray-700 px-4 py-2 flex items-center justify-end border-b border-gray-200"
>
<div>{{ formatBytes(size) }}</div>
</div>
<div
class="flex items-center justify-center px-4 py-10 border-b border-gray-200 font-medium text-gray-500 text-sm whitespace-pre-wrap"
>
<p>
{{ $t('shared.tooLargeFile') }}
<span
class="underline cursor-pointer"
@click="normalFileDownload"
>{{ $t('shared.tooLargeFile2') }}
</span>
{{ $t('shared.tooLargeFile3') }}
</p>
</div>
</div>
<div
v-else
class="border border-t-0 border-gray-200 rounded-b"
Expand Down Expand Up @@ -233,7 +253,9 @@
const sha = ref('')
const lfsPointerSize = ref(0)
const lfsRelativePath = ref('')
const path = ref('')
const lfs = ref(false)
const previewCode =ref(0)
const size = ref(0)
const content = ref('')
const lastCommit = ref({})
Expand Down Expand Up @@ -302,6 +324,8 @@
lastCommit.value = data.commit
size.value = data.size
lfs.value = data.lfs
path.value = data.path
previewCode.value = data.preview_code ?? ''
lfsRelativePath.value = data.lfs_relative_path
lfsPointerSize.value = data.lfs_pointer_size
}
Expand Down Expand Up @@ -347,6 +371,26 @@
}
}

const normalFileDownload = async () => {
const url = `/${prefixPath}/${props.namespacePath}/download/${path.value}?ref=${props.currentBranch}`

try {
const { data, error } = await useFetchApi(url).blob()

if (error.value) {
ElMessage({
message: error.value.msg,
type: 'warning'
})
} else {
const downloadUrl = window.URL.createObjectURL(data.value)
createAndClickAnchor(downloadUrl, path.value)
}
} catch (error) {
console.error(error)
}
}

onMounted(() => {
fetchFileContent()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class="max-w-[411px] md:mb-[24px]"
:name="profileName"
></Menu>
<div class="grow flex flex-col gap-[24px] px-6 py-10 border-l md:border-l-0 min-h-[calc(100vh-153px)] min-h-auto">
<div class="grow flex flex-col gap-[24px] px-6 py-10 border-l md:border-l-0 min-h-[calc(100vh-153px)] md:min-h-0">
<div class="max-w-[512px]">
<div class="mb-[16px]">
<h3 class="mb-[4px] text-gray-700 text-xl font-semibold">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/user_settings/SshKeySettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:name="name"
>
</Menu>
<div class="grow flex flex-col gap-[24px] px-6 py-10 border-l md:border-l-0 min-h-[calc(100vh-153px)] min-h-auto">
<div class="grow flex flex-col gap-[24px] px-6 py-10 border-l md:border-l-0 min-h-[calc(100vh-153px)] md:min-h-0">
<h3 class="text-gray-700 text-xl font-[600]">SSH Keys</h3>
<button
@click="centerDialogVisible = true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</Menu>

<!-- API Key list -->
<div class="grow flex flex-col gap-[24px] px-6 py-10 border-l md:border-l-0 min-h-[calc(100vh-153px)] min-h-auto">
<div class="grow flex flex-col gap-[24px] px-6 py-10 border-l md:border-l-0 min-h-[calc(100vh-153px)] md:min-h-0">
<div class="max-w-[512px]">
<div class="mb-[16px]">
<h3 class="mb-[4px] text-gray-700 text-xl font-semibold">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:name="name"
>
</Menu>
<div class="grow flex flex-col gap-[24px] px-6 py-10 border-l border-l-0 min-h-[calc(100vh-153px)] min-h-auto">
<div class="grow flex flex-col gap-[24px] px-6 py-10 border-l border-l-0 min-h-[calc(100vh-153px)] md:min-h-0">
<div class="max-w-[512px]">
<div class="mb-[16px]">
<h3 class="mb-[4px] text-gray-700 text-xl font-semibold">
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/locales/en_js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ export const shared = {
preview: "Preview",
edit: "Edit",
likes: "Likes",
hasLikes: "Liked"
hasLikes: "Liked",
tooLargeFile:"File too large to display,you can check the",
tooLargeFile2:"raw version",
tooLargeFile3:"instead"
}
6 changes: 5 additions & 1 deletion frontend/src/locales/zh_js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ export const shared = {
preview: "预览",
edit: "编辑",
likes: "收藏",
hasLikes: "已收藏"
hasLikes: "已收藏",
tooLargeFile: "文件过大无法显示,您可以查看",
tooLargeFile2: "原始版本",
tooLargeFile3:""

}
Loading