mirror of
https://github.com/keven1024/015.git
synced 2026-06-07 21:04:33 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3001ea3250 | ||
|
|
1b12703b90 | ||
|
|
e4bb9781f7 | ||
|
|
943a5a76d2 | ||
|
|
71147451bb | ||
|
|
3d88c68ed5 | ||
|
|
338e22dfca | ||
|
|
464dba2546 | ||
|
|
a3dd28dd92 | ||
|
|
9fd4943bb6 |
@@ -13,8 +13,10 @@ require (
|
|||||||
github.com/matoous/go-nanoid/v2 v2.1.0
|
github.com/matoous/go-nanoid/v2 v2.1.0
|
||||||
github.com/redis/go-redis/v9 v9.7.3
|
github.com/redis/go-redis/v9 v9.7.3
|
||||||
github.com/samber/lo v1.50.0
|
github.com/samber/lo v1.50.0
|
||||||
|
github.com/spf13/cast v1.7.1
|
||||||
github.com/spf13/viper v1.20.1
|
github.com/spf13/viper v1.20.1
|
||||||
go.uber.org/zap v1.27.0
|
go.uber.org/zap v1.27.0
|
||||||
|
golang.org/x/crypto v0.39.0
|
||||||
golang.org/x/time v0.11.0
|
golang.org/x/time v0.11.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,16 +37,14 @@ require (
|
|||||||
github.com/sagikazarmark/locafero v0.7.0 // indirect
|
github.com/sagikazarmark/locafero v0.7.0 // indirect
|
||||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
github.com/spf13/afero v1.12.0 // indirect
|
github.com/spf13/afero v1.12.0 // indirect
|
||||||
github.com/spf13/cast v1.7.1 // indirect
|
|
||||||
github.com/spf13/pflag v1.0.6 // indirect
|
github.com/spf13/pflag v1.0.6 // indirect
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/crypto v0.36.0 // indirect
|
|
||||||
golang.org/x/net v0.37.0 // indirect
|
golang.org/x/net v0.37.0 // indirect
|
||||||
golang.org/x/sys v0.31.0 // indirect
|
golang.org/x/sys v0.33.0 // indirect
|
||||||
golang.org/x/text v0.23.0 // indirect
|
golang.org/x/text v0.26.0 // indirect
|
||||||
google.golang.org/protobuf v1.36.5 // indirect
|
google.golang.org/protobuf v1.36.5 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -90,15 +90,15 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
|||||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||||
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
|
||||||
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
|
||||||
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
|
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
|
||||||
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||||
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
|
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
|
||||||
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
||||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||||
|
|||||||
@@ -72,8 +72,17 @@ func VaildateShare(c echo.Context) error {
|
|||||||
if shareInfo == nil {
|
if shareInfo == nil {
|
||||||
return utils.HTTPErrorHandler(c, errors.New("分享不存在"))
|
return utils.HTTPErrorHandler(c, errors.New("分享不存在"))
|
||||||
}
|
}
|
||||||
if shareInfo.Password != "" && shareInfo.Password != r.Password {
|
if shareInfo.Password != "" {
|
||||||
return utils.HTTPErrorHandler(c, errors.New("分享密码错误"))
|
if r.Password == "" {
|
||||||
|
return utils.HTTPErrorHandler(c, errors.New("缺少分享密码"))
|
||||||
|
}
|
||||||
|
hash, err := utils.GeneratePasswordHash(r.Password)
|
||||||
|
if err != nil {
|
||||||
|
return utils.HTTPErrorHandler(c, err)
|
||||||
|
}
|
||||||
|
if hash != shareInfo.Password {
|
||||||
|
return utils.HTTPErrorHandler(c, errors.New("分享密码错误"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 如果下载次数为0,则设置为-1 防止空值问题
|
// 如果下载次数为0,则设置为-1 防止空值问题
|
||||||
if shareInfo.ViewNum < 1 {
|
if shareInfo.ViewNum < 1 {
|
||||||
|
|||||||
@@ -64,17 +64,25 @@ func CreateShareInfo(c echo.Context) error {
|
|||||||
return utils.HTTPErrorHandler(c, errors.New("分享文件状态错误"))
|
return utils.HTTPErrorHandler(c, errors.New("分享文件状态错误"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
password := ""
|
||||||
|
if r.Config.Password != "" {
|
||||||
|
hash, err := utils.GeneratePasswordHash(r.Config.Password)
|
||||||
|
if err != nil {
|
||||||
|
return utils.HTTPErrorHandler(c, err)
|
||||||
|
}
|
||||||
|
password = hash
|
||||||
|
}
|
||||||
|
|
||||||
models.SetRedisShareInfo(id, models.RedisShareInfo{
|
models.SetRedisShareInfo(id, models.RedisShareInfo{
|
||||||
Data: r.Data,
|
Data: r.Data,
|
||||||
Type: r.Type,
|
Type: r.Type,
|
||||||
CreatedAt: time.Now().Unix(),
|
CreatedAt: time.Now().Unix(),
|
||||||
Owner: cc.Auth.(string),
|
Owner: cc.Auth.(string),
|
||||||
ViewNum: r.Config.ViewNum,
|
ViewNum: r.Config.ViewNum,
|
||||||
Password: r.Config.Password,
|
Password: password,
|
||||||
NotifyEmail: r.Config.NotifyEmail,
|
// NotifyEmail: r.Config.NotifyEmail,
|
||||||
FileName: r.FileName,
|
FileName: r.FileName,
|
||||||
ExpireAt: ExpireTime.Unix(),
|
ExpireAt: ExpireTime.Unix(),
|
||||||
})
|
})
|
||||||
var pickupCode string
|
var pickupCode string
|
||||||
if r.Config.HasPickupCode {
|
if r.Config.HasPickupCode {
|
||||||
@@ -153,6 +161,7 @@ func GetShareInfo(c echo.Context) error {
|
|||||||
"type": shareInfo.Type,
|
"type": shareInfo.Type,
|
||||||
"name": shareInfo.FileName,
|
"name": shareInfo.FileName,
|
||||||
"download_nums": shareInfo.ViewNum,
|
"download_nums": shareInfo.ViewNum,
|
||||||
|
"has_password": shareInfo.Password != "",
|
||||||
"expire_at": shareInfo.ExpireAt,
|
"expire_at": shareInfo.ExpireAt,
|
||||||
"owner": shareInfo.Owner,
|
"owner": shareInfo.Owner,
|
||||||
"size": fileInfo.FileSize,
|
"size": fileInfo.FileSize,
|
||||||
@@ -165,6 +174,7 @@ func GetShareInfo(c echo.Context) error {
|
|||||||
"type": shareInfo.Type,
|
"type": shareInfo.Type,
|
||||||
"name": shareInfo.FileName,
|
"name": shareInfo.FileName,
|
||||||
"download_nums": shareInfo.ViewNum,
|
"download_nums": shareInfo.ViewNum,
|
||||||
|
"has_password": shareInfo.Password != "",
|
||||||
"expire_at": shareInfo.ExpireAt,
|
"expire_at": shareInfo.ExpireAt,
|
||||||
"owner": shareInfo.Owner,
|
"owner": shareInfo.Owner,
|
||||||
})
|
})
|
||||||
|
|||||||
17
backend/internal/utils/password.go
Normal file
17
backend/internal/utils/password.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/argon2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GeneratePasswordHash(password string) (string, error) {
|
||||||
|
salt := GetEnv("PASSWORD_SALT")
|
||||||
|
if salt == "" {
|
||||||
|
return "", errors.New("请配置PASSWORD_SALT")
|
||||||
|
}
|
||||||
|
hash := argon2.IDKey([]byte(password), []byte(salt), 1, 64*1024, 4, 32)
|
||||||
|
return fmt.Sprintf("%x", hash), nil
|
||||||
|
}
|
||||||
39
front/components/Drawer/PasswallShareDrawer.vue
Normal file
39
front/components/Drawer/PasswallShareDrawer.vue
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import VeeForm from '@/components/VeeForm.vue'
|
||||||
|
import FormButton from '@/components/Field/FormButton.vue'
|
||||||
|
import InputField from '@/components/Field/InputField.vue'
|
||||||
|
import type { FormContext, GenericObject } from 'vee-validate'
|
||||||
|
import { toast } from 'vue-sonner'
|
||||||
|
const props = defineProps<{
|
||||||
|
share_id: string
|
||||||
|
hide: any
|
||||||
|
}>()
|
||||||
|
const { getShareToken } = useMyAppShare()
|
||||||
|
|
||||||
|
const handleSubmit = async (form: FormContext<GenericObject, GenericObject>) => {
|
||||||
|
try {
|
||||||
|
const password = form.values.password
|
||||||
|
const token = await getShareToken(props.share_id, { password })
|
||||||
|
if (!token) {
|
||||||
|
toast.error('密码错误')
|
||||||
|
form.resetForm()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
props?.hide(token)
|
||||||
|
return
|
||||||
|
} catch (error) {
|
||||||
|
toast.error('密码错误')
|
||||||
|
form.resetForm()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<VeeForm>
|
||||||
|
<div class="flex flex-col gap-5">
|
||||||
|
<div class="text-xl font-bold">输入密码</div>
|
||||||
|
<InputField name="password" type="password" rules="required" placeholder="请输入密码" />
|
||||||
|
<FormButton @click="handleSubmit">提交</FormButton>
|
||||||
|
</div>
|
||||||
|
</VeeForm>
|
||||||
|
</template>
|
||||||
@@ -1,17 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<Field :name="props.name" v-slot="{ field }">
|
<Field :name="props.name" v-slot="{ field }">
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<Label v-if="props.label">{{ props.label }}</Label>
|
<Label v-if="props.label">{{ props.label }}</Label>
|
||||||
<Input v-bind="field" :placeholder="props.placeholder" :class="props.class" />
|
<Input v-bind="{ ...field, ...$attrs }" />
|
||||||
</div>
|
</div>
|
||||||
</Field>
|
</Field>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
name: string
|
name: string
|
||||||
label?: string
|
label?: string
|
||||||
placeholder?: string
|
|
||||||
class?: string
|
|
||||||
}>()
|
}>()
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import { Drawer, DrawerContent } from '@/components/ui/drawer'
|
||||||
Drawer,
|
|
||||||
DrawerContent,
|
|
||||||
} from '@/components/ui/drawer'
|
|
||||||
import { createVNode } from 'vue'
|
import { createVNode } from 'vue'
|
||||||
import useStore from '@/composables/useStore'
|
import useStore from '@/composables/useStore'
|
||||||
|
|
||||||
@@ -10,24 +7,29 @@ const store = useStore('drawer')
|
|||||||
const drawer = computed(() => store?._get('drawer'))
|
const drawer = computed(() => store?._get('drawer'))
|
||||||
const currentDrawer = computed(() => drawer?.value?.[drawer?.value?.length - 1])
|
const currentDrawer = computed(() => drawer?.value?.[drawer?.value?.length - 1])
|
||||||
|
|
||||||
const render = computed(() => currentDrawer?.value?.render)
|
const render = computed<() => Component>(() => currentDrawer?.value?.render)
|
||||||
|
const hide = computed<() => void>(() => currentDrawer?.value?.onClose)
|
||||||
const Children = () =>
|
const Children = () =>
|
||||||
createVNode(render.value, {
|
createVNode(render.value, {
|
||||||
hide: () => store?._set('drawer', drawer?.value?.slice(0, -1)),
|
hide: hide?.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Drawer :open="!!store?._get('drawer')?.[store?._get('drawer')?.length - 1]" @update:open="(open) => {
|
<Drawer
|
||||||
if (!open && drawer?.length > 0) {
|
:open="!!drawer?.[drawer?.length - 1]"
|
||||||
store?._set('drawer', drawer?.slice(0, -1))
|
@update:open="
|
||||||
}
|
(open) => {
|
||||||
}">
|
if (!open && drawer?.length > 0) {
|
||||||
<DrawerContent>
|
hide()
|
||||||
<div class="mx-auto w-full max-w-sm pb-10">
|
}
|
||||||
<Children />
|
}
|
||||||
</div>
|
"
|
||||||
</DrawerContent>
|
>
|
||||||
</Drawer>
|
<DrawerContent>
|
||||||
</template>
|
<div class="mx-auto w-full max-w-sm pb-10">
|
||||||
|
<Children />
|
||||||
|
</div>
|
||||||
|
</DrawerContent>
|
||||||
|
</Drawer>
|
||||||
|
</template>
|
||||||
|
|||||||
@@ -1,193 +1,166 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useQuery } from "@tanstack/vue-query";
|
import { useQuery } from '@tanstack/vue-query'
|
||||||
import { AsyncButton, Button } from "@/components/ui/button";
|
import { AsyncButton, Button } from '@/components/ui/button'
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from '@/components/ui/skeleton'
|
||||||
import { filesize } from "filesize";
|
import { filesize } from 'filesize'
|
||||||
import useMyAppShare from "@/composables/useMyAppShare";
|
import useMyAppShare from '@/composables/useMyAppShare'
|
||||||
import { toast } from "vue-sonner";
|
import { toast } from 'vue-sonner'
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(e: "change", key: string): void;
|
(e: 'change', key: string): void
|
||||||
}>();
|
}>()
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
data: { file: File; config: any; handle_type: string; file_id: string };
|
data: { file: File; config: any; handle_type: string; file_id: string }
|
||||||
}>();
|
}>()
|
||||||
|
|
||||||
const { data } = useQuery({
|
const { data } = useQuery({
|
||||||
queryKey: ["create-image-compress", props?.data?.file_id],
|
queryKey: ['create-image-compress', props?.data?.file_id],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const { file_id } = props?.data || {};
|
const { file_id } = props?.data || {}
|
||||||
const data = await $fetch<{
|
const data = await $fetch<{
|
||||||
code: number;
|
code: number
|
||||||
data: {
|
data: {
|
||||||
id?: string;
|
id?: string
|
||||||
};
|
}
|
||||||
}>(`/api/image/compress`, {
|
}>(`/api/image/compress`, {
|
||||||
method: "POST",
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
file_id,
|
file_id,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
return data?.data;
|
return data?.data
|
||||||
},
|
},
|
||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
});
|
})
|
||||||
|
|
||||||
const taskId = computed(() => data?.value?.id);
|
const taskId = computed(() => data?.value?.id)
|
||||||
|
|
||||||
const { data: taskData, refetch } = useQuery({
|
const { data: taskData, refetch } = useQuery({
|
||||||
queryKey: ["image-compress-task", taskId],
|
queryKey: ['image-compress-task', taskId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const data = await $fetch<{
|
const data = await $fetch<{
|
||||||
code: number;
|
code: number
|
||||||
data: {
|
data: {
|
||||||
result: {
|
result: {
|
||||||
old_file: {
|
old_file: {
|
||||||
id: string;
|
id: string
|
||||||
size: number;
|
size: number
|
||||||
};
|
}
|
||||||
new_file: {
|
new_file: {
|
||||||
id: string;
|
id: string
|
||||||
size: number;
|
size: number
|
||||||
};
|
}
|
||||||
}[];
|
}[]
|
||||||
status: "success" | "retry" | "archived";
|
status: 'success' | 'retry' | 'archived'
|
||||||
err?: {
|
err?: {
|
||||||
message?: string;
|
message?: string
|
||||||
retry?: number;
|
retry?: number
|
||||||
max_retry?: number;
|
max_retry?: number
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
}>(`/api/image/compress/${taskId.value}`);
|
}>(`/api/image/compress/${taskId.value}`)
|
||||||
return data?.data;
|
return data?.data
|
||||||
},
|
},
|
||||||
enabled: !!taskId.value,
|
enabled: !!taskId.value,
|
||||||
});
|
})
|
||||||
|
|
||||||
const { downloadFile, createFileShare } = useMyAppShare();
|
const { downloadFileByShareId, createFileShare } = useMyAppShare()
|
||||||
|
|
||||||
const { counter, pause } = useInterval(2000, { controls: true });
|
const { counter, pause } = useInterval(2000, { controls: true })
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => counter.value,
|
() => counter.value,
|
||||||
() => {
|
() => {
|
||||||
if (["success", "archived"].includes(taskData.value?.status ?? "")) {
|
if (['success', 'archived'].includes(taskData.value?.status ?? '')) {
|
||||||
pause();
|
pause()
|
||||||
return;
|
return
|
||||||
|
}
|
||||||
|
refetch()
|
||||||
}
|
}
|
||||||
refetch();
|
)
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => taskData.value?.err?.retry,
|
() => taskData.value?.err?.retry,
|
||||||
(newVal, oldVal) => {
|
(newVal, oldVal) => {
|
||||||
if (!oldVal || !newVal || !taskData.value?.err?.max_retry) {
|
if (!oldVal || !newVal || !taskData.value?.err?.max_retry) {
|
||||||
return;
|
return
|
||||||
|
}
|
||||||
|
if (newVal <= taskData.value?.err?.max_retry) {
|
||||||
|
toast.error(`处理错误: ${taskData.value?.err?.message}, 将再次重试`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (newVal <= taskData.value?.err?.max_retry) {
|
)
|
||||||
toast.error(`处理错误: ${taskData.value?.err?.message}, 将再次重试`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col gap-3">
|
<div class="flex flex-col gap-3">
|
||||||
<h2 class="text-lg">上传成功</h2>
|
<h2 class="text-lg">上传成功</h2>
|
||||||
<div class="flex flex-col gap-1 items-center">
|
<div class="flex flex-col gap-1 items-center">
|
||||||
<div class="flex flex-col h-30 items-center justify-center">
|
<div class="flex flex-col h-30 items-center justify-center">
|
||||||
<FilePreviewView :value="props?.data?.file" />
|
<FilePreviewView :value="props?.data?.file" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-if="taskData?.status === 'success'"
|
|
||||||
class="flex flex-col gap-2"
|
|
||||||
v-for="item in taskData?.result"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="bg-white/80 p-2 rounded-md w-full flex flex-row items-center justify-between gap-2"
|
|
||||||
>
|
|
||||||
<div class="flex flex-row gap-2 items-center max-w-2/3">
|
|
||||||
<div
|
|
||||||
class="flex flex-row items-center justify-center rounded-md bg-black/5 p-2"
|
|
||||||
>
|
|
||||||
<LucideImage />
|
|
||||||
</div>
|
|
||||||
<div class="truncate w-auto">{{ props?.data?.file?.name }}</div>
|
|
||||||
<div class="flex flex-row gap-2 items-center text-sm shrink-0">
|
|
||||||
<span class="opacity-75">{{
|
|
||||||
filesize(item.new_file.size ?? 0)
|
|
||||||
}}</span>
|
|
||||||
<span
|
|
||||||
class="bg-green-200 text-green-600 rounded-md px-1 py-0.5 flex flex-row gap-1 items-center text-xs"
|
|
||||||
>
|
|
||||||
<LucideChevronDown class="size-4" />
|
|
||||||
{{
|
|
||||||
((1 - item.new_file.size / item.old_file.size) * 100).toFixed(
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
}}%
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<AsyncButton
|
<div v-if="taskData?.status === 'success'" class="flex flex-col gap-2" v-for="item in taskData?.result">
|
||||||
variant="outline"
|
<div class="bg-white/80 p-2 rounded-md w-full flex flex-row items-center justify-between gap-2">
|
||||||
class="bg-black/5"
|
<div class="flex flex-row gap-2 items-center max-w-2/3">
|
||||||
size="icon"
|
<div class="flex flex-row items-center justify-center rounded-md bg-black/5 p-2">
|
||||||
@click="
|
<LucideImage />
|
||||||
async () => {
|
</div>
|
||||||
const data = await createFileShare({
|
<div class="truncate w-auto">{{ props?.data?.file?.name }}</div>
|
||||||
file_id: item.new_file.id,
|
<div class="flex flex-row gap-2 items-center text-sm shrink-0">
|
||||||
config: {
|
<span class="opacity-75">{{ filesize(item.new_file.size ?? 0) }}</span>
|
||||||
download_nums: 1,
|
<span class="bg-green-200 text-green-600 rounded-md px-1 py-0.5 flex flex-row gap-1 items-center text-xs">
|
||||||
expire_time: 60,
|
<LucideChevronDown class="size-4" />
|
||||||
has_pickup_code: false,
|
{{ ((1 - item.new_file.size / item.old_file.size) * 100).toFixed(2) }}%
|
||||||
has_password: false,
|
</span>
|
||||||
},
|
</div>
|
||||||
file_name: props?.data?.file?.name,
|
</div>
|
||||||
});
|
<AsyncButton
|
||||||
const { id } = data?.data || {};
|
variant="outline"
|
||||||
if (!id) {
|
class="bg-black/5"
|
||||||
return;
|
size="icon"
|
||||||
}
|
@click="
|
||||||
await downloadFile(id);
|
async () => {
|
||||||
}
|
const data = await createFileShare({
|
||||||
"
|
file_id: item.new_file.id,
|
||||||
>
|
config: {
|
||||||
<LucideDownload />
|
download_nums: 1,
|
||||||
</AsyncButton>
|
expire_time: 60,
|
||||||
</div>
|
has_pickup_code: false,
|
||||||
</div>
|
has_password: false,
|
||||||
<div
|
},
|
||||||
v-else-if="taskData?.status !== 'retry' && !!taskData?.err?.message"
|
file_name: props?.data?.file?.name,
|
||||||
class="flex flex-col gap-2"
|
})
|
||||||
>
|
const { id } = data?.data || {}
|
||||||
<div
|
if (!id) {
|
||||||
class="w-full h-16 flex flex-row items-center gap-3 bg-white/80 rounded-md p-2"
|
return
|
||||||
>
|
}
|
||||||
<div
|
try {
|
||||||
class="size-10 flex items-center justify-center rounded-md bg-red-200"
|
await downloadFileByShareId(id)
|
||||||
>
|
} catch (error: any) {
|
||||||
<LucideAlertTriangle class="size-5 text-red-600" />
|
toast.error(error?.data?.message || error?.message || error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<LucideDownload />
|
||||||
|
</AsyncButton>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-sm">
|
<div v-else-if="taskData?.status !== 'retry' && !!taskData?.err?.message" class="flex flex-col gap-2">
|
||||||
{{
|
<div class="w-full h-16 flex flex-row items-center gap-3 bg-white/80 rounded-md p-2">
|
||||||
`经过 ${taskData?.err?.retry} 次重试后任务处理失败: ${taskData?.err?.message}`
|
<div class="size-10 flex items-center justify-center rounded-md bg-red-200">
|
||||||
}}
|
<LucideAlertTriangle class="size-5 text-red-600" />
|
||||||
|
</div>
|
||||||
|
<div class="text-sm">
|
||||||
|
{{ `经过 ${taskData?.err?.retry} 次重试后任务处理失败: ${taskData?.err?.message}` }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-row justify-center">
|
||||||
|
<Button @click="emit('change', 'input')"> 返回首页 </Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="flex flex-row justify-center">
|
|
||||||
<Button @click="emit('change', 'input')"> 返回首页 </Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
<div v-else="taskData?.status !== 'retry' && !!taskData?.err?.message" class="flex flex-col gap-2">
|
||||||
v-else="taskData?.status !== 'retry' && !!taskData?.err?.message"
|
<Skeleton class="w-full h-16 flex flex-row items-center justify-between" v-for="i in 3" />
|
||||||
class="flex flex-col gap-2"
|
</div>
|
||||||
>
|
|
||||||
<Skeleton
|
|
||||||
class="w-full h-16 flex flex-row items-center justify-between"
|
|
||||||
v-for="i in 3"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,69 +1,81 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import AsyncButton from "@/components/ui/button/AsyncButton.vue";
|
import AsyncButton from '@/components/ui/button/AsyncButton.vue'
|
||||||
import dayjs from "dayjs";
|
import dayjs from 'dayjs'
|
||||||
import duration from "dayjs/plugin/duration";
|
import duration from 'dayjs/plugin/duration'
|
||||||
import relativeTime from "dayjs/plugin/relativeTime";
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||||
import { isBoolean } from "lodash-es";
|
import { isBoolean } from 'lodash-es'
|
||||||
import { LucideCheck, LucideX } from "lucide-vue-next";
|
import { LucideCheck, LucideX } from 'lucide-vue-next'
|
||||||
import { useQueryClient } from "@tanstack/vue-query";
|
import { useQueryClient } from '@tanstack/vue-query'
|
||||||
dayjs.extend(duration);
|
import showDrawer from '~/lib/showDrawer'
|
||||||
dayjs.extend(relativeTime);
|
import { toast } from 'vue-sonner'
|
||||||
|
import PasswallShareDrawer from '~/components/Drawer/PasswallShareDrawer.vue'
|
||||||
|
dayjs.extend(duration)
|
||||||
|
dayjs.extend(relativeTime)
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
data: any;
|
data: any
|
||||||
}>();
|
}>()
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient()
|
||||||
const { downloadFile } = useMyAppShare();
|
const { downloadFile, getShareToken } = useMyAppShare()
|
||||||
|
|
||||||
const handleDownload = async () => {
|
const handleDownload = async () => {
|
||||||
const { id } = props?.data || {};
|
const { id } = props?.data || {}
|
||||||
await downloadFile(id);
|
try {
|
||||||
queryClient.invalidateQueries({ queryKey: ["share", id] });
|
let token = null
|
||||||
};
|
if (props?.data?.has_password) {
|
||||||
|
token = await showDrawer({
|
||||||
|
render: ({ ...rest }) => h(PasswallShareDrawer, { ...rest, share_id: id }),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
token = await getShareToken(id)
|
||||||
|
}
|
||||||
|
if (!token) {
|
||||||
|
throw new Error('获取token失败')
|
||||||
|
}
|
||||||
|
downloadFile(token)
|
||||||
|
} catch (error: any) {
|
||||||
|
toast.error(error?.data?.message || error?.message || error)
|
||||||
|
} finally {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['share', id] })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const expireSeconds = computed(() => {
|
const expireSeconds = computed(() => {
|
||||||
return dayjs(props?.data?.expire_at * 10e2).unix() - dayjs().unix();
|
return dayjs(props?.data?.expire_at * 10e2).unix() - dayjs().unix()
|
||||||
});
|
})
|
||||||
|
|
||||||
const { remaining, start } = useCountdown(expireSeconds.value);
|
const { remaining, start } = useCountdown(expireSeconds.value)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
start();
|
start()
|
||||||
});
|
})
|
||||||
|
|
||||||
const fileShareInfo = computed(() => {
|
const fileShareInfo = computed(() => {
|
||||||
return [
|
return [
|
||||||
{ label: "需要密码", value: props?.data?.has_password ?? false },
|
{ label: '需要密码', value: props?.data?.has_password ?? false },
|
||||||
{
|
{
|
||||||
label: "过期时间",
|
label: '过期时间',
|
||||||
value: dayjs.duration(remaining.value, "seconds").format(`D天 HH:mm:ss`),
|
value: dayjs.duration(remaining.value, 'seconds').format(`D天 HH:mm:ss`),
|
||||||
},
|
},
|
||||||
{ label: "剩余下载次数", value: props?.data?.download_nums ?? 0 },
|
{ label: '剩余下载次数', value: props?.data?.download_nums ?? 0 },
|
||||||
];
|
]
|
||||||
});
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col gap-5 items-center">
|
<div class="flex flex-col gap-5 items-center">
|
||||||
<h1 class="text-xl font-bold">下载文件</h1>
|
<h1 class="text-xl font-bold">下载文件</h1>
|
||||||
<FilePreviewView :value="props?.data" />
|
<FilePreviewView :value="props?.data" />
|
||||||
<div class="flex flex-col gap-2 md:flex-row w-full">
|
<div class="flex flex-col gap-2 md:flex-row w-full">
|
||||||
<div
|
<div class="flex flex-row md:flex-col md:gap-1 justify-between items-center md:flex-1" v-for="item in fileShareInfo">
|
||||||
class="flex flex-row md:flex-col md:gap-1 justify-between items-center md:flex-1"
|
<div class="text-xs opacity-75">{{ item?.label }}</div>
|
||||||
v-for="item in fileShareInfo"
|
<component v-if="isBoolean(item?.value)" :is="item?.value ? LucideCheck : LucideX" class="size-6" />
|
||||||
>
|
<div v-else class="md:text-xl">{{ item?.value }}</div>
|
||||||
<div class="text-xs opacity-75">{{ item?.label }}</div>
|
</div>
|
||||||
<component
|
</div>
|
||||||
v-if="isBoolean(item?.value)"
|
<div class="w-full">
|
||||||
:is="item?.value ? LucideCheck : LucideX"
|
<AsyncButton @click="handleDownload" class="w-full">下载</AsyncButton>
|
||||||
class="size-6"
|
</div>
|
||||||
/>
|
|
||||||
<div v-else class="md:text-xl">{{ item?.value }}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full">
|
|
||||||
<AsyncButton @click="handleDownload" class="w-full">下载</AsyncButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import MarkdownRender from '@/components/MarkdownRender.vue'
|
|||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { LucideCopy } from 'lucide-vue-next'
|
import { LucideCopy } from 'lucide-vue-next'
|
||||||
import { useClipboard } from '@vueuse/core'
|
import { useClipboard } from '@vueuse/core'
|
||||||
|
import showDrawer from '~/lib/showDrawer'
|
||||||
|
import PasswallShareDrawer from '~/components/Drawer/PasswallShareDrawer.vue'
|
||||||
|
|
||||||
dayjs.extend(duration)
|
dayjs.extend(duration)
|
||||||
dayjs.extend(relativeTime)
|
dayjs.extend(relativeTime)
|
||||||
@@ -47,7 +49,14 @@ const previewText = ref<string | null>(null)
|
|||||||
|
|
||||||
const handlePreview = async () => {
|
const handlePreview = async () => {
|
||||||
try {
|
try {
|
||||||
const token = await getShareToken(props?.data?.id)
|
let token = null
|
||||||
|
if (props?.data?.has_password) {
|
||||||
|
token = await showDrawer({
|
||||||
|
render: ({ ...rest }) => h(PasswallShareDrawer, { ...rest, share_id: props?.data?.id }),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
token = await getShareToken(props?.data?.id)
|
||||||
|
}
|
||||||
const r = await $fetch<{
|
const r = await $fetch<{
|
||||||
code: number
|
code: number
|
||||||
data: {
|
data: {
|
||||||
@@ -55,8 +64,8 @@ const handlePreview = async () => {
|
|||||||
}
|
}
|
||||||
}>(`/api/download?token=${token}`)
|
}>(`/api/download?token=${token}`)
|
||||||
previewText.value = r?.data?.data
|
previewText.value = r?.data?.data
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
toast.error((error as any)?.data?.message || error)
|
toast.error(error?.data?.message || error?.message || error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
import { toast } from 'vue-sonner'
|
import { toast } from 'vue-sonner'
|
||||||
|
declare const window: any
|
||||||
let shareIdTokenMap: WeakMap<{ share_id: string }, string>
|
let shareIdTokenMap: WeakMap<{ share_id: string }, string>
|
||||||
|
|
||||||
const getShareToken = async (share_id: string): Promise<string | undefined> => {
|
const getShareToken = async (
|
||||||
|
share_id: string,
|
||||||
|
options?: {
|
||||||
|
password?: string
|
||||||
|
}
|
||||||
|
): Promise<string | undefined> => {
|
||||||
if (!shareIdTokenMap) {
|
if (!shareIdTokenMap) {
|
||||||
shareIdTokenMap = new WeakMap()
|
shareIdTokenMap = new WeakMap()
|
||||||
}
|
}
|
||||||
let token = shareIdTokenMap.get({ share_id })
|
let token = shareIdTokenMap.get({ share_id })
|
||||||
|
const { password } = options || {}
|
||||||
if (!token) {
|
if (!token) {
|
||||||
const data = await $fetch<{
|
const data = await $fetch<{
|
||||||
code: number
|
code: number
|
||||||
@@ -18,6 +24,7 @@ const getShareToken = async (share_id: string): Promise<string | undefined> => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
share_id,
|
share_id,
|
||||||
|
password,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!data?.data?.token) {
|
if (!data?.data?.token) {
|
||||||
@@ -29,17 +36,16 @@ const getShareToken = async (share_id: string): Promise<string | undefined> => {
|
|||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloadFile = async (share_id: string) => {
|
const downloadFile = (token: string) => {
|
||||||
try {
|
window?.open(`/api/download?token=${token}`)
|
||||||
const token = await getShareToken(share_id)
|
}
|
||||||
if (!token) {
|
|
||||||
throw new Error('获取token失败')
|
const downloadFileByShareId = async (share_id: string) => {
|
||||||
return
|
const token = await getShareToken(share_id)
|
||||||
}
|
if (!token) {
|
||||||
;(window as any)?.open(`/api/download?token=${token}`)
|
throw new Error('获取token失败')
|
||||||
} catch (e) {
|
|
||||||
toast.error((e as any)?.data?.message || e)
|
|
||||||
}
|
}
|
||||||
|
return downloadFile(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
const createShare = async (data: any) => {
|
const createShare = async (data: any) => {
|
||||||
@@ -92,6 +98,7 @@ const createTextShare = async (data: { text: string; config: any }) => {
|
|||||||
const useMyAppShare = () => {
|
const useMyAppShare = () => {
|
||||||
return {
|
return {
|
||||||
downloadFile,
|
downloadFile,
|
||||||
|
downloadFileByShareId,
|
||||||
createShare,
|
createShare,
|
||||||
createFileShare,
|
createFileShare,
|
||||||
createTextShare,
|
createTextShare,
|
||||||
|
|||||||
@@ -1,35 +1,34 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { cloneDeep, get, isEmpty, isUndefined, set,isString } from 'lodash-es'
|
import { cloneDeep, get, isEmpty, isUndefined, set, isString } from 'lodash-es'
|
||||||
|
|
||||||
type StoreType = Record<string, any>
|
type StoreType = Record<string, any>
|
||||||
|
|
||||||
const initState: StoreType = {}
|
const initState: StoreType = {}
|
||||||
// 做了一点小小的改进,可以传入key,会自动初始化,如果不初始化的话容易导致不存在值而丢失响应式
|
// 做了一点小小的改进,可以传入key,会自动初始化,如果不初始化的话容易导致不存在值而丢失响应式
|
||||||
const useStore = (key?: string) => {
|
const useStore = (key?: string) => {
|
||||||
const store = defineStore('store', {
|
const store = defineStore('store', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
...initState,
|
...initState,
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
_get(path?: string) {
|
_get(path?: string) {
|
||||||
if (isEmpty(path) || isUndefined(path)) {
|
if (isEmpty(path) || isUndefined(path)) {
|
||||||
return this.$state
|
return this.$state
|
||||||
}
|
}
|
||||||
return get(this.$state, path)
|
return get(this.$state, path)
|
||||||
},
|
},
|
||||||
_set(path: string, value: any) {
|
_set(path: string, value: any) {
|
||||||
const newState = cloneDeep(this.$state)
|
const newState = cloneDeep(this.$state)
|
||||||
set(newState, path, value)
|
set(newState, path, value)
|
||||||
this.$patch(newState)
|
this.$patch(newState)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
persist: true,
|
})()
|
||||||
})()
|
if (!isEmpty(key) && isString(key) && isUndefined(store?._get(key))) {
|
||||||
if (!isEmpty(key) && isString(key) && isUndefined(store?._get(key))) {
|
// console.log('reset', key, store?._get(key))
|
||||||
console.log('reset', key, store?._get(key))
|
store?._set(key, null)
|
||||||
store?._set(key, undefined)
|
}
|
||||||
}
|
return store
|
||||||
return store
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useStore
|
export default useStore
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
interface DrawerProps {
|
interface DrawerProps {
|
||||||
render: (props: { hide: () => void }) => Component
|
render: (props: { hide: () => void }) => Component
|
||||||
}
|
}
|
||||||
|
|
||||||
const showDrawer = (props: DrawerProps) => {
|
const showDrawer = (props: DrawerProps) => {
|
||||||
const { render } = props || {}
|
const key = Math.random().toString(36).slice(2, 8)
|
||||||
const store = useStore()
|
return new Promise<void>((res) => {
|
||||||
store?._set('drawer', [...(store?._get('drawer')?.value || []), { render }])
|
const { render } = props || {}
|
||||||
|
const onClose = (data?: any) => {
|
||||||
|
store._set(
|
||||||
|
'drawer',
|
||||||
|
(store._get('drawer')?.value ?? [])?.filter((item: any) => item.key !== key)
|
||||||
|
)
|
||||||
|
res(data)
|
||||||
|
}
|
||||||
|
const store = useStore()
|
||||||
|
store._set('drawer', [...(store._get('drawer')?.value || []), { render, onClose, key }])
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default showDrawer
|
export default showDrawer
|
||||||
|
|||||||
Reference in New Issue
Block a user