Skip to content

Commit 161ec43

Browse files
committed
feat: upload toolset resource user auth
1 parent 589b2c9 commit 161ec43

File tree

31 files changed

+199
-115
lines changed

31 files changed

+199
-115
lines changed

components/content/ProseImg.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script setup lang="ts">
22
import { withTrailingSlash, withLeadingSlash, joinURL } from 'ufo'
3-
import { useRuntimeConfig, computed } from '#imports'
43
54
import ImageComponent from '#build/mdc-image-component.mjs'
65

components/kun/progress/Progress.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@ const circleOffset = computed(
144144
:class="[sizeClasses, roundedClasses, className]"
145145
>
146146
<div
147-
:class="[barClasses, 'h-full transition-all duration-500 ease-out']"
147+
:class="
148+
cn(
149+
'flex h-full items-center transition-all duration-500 ease-out',
150+
barClasses
151+
)
152+
"
148153
:style="indeterminate ? 'width:100%' : `width:${percentage}%`"
149154
>
150155
<span

components/kun/top-bar/TopBar.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script setup lang="ts">
2-
import { KunTopBarNav } from '#components'
3-
42
withDefaults(
53
defineProps<{
64
className?: string

components/toolset/Detail.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ const loadPracticalityMine = async () => {
9090
onMounted(loadPracticalityMine)
9191
9292
const handleSetStar = async (val: number) => {
93+
if (!uid) {
94+
useMessage('请登陆后再评分, 否则我们无法统计数据', 'warn', 7000)
95+
return
96+
}
9397
isSubmittingRate.value = true
9498
await $fetch(`/api/toolset/${props.id}/practicality`, {
9599
method: 'PUT',
@@ -225,7 +229,7 @@ const handleResourceUpdated = (res: ToolsetResource) => {
225229
{{ `${formatNumber(data.download)} 下载` }}
226230
</div>
227231
<div class="flex gap-1">
228-
<KunButton @click="handlePublishResource">上传/添加资源</KunButton>
232+
<KunButton @click="handlePublishResource">上传 / 添加资源</KunButton>
229233
<KunButton
230234
v-if="canManageToolset"
231235
variant="flat"
@@ -272,14 +276,11 @@ const handleResourceUpdated = (res: ToolsetResource) => {
272276
@update:modal-value="(v) => (showResourceModal = v)"
273277
:is-dismissable="false"
274278
>
275-
<div class="max-w-2xl">
276-
<h3 class="mb-3 text-lg font-semibold">发布资源</h3>
277-
<ToolsetResourceContainer
278-
:toolset-id="data.id"
279-
@on-close="() => (showResourceModal = false)"
280-
@on-success="(value) => data!.resource.push(value)"
281-
/>
282-
</div>
279+
<ToolsetResourceContainer
280+
:toolset-id="data.id"
281+
@on-close="() => (showResourceModal = false)"
282+
@on-success="(value) => data!.resource.push(value)"
283+
/>
283284
</KunModal>
284285
</div>
285286
</template>

components/toolset/card/Container.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { data, status } = await useFetch(`/api/toolset`, {
1212
<div v-if="data" class="flex flex-col gap-3">
1313
<KunCard class-name="z-10" :is-hoverable="false" :is-transparent="false">
1414
<KunHeader
15-
name="Galgame 工具集"
15+
name="Galgame 工具资源下载"
1616
description="收录 Galgame 相关工具:模拟器、翻译器、提取器等"
1717
:is-show-divider="false"
1818
>
Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
import { USER_DAILY_UPLOAD_LIMIT } from '~/config/upload'
23
import type {
34
ToolsetUploadCompleteResponse,
45
ToolsetResource
@@ -13,44 +14,92 @@ const emits = defineEmits<{
1314
onSuccess: [ToolsetResource]
1415
}>()
1516
17+
const { moemoepoint, dailyToolsetUploadCount } = storeToRefs(
18+
usePersistUserStore()
19+
)
20+
21+
const MB = 1024 * 1024
22+
1623
const mode = ref<'s3' | 'user'>('s3')
1724
const uploadResult = ref<ToolsetUploadCompleteResponse>({
1825
salt: '',
1926
key: '',
20-
filesize: 0
27+
filesize: 0,
28+
dailyToolsetUploadCount: 0
2129
})
30+
31+
const handleUploadSuccess = (value: ToolsetUploadCompleteResponse) => {
32+
uploadResult.value = value
33+
dailyToolsetUploadCount.value = value.dailyToolsetUploadCount
34+
}
2235
</script>
2336

2437
<template>
25-
<div class="z-10 space-y-4">
26-
<div class="flex items-center gap-6">
27-
<KunCheckBox
28-
type="single"
29-
:model-value="mode === 's3'"
30-
label="对象存储 (S3)"
31-
@change="() => (mode = 's3')"
32-
/>
33-
<KunCheckBox
34-
type="single"
35-
:model-value="mode === 'user'"
36-
label="自定义链接"
37-
@change="() => (mode = 'user')"
38+
<div class="max-w-2xl space-y-3">
39+
<h3 class="mb-3 text-lg font-semibold">发布资源</h3>
40+
41+
<KunLink to="/doc">发布 Galgame 工具下载资源规定</KunLink>
42+
43+
<div class="flex flex-col gap-1">
44+
<p class="text-default-700 text-sm">
45+
您今日已使用存储量
46+
{{
47+
`${(dailyToolsetUploadCount / MB).toFixed(3)} / ${USER_DAILY_UPLOAD_LIMIT / MB + moemoepoint} MB`
48+
}}
49+
</p>
50+
<KunProgress
51+
:value="Math.floor(dailyToolsetUploadCount / USER_DAILY_UPLOAD_LIMIT)"
52+
:show-label="true"
53+
size="lg"
3854
/>
3955
</div>
4056

41-
<ToolsetResourceUpload
42-
v-if="mode === 's3'"
43-
:toolset-id="props.toolsetId"
44-
@on-close="emits('onClose')"
45-
@on-upload-success="(value) => (uploadResult = value)"
46-
/>
47-
48-
<ToolsetResourceLinkForm
49-
:toolset-id="props.toolsetId"
50-
:type="mode"
51-
:upload-result="uploadResult"
52-
@on-close="emits('onClose')"
53-
@on-success="(value) => emits('onSuccess', value)"
54-
/>
57+
<KunInfo title="注意事项简要说明" color="info">
58+
<div class="flex flex-col gap-2">
59+
<p class="font-bold">
60+
1. 禁止在此页面上传游戏资源, 违规直接永久封禁账号
61+
</p>
62+
<p>2. 第一次发布资源前请对自己的设备查毒, 以免大量用户感染病毒</p>
63+
<p>3. 请注意工具资源的所有权, 作者明确禁止转载的资源请勿上传</p>
64+
<p>
65+
4. 发布一个工具资源您将获得 3 萌萌点, 删除一个工具将会扣除 3 萌萌点
66+
</p>
67+
<p>5. 每名用户每天有 (100 + 您的萌萌点数) MB 的上传额度, 每天会重置</p>
68+
<p>6. 每名用户的最大上传文件大小为 2GB</p>
69+
<p>7. 上传速度完全取决于您的网络情况, 网络不佳请使用代理</p>
70+
</div>
71+
</KunInfo>
72+
73+
<div class="z-10 space-y-4">
74+
<div class="flex items-center gap-6">
75+
<KunCheckBox
76+
type="single"
77+
:model-value="mode === 's3'"
78+
label="对象存储 (S3)"
79+
@change="() => (mode = 's3')"
80+
/>
81+
<KunCheckBox
82+
type="single"
83+
:model-value="mode === 'user'"
84+
label="自定义链接"
85+
@change="() => (mode = 'user')"
86+
/>
87+
</div>
88+
89+
<ToolsetResourceUpload
90+
v-if="mode === 's3'"
91+
:toolset-id="props.toolsetId"
92+
@on-close="emits('onClose')"
93+
@on-upload-success="handleUploadSuccess"
94+
/>
95+
96+
<ToolsetResourceLinkForm
97+
:toolset-id="props.toolsetId"
98+
:type="mode"
99+
:upload-result="uploadResult"
100+
@on-close="emits('onClose')"
101+
@on-success="(value) => emits('onSuccess', value)"
102+
/>
103+
</div>
55104
</div>
56105
</template>

components/toolset/resource/Upload.vue

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<script setup lang="ts">
2-
import { MAX_SMALL_FILE_SIZE } from '~/config/upload'
2+
import {
3+
MAX_SMALL_FILE_SIZE,
4+
MAX_LARGE_FILE_SIZE,
5+
USER_DAILY_UPLOAD_LIMIT
6+
} from '~/config/upload'
37
import {
48
initToolsetUploadSchema,
59
completeToolsetUploadSchema,
@@ -20,18 +24,29 @@ const emits = defineEmits<{
2024
onClose: []
2125
}>()
2226
27+
const MB = 1024 * 1024
28+
29+
const { moemoepoint, dailyToolsetUploadCount } = storeToRefs(
30+
usePersistUserStore()
31+
)
2332
const fileInput = ref<HTMLInputElement>()
2433
const selectedFile = ref<File | null>(null)
2534
2635
const progress = ref(0)
36+
const isDragging = ref(false)
2737
const uploadStatus =
2838
ref<(typeof KUN_GALGAME_TOOLSET_UPLOAD_STATUS_CONST)[number]>('idle')
29-
const isDragging = ref(false)
3039
3140
const isLarge = computed(() => {
3241
const f = selectedFile.value
3342
return !!f && f.size > MAX_SMALL_FILE_SIZE
3443
})
44+
const userUploadLimit = computed(
45+
() =>
46+
USER_DAILY_UPLOAD_LIMIT +
47+
moemoepoint.value * MB -
48+
dailyToolsetUploadCount.value
49+
)
3550
3651
const statusMessage = computed(() => {
3752
if (uploadStatus.value === 'largeUploading') {
@@ -41,12 +56,37 @@ const statusMessage = computed(() => {
4156
}
4257
})
4358
59+
const checkFileValid = (file: File | null) => {
60+
if (!file) {
61+
return false
62+
}
63+
if (!isValidArchive(file.name || '')) {
64+
useMessage('我们仅支持 .7z, .zip, .rar 压缩格式上传', 'warn')
65+
return false
66+
}
67+
if (file.size > MAX_LARGE_FILE_SIZE) {
68+
useMessage(
69+
`文件大小超过最大文件限制 ${MAX_LARGE_FILE_SIZE / MB} MB`,
70+
'warn'
71+
)
72+
return false
73+
}
74+
if (file.size > userUploadLimit.value) {
75+
useMessage(
76+
`文件大小超过您的可用上传额度 ${(userUploadLimit.value / MB).toFixed(1)} MB`,
77+
'warn'
78+
)
79+
return false
80+
}
81+
return true
82+
}
83+
4484
const pick = () => fileInput.value?.click()
4585
const onChange = (e: Event) => {
4686
const t = e.target as HTMLInputElement
4787
const targetFile = t.files && t.files[0] ? t.files[0] : null
48-
if (!isValidArchive(targetFile?.name || '')) {
49-
useMessage('我们仅支持 .7z, .zip, .rar 压缩格式上传', 'warn')
88+
const res = checkFileValid(targetFile)
89+
if (!res) {
5090
return
5191
}
5292
selectedFile.value = targetFile
@@ -57,8 +97,8 @@ const onDrop = (e: DragEvent) => {
5797
isDragging.value = false
5898
const dt = e.dataTransfer
5999
if (dt?.files && dt.files.length > 0) {
60-
if (!isValidArchive(dt.files[0].name || '')) {
61-
useMessage('我们仅支持 .7z, .zip, .rar 压缩格式上传', 'warn')
100+
const res = checkFileValid(dt.files[0])
101+
if (!res) {
62102
return
63103
}
64104
selectedFile.value = dt.files[0]
@@ -313,19 +353,12 @@ const submit = async () => {
313353
>
314354
{{
315355
isLarge
316-
? `文件大于 ${MAX_SMALL_FILE_SIZE / (1024 * 1024)}MB, 分片上传`
317-
: `文件小于 ${MAX_SMALL_FILE_SIZE / (1024 * 1024)}MB, 直接上传`
356+
? `文件大于 ${MAX_SMALL_FILE_SIZE / MB}MB, 分片上传`
357+
: `文件小于 ${MAX_SMALL_FILE_SIZE / MB}MB, 直接上传`
318358
}}
319359
</span>
320360
</div>
321361

322-
<!-- <div class="bg-default-200 h-2 w-full rounded">
323-
<div
324-
class="bg-primary-500 h-2 rounded"
325-
:style="{ width: `${progress}%` }"
326-
/>
327-
</div> -->
328-
329362
<KunProgress :value="progress" />
330363

331364
<div

config/upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const KUN_VISUAL_NOVEL_IMAGE_COMPRESS_LIMIT = 1.007
44
export const LARGE_FILE_CHUNK_SIZE = 5 * 1024 * 1024
55

66
export const MAX_SMALL_FILE_SIZE = 50 * 1024 * 1024
7-
export const MAX_LARGE_FILE_SIZE = 5 * 1024 * 1024 * 1024
7+
export const MAX_LARGE_FILE_SIZE = 2 * 1024 * 1024 * 1024
88

99
export const USER_DAILY_UPLOAD_LIMIT = 100 * 1024 * 1024
1010
export const KUN_VISUAL_NOVEL_USER_DAILY_UPLOAD_IMAGE_LIMIT = 50

constants/toolset.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ import type { KunSelectOption } from '~/components/kun/select/type'
33
export const KUN_GALGAME_TOOLSET_TYPE_MAP: Record<string, string> = {
44
name: '工具类型',
55
all: '全部类型',
6-
emulator: '模拟器相关 (KRKR 等)',
7-
translator: '翻译相关 (翻译器, 文本 Hook, OCR 等)',
6+
emulator: '模拟器相关',
7+
translator: '翻译相关',
88
extractor: '解包工具',
9-
converter: '资源转换 (音频/图片/字体)',
9+
converter: '资源转换工具',
1010
engine: '引擎相关工具',
1111
debug: '开发者工具',
1212
launcher: '游戏管理工具',
1313
script: '自动化脚本',
14-
docs: '文档相关 (指南, 社区资源 等)',
14+
docs: '文档相关',
1515
others: '其它'
1616
}
1717
export const kunGalgameToolsetTypeOptions: KunSelectOption[] = [
1818
{ value: 'all', label: '全部类型' },
19-
{ value: 'emulator', label: '模拟器相关 (KRKR 等)' },
20-
{ value: 'translator', label: '翻译相关 (翻译器, Hook 等)' },
19+
{ value: 'emulator', label: '模拟器相关' },
20+
{ value: 'translator', label: '翻译相关' },
2121
{ value: 'extractor', label: '解包工具' },
22-
{ value: 'converter', label: '资源转换 (音频/图片/字体)' },
22+
{ value: 'converter', label: '资源转换工具' },
2323
{ value: 'engine', label: '引擎相关工具' },
2424
{ value: 'debug', label: '开发者工具' },
2525
{ value: 'launcher', label: '游戏管理工具' },
2626
{ value: 'script', label: '自动化脚本' },
27-
{ value: 'docs', label: '文档相关 (指南, 社区资源 等)' },
27+
{ value: 'docs', label: '文档相关' },
2828
{ value: 'others', label: '其它' }
2929
]
3030
export const KUN_TOOLSET_TYPE_CONST = [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kun-galgame-nuxt3",
3-
"version": "4.4.6",
3+
"version": "4.4.7",
44
"packageManager": "[email protected]",
55
"private": true,
66
"scripts": {

0 commit comments

Comments
 (0)